Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> // fread,
- #include <stdlib.h>
- /*
- * The number of bytes in an ethernet (MAC) address.
- */
- #define ETHER_ADDR_LEN 6
- /*
- * The number of bytes in the type field.
- */
- #define ETHER_TYPE_LEN 2
- /*
- * The number of bytes in the trailing CRC field.
- */
- #define ETHER_CRC_LEN 4
- /*
- * Structure of Ethernet header.
- */
- struct ether_header {
- u_char ether_dhost[ETHER_ADDR_LEN]; // 6 bytes
- u_char ether_shost[ETHER_ADDR_LEN]; // 6 bytes
- int ether_optional; // 4 bytes
- u_short ether_len_packet; // 2 bytes
- };
- int main(int argc, const char *argv[])
- {
- struct ether_header eth_header;
- printf("Sizeof struct eth_header: %d bytes\n", sizeof(struct ether_header));
- printf("Sizeof struct eth_header.ether_dhost: %d bytes\n", sizeof( ((struct ether_header*)0)->ether_dhost ));
- printf("Sizeof struct eth_header.ether_shost: %d bytes\n", sizeof( ((struct ether_header*)0)->ether_shost ));
- printf("Sizeof struct eth_header.ether_optional: %d bytes\n", sizeof( ((struct ether_header*)0)->ether_optional ));
- printf("Sizeof struct eth_header.ether_len_packet: %d bytes\n", sizeof( ((struct ether_header*)0)->ether_len_packet ));
- return 0;
- }
- /*
- bezrukov@Jdanovsk:~/$ ./TTT
- Sizeof struct eth_header: 20 bytes
- Sizeof struct eth_header.ether_dhost: 6 bytes
- Sizeof struct eth_header.ether_shost: 6 bytes
- Sizeof struct eth_header.ether_optional: 4 bytes
- Sizeof struct eth_header.ether_len_packet: 2 bytes
- */
Add Comment
Please, Sign In to add comment