#ifndef ETHERNET_H
#define ETHERNET_H
/** padding at end of packet
to reach next size divisible by 4 and at least 60 bytes */
#define ETHERNET_PADDING_SIZE(packet) \
(sizeof(struct packet) >= 60 ? 0 : 60 - sizeof(struct packet))
#define ETHERNET_PADDING(packet) \
unsigned char padding[ETHERNET_PADDING_SIZE(packet)]
#define ETHERNET_PAD(packet) \
struct packet ## _pad \
{ \
struct packet p; \
ETHERNET_PADDING(packet); \
} __attribute__((packed))
/// header of ethernet packet
struct ethernet_header
{
unsigned char dest[6];
unsigned char src[6];
unsigned short type;
} __attribute__((packed));
/// ethernet packet
struct ethernet_packet
{
struct ethernet_header eth_hdr;
} __attribute__((packed));
/// ethernet packet with padding
ETHERNET_PAD(ethernet_packet);
/**
* @brief process a received ethernet packet
* @param[in] ptr pointer to data of packet
* @param[in] sz size of packet
*/
void ethernet_recv(void *ptr, unsigned int sz);
/**
* @brief send an ethernet packet
* @param[in] ptr pointer to data of packet
* @param[in] sz size of packet
*
* ptr must point to a ethernet_packet of sufficient size (ethernet padding)
* with eth_hdr.dest and eth_hdr.type already initialized
*/
void ethernet_send(void *ptr, unsigned int sz);
#endif // #ifdef ETHERNET_H