#define PACKETS_H 1
#include <stdint.h>
+#include <string.h>
#include "util.h"
#define ETH_ADDR_LEN 6
{
return ea[0] & 2;
}
+static inline bool eth_addr_equals(const uint8_t a[ETH_ADDR_LEN],
+ const uint8_t b[ETH_ADDR_LEN])
+{
+ return !memcmp(a, b, ETH_ADDR_LEN);
+}
+#define ETH_ADDR_FMT \
+ "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8
+#define ETH_ADDR_ARGS(ea) \
+ (ea)[0], (ea)[1], (ea)[2], (ea)[3], (ea)[4], (ea)[5]
#define ETH_TYPE_IP 0x0800
#define ETH_TYPE_ARP 0x0806
uint8_t eth_dst[ETH_ADDR_LEN];
uint8_t eth_src[ETH_ADDR_LEN];
uint16_t eth_type;
-};
+} __attribute__((packed));
BUILD_ASSERT_DECL(ETH_HEADER_LEN == sizeof(struct eth_header));
#define LLC_DSAP_SNAP 0xaa
uint8_t llc_dsap;
uint8_t llc_ssap;
uint8_t llc_cntl;
-};
+} __attribute__((packed));
BUILD_ASSERT_DECL(LLC_HEADER_LEN == sizeof(struct llc_header));
#define SNAP_ORG_ETHERNET "\0\0" /* The compiler adds a null byte, so
struct llc_snap_header {
struct llc_header llc;
struct snap_header snap;
-};
+} __attribute__((packed));
BUILD_ASSERT_DECL(LLC_SNAP_HEADER_LEN == sizeof(struct llc_snap_header));
#define VLAN_VID 0x0fff
};
BUILD_ASSERT_DECL(VLAN_ETH_HEADER_LEN == sizeof(struct vlan_eth_header));
+#define IP_FMT "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8
+#define IP_ARGS(ip) \
+ ((uint8_t *) ip)[0], \
+ ((uint8_t *) ip)[1], \
+ ((uint8_t *) ip)[2], \
+ ((uint8_t *) ip)[3]
+
#define IP_VER(ip_ihl_ver) ((ip_ihl_ver) >> 4)
#define IP_IHL(ip_ihl_ver) ((ip_ihl_ver) & 15)