00d70bee0c1121134e74c1402ebdc9b80807a3bf
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) 
Stefan Schuermans implementation of ethernet...

Stefan Schuermans authored 12 years ago

34) /**
35)  * @brief process a received ethernet packet
36)  * @param[in] ptr pointer to data of packet
37)  * @param[in] sz size of packet
38)  */
39) void ethernet_recv(void *ptr, unsigned int sz);
40) 
41) /**
42)  * @brief send an ethernet packet
43)  * @param[in] ptr pointer to data of packet
44)  * @param[in] sz size of packet
45)  *
Stefan Schuermans implemented IP + ICMP, fixe...

Stefan Schuermans authored 12 years ago

46)  * ptr must point to a ethernet_packet of sufficient size (ethernet padding)
47)  * with eth_hdr.dest and eth_hdr.type already initialized