From 038722e045684a1a04f0fd6a51da2a6ea9dc9bb5 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 26 Sep 2020 13:19:06 +0200 Subject: Some random network things --- kernel/inc/net.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'kernel/inc/net.h') diff --git a/kernel/inc/net.h b/kernel/inc/net.h index 211cf90..300c0bd 100644 --- a/kernel/inc/net.h +++ b/kernel/inc/net.h @@ -5,10 +5,21 @@ #include +#define htonl(l) \ + ((((l)&0xFF) << 24) | (((l)&0xFF00) << 8) | (((l)&0xFF0000) >> 8) | \ + (((l)&0xFF000000) >> 24)) +#define htons(s) ((((s)&0xFF) << 8) | (((s)&0xFF00) >> 8)) +#define ntohl(l) htonl((l)) +#define ntohs(s) htons((s)) + #define ETHERNET_TYPE_IP4 0x0800 #define ETHERNET_TYPE_IP6 0x86dd #define ETHERNET_TYPE_ARP 0x0806 +#define IP_PROT_ICMP 0x01 +#define IP_PROT_TCP 0x06 +#define IP_PROT_UDP 0x11 + struct ethernet_packet { u8 dst_mac_addr[6]; u8 src_mac_addr[6]; @@ -17,16 +28,17 @@ struct ethernet_packet { } __attribute__((packed)); struct ip_packet { - u8 version_ihl; + u8 version : 4; + u8 ihl : 4; u8 dscp_ecn; u16 length; u16 id; - u8 flags_fragment; + u16 flags_fragment; u8 ttl; u8 protocol; u16 checksum; - u8 src_ip[4]; - u8 dst_ip[4]; + u32 src; + u32 dst; u8 data[]; } __attribute__((packed)); -- cgit v1.2.3