diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-08-13 20:49:02 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2017-08-13 20:49:02 +0200 |
commit | d7a5dafaf9cdabb78b39bffbfad46eb72cf44fdf (patch) | |
tree | 9645338b048e828d25f7fb4adfd79040dde1a8a7 /src/net/ipv4.h | |
parent | 6f94e0aed01aacc7e0dce031aeb017698e3eab59 (diff) | |
download | abaos-d7a5dafaf9cdabb78b39bffbfad46eb72cf44fdf.tar.gz abaos-d7a5dafaf9cdabb78b39bffbfad46eb72cf44fdf.tar.bz2 |
some work on IPv4
Diffstat (limited to 'src/net/ipv4.h')
-rw-r--r-- | src/net/ipv4.h | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/net/ipv4.h b/src/net/ipv4.h index acf7f7f..95dec18 100644 --- a/src/net/ipv4.h +++ b/src/net/ipv4.h @@ -9,10 +9,44 @@ // protocol_address_len #define NETWORK_PROTOCOL_IPV4_ADDRESS_LENGTH 4 +// protocol string len +#define NETWORK_PROTOCOL_IPV4_PROTOCOL_STRING 5 + +#if defined( __TINYC__ ) +#pragma pack(1) +#endif + typedef struct { uint8_t byte[NETWORK_PROTOCOL_IPV4_ADDRESS_LENGTH]; -} network_ipv4_address_t; +} __attribute__( ( packed ) ) network_ipv4_address_t; + +typedef uint8_t network_ipv4_protocol_t; + +// TODO: network order not host oder, so for now swap it +#define NETWORK_IPV4_PROTOCOL_ICMP (network_ipv4_protocol_t)0x01 +#define NETWORK_IPV4_PROTOCOL_UDP (network_ipv4_protocol_t)0x11 + +typedef struct { + uint8_t internet_header_length : 4; + uint8_t version : 4; + uint8_t explicit_congestion_notification : 2; + uint8_t differentiated_services_code_point : 6; + uint16_t total_length; + uint16_t identification; + uint16_t fragment_offset : 13; + uint16_t flags : 3; + uint8_t time_to_live; + network_ipv4_protocol_t protocol; + uint16_t checksum; + network_ipv4_address_t source_address; + network_ipv4_address_t destination_address; +} __attribute__( ( packed ) ) network_ipv4_packet_t; + +#if defined( __TINYC__ ) +#pragma pack() +#endif char *network_ipv4_address_to_string( network_ipv4_address_t addr, char *buf, size_t buflen ); +char *network_ipv4_protocol_to_string( network_ipv4_protocol_t protocol, char *buf, size_t buflen ); #endif // IPV4_H |