eth.h revision 2632
15390SN/A/* 25452SN/A * eth.h 35390SN/A * 45390SN/A * Ethernet. 55390SN/A * 65390SN/A * Copyright (c) 2000 Dug Song <dugsong@monkey.org> 75390SN/A * 85390SN/A * $Id: eth.h,v 1.15 2004/01/03 08:47:23 dugsong Exp $ 95390SN/A */ 105390SN/A 115390SN/A#ifndef DNET_ETH_H 125390SN/A#define DNET_ETH_H 135390SN/A 145390SN/A#define ETH_ADDR_LEN 6 155390SN/A#define ETH_ADDR_BITS 48 165390SN/A#define ETH_TYPE_LEN 2 175390SN/A#define ETH_CRC_LEN 4 185390SN/A#define ETH_HDR_LEN 14 195390SN/A 205390SN/A#define ETH_LEN_MIN 64 /* minimum frame length with CRC */ 215390SN/A#define ETH_LEN_MAX 1518 /* maximum frame length with CRC */ 225390SN/A 235390SN/A#define ETH_MTU (ETH_LEN_MAX - ETH_HDR_LEN - ETH_CRC_LEN) 245390SN/A#define ETH_MIN (ETH_LEN_MIN - ETH_HDR_LEN - ETH_CRC_LEN) 255390SN/A 265390SN/Atypedef struct eth_addr { 275390SN/A uint8_t data[ETH_ADDR_LEN]; 285390SN/A} eth_addr_t; 295390SN/A 305390SN/Astruct eth_hdr { 315629Sgblack@eecs.umich.edu eth_addr_t eth_dst; /* destination address */ 325629Sgblack@eecs.umich.edu eth_addr_t eth_src; /* source address */ 335390SN/A uint16_t eth_type; /* payload type */ 345629Sgblack@eecs.umich.edu}; 355393SN/A 365629Sgblack@eecs.umich.edu/* 375390SN/A * Ethernet payload types - http://standards.ieee.org/regauth/ethertype 385390SN/A */ 395390SN/A#define ETH_TYPE_PUP 0x0200 /* PUP protocol */ 405390SN/A#define ETH_TYPE_IP 0x0800 /* IP protocol */ 415827Sgblack@eecs.umich.edu#define ETH_TYPE_ARP 0x0806 /* address resolution protocol */ 425632Sgblack@eecs.umich.edu#define ETH_TYPE_REVARP 0x8035 /* reverse addr resolution protocol */ 435629Sgblack@eecs.umich.edu#define ETH_TYPE_8021Q 0x8100 /* IEEE 802.1Q VLAN tagging */ 445390SN/A#define ETH_TYPE_IPV6 0x86DD /* IPv6 protocol */ 455390SN/A#define ETH_TYPE_MPLS 0x8847 /* MPLS */ 465629Sgblack@eecs.umich.edu#define ETH_TYPE_MPLS_MCAST 0x8848 /* MPLS Multicast */ 475629Sgblack@eecs.umich.edu#define ETH_TYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */ 485390SN/A#define ETH_TYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */ 495390SN/A#define ETH_TYPE_LOOPBACK 0x9000 /* used to test interfaces */ 505390SN/A 515390SN/A#define ETH_IS_MULTICAST(ea) (*(ea) & 0x01) /* is address mcast/bcast? */ 525390SN/A 535390SN/A#define ETH_ADDR_BROADCAST "\xff\xff\xff\xff\xff\xff" 545390SN/A 555390SN/A#define eth_pack_hdr(h, dst, src, type) do { \ 565390SN/A struct eth_hdr *eth_pack_p = (struct eth_hdr *)(h); \ 575393SN/A memmove(ð_pack_p->eth_dst, &(dst), ETH_ADDR_LEN); \ 585393SN/A memmove(ð_pack_p->eth_src, &(src), ETH_ADDR_LEN); \ 595632Sgblack@eecs.umich.edu eth_pack_p->eth_type = htons(type); \ 605827Sgblack@eecs.umich.edu} while (0) 615393SN/A 625611SN/Atypedef struct eth_handle eth_t; 635827Sgblack@eecs.umich.edu 645634Sgblack@eecs.umich.edu__BEGIN_DECLS 655393SN/Aeth_t *eth_open(const char *device); 665393SN/Aint eth_get(eth_t *e, eth_addr_t *ea); 675393SN/Aint eth_set(eth_t *e, const eth_addr_t *ea); 685632Sgblack@eecs.umich.edusize_t eth_send(eth_t *e, const void *buf, size_t len); 695393SN/Aeth_t *eth_close(eth_t *e); 705393SN/A 715390SN/Achar *eth_ntop(const eth_addr_t *eth, char *dst, size_t len); 725629Sgblack@eecs.umich.eduint eth_pton(const char *src, eth_addr_t *dst); 735390SN/Achar *eth_ntoa(const eth_addr_t *eth); 749808Sstever@gmail.com#define eth_aton eth_pton 755634Sgblack@eecs.umich.edu__END_DECLS 765390SN/A 775390SN/A#endif /* DNET_ETH_H */ 785390SN/A