Skip to content

Instantly share code, notes, and snippets.

@polc
Created March 31, 2015 13:20
Show Gist options
  • Save polc/b3d12a24385244d86b2c to your computer and use it in GitHub Desktop.
Save polc/b3d12a24385244d86b2c to your computer and use it in GitHub Desktop.
typedef struct IPv4Header
{
u_int8_t versionAndHeaderLength;
u_int8_t differentiatedServices;
u_int16_t totalLength;
u_int16_t identification;
u_int16_t fragmentOffset;
u_int8_t timeToLive;
u_int8_t protocol;
u_int16_t checksum;
struct in_addr source, destination;
} IPv4Header;
uint8_t buffer[HeaderSize];
mHeader = *((IPv4Header*) buffer); // uint8_t to IPv4Header
*((IPv4Header*) buffer) = mHeader; // IPv4Header to uint8_t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment