Skip to content
Browse files

fixed struct padding and field sizes for != 32 bit systems

  • Loading branch information...
1 parent 470063d commit af4df0bad87e0291e120083aabb6d34d55fd8412 @deoxxa committed
Showing with 24 additions and 22 deletions.
  1. +24 −22 headers.h
View
46 headers.h
@@ -1,3 +1,5 @@
+#pragma pack(2)
+
struct fs_ethhdr
{
unsigned char dst[6];
@@ -15,23 +17,23 @@ struct fs_ipv4hdr
unsigned int version:4;
unsigned int header_length:4;
#endif
- unsigned char dscp;
- unsigned short int length;
- unsigned short int id;
- unsigned short int offset;
- unsigned char ttl;
- unsigned char protocol;
- unsigned short checksum;
- unsigned long int src;
- unsigned long int dst;
+ unsigned char dscp:8;
+ unsigned short int length:16;
+ unsigned short int id:16;
+ unsigned short int offset:16;
+ unsigned char ttl:8;
+ unsigned char protocol:8;
+ unsigned short checksum:16;
+ unsigned long int src:32;
+ unsigned long int dst:32;
};
struct fs_tcphdr
{
- unsigned short int src;
- unsigned short int dst;
- unsigned long int seq_num;
- unsigned long int ack_num;
+ unsigned short int src:16;
+ unsigned short int dst:16;
+ unsigned long int seq_num:32;
+ unsigned long int ack_num:32;
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned short int reserved:4;
unsigned short int offset:4;
@@ -45,7 +47,7 @@ struct fs_tcphdr
unsigned short int flag_cwr:1;
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
- unsigned short int offset:4;
+ unsigned short int offset:4;
unsigned short int reserved:4;
unsigned short int flag_cwr:1;
unsigned short int flag_ece:1;
@@ -56,16 +58,16 @@ struct fs_tcphdr
unsigned short int flag_syn:1;
unsigned short int flag_fin:1;
#endif
- unsigned short int window;
- unsigned short int checksum;
- unsigned short int urg_ptr;
+ unsigned short int window:16;
+ unsigned short int checksum:16;
+ unsigned short int urg_ptr:16;
};
struct fs_pseudov4hdr
{
- unsigned long int src;
- unsigned long int dst;
- unsigned char reserved;
- unsigned char protocol;
- unsigned short int length;
+ unsigned long int src:32;
+ unsigned long int dst:32;
+ unsigned char reserved:8;
+ unsigned char protocol:8;
+ unsigned short int length:16;
};

0 comments on commit af4df0b

Please sign in to comment.
Something went wrong with that request. Please try again.