Guest User

Untitled

a guest
Oct 22nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <stdio.h> // fread,
  2. #include <stdlib.h>
  3.  
  4. /*
  5. * The number of bytes in an ethernet (MAC) address.
  6. */
  7. #define ETHER_ADDR_LEN 6
  8.  
  9. /*
  10. * The number of bytes in the type field.
  11. */
  12. #define ETHER_TYPE_LEN 2
  13.  
  14. /*
  15. * The number of bytes in the trailing CRC field.
  16. */
  17. #define ETHER_CRC_LEN 4
  18.  
  19.  
  20. /*
  21. * Structure of Ethernet header.
  22. */
  23. struct ether_header {
  24. u_char ether_dhost[ETHER_ADDR_LEN]; // 6 bytes
  25. u_char ether_shost[ETHER_ADDR_LEN]; // 6 bytes
  26. int ether_optional; // 4 bytes
  27. u_short ether_len_packet; // 2 bytes
  28. };
  29.  
  30.  
  31.  
  32. int main(int argc, const char *argv[])
  33. {
  34.  
  35. struct ether_header eth_header;
  36.  
  37. printf("Sizeof struct eth_header: %d bytes\n", sizeof(struct ether_header));
  38. printf("Sizeof struct eth_header.ether_dhost: %d bytes\n", sizeof( ((struct ether_header*)0)->ether_dhost ));
  39. printf("Sizeof struct eth_header.ether_shost: %d bytes\n", sizeof( ((struct ether_header*)0)->ether_shost ));
  40. printf("Sizeof struct eth_header.ether_optional: %d bytes\n", sizeof( ((struct ether_header*)0)->ether_optional ));
  41. printf("Sizeof struct eth_header.ether_len_packet: %d bytes\n", sizeof( ((struct ether_header*)0)->ether_len_packet ));
  42. return 0;
  43. }
  44.  
  45. /*
  46.  
  47. bezrukov@Jdanovsk:~/$ ./TTT
  48. Sizeof struct eth_header: 20 bytes
  49. Sizeof struct eth_header.ether_dhost: 6 bytes
  50. Sizeof struct eth_header.ether_shost: 6 bytes
  51. Sizeof struct eth_header.ether_optional: 4 bytes
  52. Sizeof struct eth_header.ether_len_packet: 2 bytes
  53.  
  54. */
Add Comment
Please, Sign In to add comment