#ifndef ETHERNET_H #define ETHERNET_H #include "stdint.h" #include "stddef.h" // length of a string representation of a MAC address #define NETWORK_ETHERNET_MAC_ADDR_STRING 6 * 3 + 1 // minimal size of an ethernet packet #define ETHERNET_MIN_FRAME_SIZE_IEEE_802_3 64 // maximal size of an ethernet packet #define ETHERNET_MAX_FRAME_SIZE_IEEE_802_3 1536 // hardware_address_len #define NETWORK_HARDWARE_ETHERNET_ADDRESS_LENGTH 6 typedef struct { uint8_t byte[NETWORK_HARDWARE_ETHERNET_ADDRESS_LENGTH]; } network_mac_address_t; typedef uint16_t network_ether_type_t; // TODO: network order not host oder, so for now swap it #define NETWORK_ETHER_PROTOCOL_TYPE_ARP (network_ether_type_t)0x0608 #define NETWORK_ETHER_PROTOCOL_TYPE_IPV4 (network_ether_type_t)0x0008 #if defined( __TINYC__ ) #pragma pack(1) #endif typedef struct { network_mac_address_t dst_addr; network_mac_address_t src_addr; network_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_address_to_string( network_mac_address_t mac, char *buf, size_t buflen ); #endif // ETHERNET_H