summaryrefslogtreecommitdiff
path: root/kernel/socket.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-06-28 17:56:53 +0200
committerAnton Kling <anton@kling.gg>2024-06-28 17:57:45 +0200
commitb747eb399c556858e05de51b1bb3e875c834c8e0 (patch)
treeb8893bea96e8a01f9053a24d5558188cd1c2ea2e /kernel/socket.c
parent0bab28c0bd18274a9aff69ce0249ae9b8009dfa4 (diff)
Bug fix: Fix undefined behavior of ipv4_t type.
Turns out unions that include arrays and a integer can have UB due to endianess not being the same across systems.
Diffstat (limited to 'kernel/socket.c')
-rw-r--r--kernel/socket.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/kernel/socket.c b/kernel/socket.c
index d4e86a9..689e2ac 100644
--- a/kernel/socket.c
+++ b/kernel/socket.c
@@ -26,10 +26,7 @@ void global_socket_init(void) {
OPEN_UNIX_SOCKET *un_sockets[100] = {0};
void gen_ipv4(ipv4_t *ip, u8 i1, u8 i2, u8 i3, u8 i4) {
- ip->a[0] = i1;
- ip->a[1] = i2;
- ip->a[2] = i3;
- ip->a[3] = i4;
+ ip->d = (i1 << (8 * 0)) | (i2 << (8 * 1)) | (i3 << (8 * 2)) | (i4 << (8 * 3));
}
void tcp_remove_connection(struct TcpConnection *con) {