aboutsummaryrefslogtreecommitdiff
path: root/kernel/inc/net.h
diff options
context:
space:
mode:
authorMarvin Borner2020-09-26 13:19:06 +0200
committerMarvin Borner2020-09-26 13:19:06 +0200
commit038722e045684a1a04f0fd6a51da2a6ea9dc9bb5 (patch)
treed0a95bc3c9dced5a390258031e810758d066c966 /kernel/inc/net.h
parent6668ea8666377f9e2adfeb486c5048a85fa590d1 (diff)
Some random network things
Diffstat (limited to 'kernel/inc/net.h')
-rw-r--r--kernel/inc/net.h20
1 files changed, 16 insertions, 4 deletions
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 <def.h>
+#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));