55a4ef917532453cc39576073284cfb60d9752af
Stefan Schuermans implementation of ethernet...

Stefan Schuermans authored 12 years ago

1) #ifndef ETHERNET_H
2) #define ETHERNET_H
3) 
Stefan Schuermans added padding of ethernet p...

Stefan Schuermans authored 12 years ago

4) /** padding at end of packet
5)     to reach next size divisible by 4 and at least 60 bytes */
6) #define ETHERNET_PADDING_SIZE(packet) \
7)         (sizeof(struct packet) >= 60 ? 0 : 60 - sizeof(struct packet))
8) #define ETHERNET_PADDING(packet) \
9)         unsigned char padding[ETHERNET_PADDING_SIZE(packet)]
10) #define ETHERNET_PAD(packet) \
11)         struct packet ## _pad \
12)         { \
13)           struct packet p; \
14)           ETHERNET_PADDING(packet); \
15)         } __attribute__((packed))
16) 
17) /// header of ethernet packet
Stefan Schuermans implementation of ethernet...

Stefan Schuermans authored 12 years ago

18) struct ethernet_header
19) {
20)   unsigned char dest[6];
21)   unsigned char src[6];
22)   unsigned short type;
23) } __attribute__((packed));
24) 
25) /// ethernet packet
26) struct ethernet_packet
27) {
28)   struct ethernet_header eth_hdr;
29) } __attribute__((packed));
30) 
Stefan Schuermans added padding of ethernet p...

Stefan Schuermans authored 12 years ago

31) /// ethernet packet with padding
32) ETHERNET_PAD(ethernet_packet);
33)