Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

eth.h

Go to the documentation of this file.
00001 /*
00002  * eth.h
00003  *
00004  * Ethernet.
00005  *
00006  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
00007  *
00008  * $Id: eth.h,v 1.16 2005/01/25 21:29:12 dugsong Exp $
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              /* minimum frame length with CRC */
00021 #define ETH_LEN_MAX     1518            /* maximum frame length with CRC */
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;        /* destination address */
00032         eth_addr_t      eth_src;        /* source address */
00033         uint16_t        eth_type;       /* payload type */
00034 };
00035 
00036 /*
00037  * Ethernet payload types - http://standards.ieee.org/regauth/ethertype
00038  */
00039 #define ETH_TYPE_PUP    0x0200          /* PUP protocol */
00040 #define ETH_TYPE_IP     0x0800          /* IP protocol */
00041 #define ETH_TYPE_ARP    0x0806          /* address resolution protocol */
00042 #define ETH_TYPE_REVARP 0x8035          /* reverse addr resolution protocol */
00043 #define ETH_TYPE_8021Q  0x8100          /* IEEE 802.1Q VLAN tagging */
00044 #define ETH_TYPE_IPV6   0x86DD          /* IPv6 protocol */
00045 #define ETH_TYPE_MPLS   0x8847          /* MPLS */
00046 #define ETH_TYPE_MPLS_MCAST     0x8848  /* MPLS Multicast */
00047 #define ETH_TYPE_PPPOEDISC      0x8863  /* PPP Over Ethernet Discovery Stage */
00048 #define ETH_TYPE_PPPOE  0x8864          /* PPP Over Ethernet Session Stage */
00049 #define ETH_TYPE_LOOPBACK       0x9000  /* used to test interfaces */
00050 
00051 #define ETH_IS_MULTICAST(ea)    (*(ea) & 0x01) /* is address mcast/bcast? */
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(&eth_pack_p->eth_dst, &(dst), ETH_ADDR_LEN);    \
00058         memmove(&eth_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 /* DNET_ETH_H */

Generated on Sun May 14 14:51:10 2006 by  doxygen 1.4.2