summaryrefslogtreecommitdiff
path: root/src/net/ethernet.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/ethernet.h')
-rw-r--r--src/net/ethernet.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/net/ethernet.h b/src/net/ethernet.h
new file mode 100644
index 0000000..a2726e7
--- /dev/null
+++ b/src/net/ethernet.h
@@ -0,0 +1,38 @@
+#ifndef ETHERNET_H
+#define ETHERNET_H
+
+#include "stddef.h"
+
+#define NETWORK_ETHERNET_MAC_ADDR_STRING 6 * 3 + 1
+
+typedef struct {
+ uint8_t byte[6];
+} network_mac_address_t;
+
+typedef uint16_t ether_type_t;
+
+// TODO: network order not host oder, so for now swap it
+#define NETWORK_ETHER_TYPE_ARP 0x0608
+
+#if defined( __TINYC__ )
+#pragma pack(1)
+#endif
+
+typedef struct {
+ network_mac_address_t dst_addr;
+ network_mac_address_t src_addr;
+ ether_type_t type;
+} __attribute__( ( packed ) ) network_ethernet_packet_header_t;
+
+typedef struct {
+ network_ethernet_packet_header_t header;
+ uint8_t *data;
+} __attribute__( ( packed ) ) network_ethernet_packet_t;
+
+#if defined( __TINYC__ )
+#pragma pack()
+#endif
+
+char *network_mac_to_string( network_mac_address_t mac, char *buf, size_t buflen );
+
+#endif // ETHERNET_H