00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef DNET_ETH_H
00012 #define DNET_ETH_H
00013
00014 #define ETH_ADDR_LEN 6
00015 #define ETH_ADDR_BITS 48
00016 #define ETH_TYPE_LEN 2
00017 #define ETH_CRC_LEN 4
00018 #define ETH_HDR_LEN 14
00019
00020 #define ETH_LEN_MIN 64
00021 #define ETH_LEN_MAX 1518
00022
00023 #define ETH_MTU (ETH_LEN_MAX - ETH_HDR_LEN - ETH_CRC_LEN)
00024 #define ETH_MIN (ETH_LEN_MIN - ETH_HDR_LEN - ETH_CRC_LEN)
00025
00026 typedef struct eth_addr {
00027 uint8_t data[ETH_ADDR_LEN];
00028 } eth_addr_t;
00029
00030 struct eth_hdr {
00031 eth_addr_t eth_dst;
00032 eth_addr_t eth_src;
00033 uint16_t eth_type;
00034 };
00035
00036
00037
00038
00039 #define ETH_TYPE_PUP 0x0200
00040 #define ETH_TYPE_IP 0x0800
00041 #define ETH_TYPE_ARP 0x0806
00042 #define ETH_TYPE_REVARP 0x8035
00043 #define ETH_TYPE_8021Q 0x8100
00044 #define ETH_TYPE_IPV6 0x86DD
00045 #define ETH_TYPE_MPLS 0x8847
00046 #define ETH_TYPE_MPLS_MCAST 0x8848
00047 #define ETH_TYPE_PPPOEDISC 0x8863
00048 #define ETH_TYPE_PPPOE 0x8864
00049 #define ETH_TYPE_LOOPBACK 0x9000
00050
00051 #define ETH_IS_MULTICAST(ea) (*(ea) & 0x01)
00052
00053 #define ETH_ADDR_BROADCAST "\xff\xff\xff\xff\xff\xff"
00054
00055 #define eth_pack_hdr(h, dst, src, type) do { \
00056 struct eth_hdr *eth_pack_p = (struct eth_hdr *)(h); \
00057 memmove(ð_pack_p->eth_dst, &(dst), ETH_ADDR_LEN); \
00058 memmove(ð_pack_p->eth_src, &(src), ETH_ADDR_LEN); \
00059 eth_pack_p->eth_type = htons(type); \
00060 } while (0)
00061
00062 typedef struct eth_handle eth_t;
00063
00064 __BEGIN_DECLS
00065 eth_t *eth_open(const char *device);
00066 int eth_get(eth_t *e, eth_addr_t *ea);
00067 int eth_set(eth_t *e, const eth_addr_t *ea);
00068 ssize_t eth_send(eth_t *e, const void *buf, size_t len);
00069 eth_t *eth_close(eth_t *e);
00070
00071 char *eth_ntop(const eth_addr_t *eth, char *dst, size_t len);
00072 int eth_pton(const char *src, eth_addr_t *dst);
00073 char *eth_ntoa(const eth_addr_t *eth);
00074 #define eth_aton eth_pton
00075 __END_DECLS
00076
00077 #endif