Back to index

glibc  2.9
ethernet.h
Go to the documentation of this file.
00001 /* Copyright (C) 1997, 1999, 2001, 2008 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /* Based on the FreeBSD version of this file. Curiously, that file
00020    lacks a copyright in the header. */
00021 
00022 #ifndef __NET_ETHERNET_H
00023 #define __NET_ETHERNET_H 1
00024 
00025 #include <sys/cdefs.h>
00026 #include <sys/types.h>
00027 #include <linux/if_ether.h>     /* IEEE 802.3 Ethernet constants */
00028 
00029 __BEGIN_DECLS
00030 
00031 /* This is a name for the 48 bit ethernet address available on many
00032    systems.  */
00033 struct ether_addr
00034 {
00035   u_int8_t ether_addr_octet[ETH_ALEN];
00036 } __attribute__ ((__packed__));
00037 
00038 /* 10Mb/s ethernet header */
00039 struct ether_header
00040 {
00041   u_int8_t  ether_dhost[ETH_ALEN]; /* destination eth addr     */
00042   u_int8_t  ether_shost[ETH_ALEN]; /* source ether addr */
00043   u_int16_t ether_type;                    /* packet type ID field    */
00044 } __attribute__ ((__packed__));
00045 
00046 /* Ethernet protocol ID's */
00047 #define       ETHERTYPE_PUP        0x0200          /* Xerox PUP */
00048 #define ETHERTYPE_SPRITE    0x0500        /* Sprite */
00049 #define       ETHERTYPE_IP         0x0800        /* IP */
00050 #define       ETHERTYPE_ARP        0x0806        /* Address resolution */
00051 #define       ETHERTYPE_REVARP     0x8035        /* Reverse ARP */
00052 #define ETHERTYPE_AT        0x809B        /* AppleTalk protocol */
00053 #define ETHERTYPE_AARP             0x80F3        /* AppleTalk ARP */
00054 #define       ETHERTYPE_VLAN              0x8100        /* IEEE 802.1Q VLAN tagging */
00055 #define ETHERTYPE_IPX              0x8137        /* IPX */
00056 #define       ETHERTYPE_IPV6              0x86dd        /* IP protocol version 6 */
00057 #define ETHERTYPE_LOOPBACK  0x9000        /* used to test interfaces */
00058 
00059 
00060 #define       ETHER_ADDR_LEN       ETH_ALEN                 /* size of ethernet addr */
00061 #define       ETHER_TYPE_LEN       2                        /* bytes in type field */
00062 #define       ETHER_CRC_LEN 4                        /* bytes in CRC field */
00063 #define       ETHER_HDR_LEN ETH_HLEN                 /* total octets in header */
00064 #define       ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
00065 #define       ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
00066 
00067 /* make sure ethenet length is valid */
00068 #define       ETHER_IS_VALID_LEN(foo)     \
00069        ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
00070 
00071 /*
00072  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
00073  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
00074  * by an ETHER type (as given above) and then the (variable-length) header.
00075  */
00076 #define       ETHERTYPE_TRAIL             0x1000        /* Trailer packet */
00077 #define       ETHERTYPE_NTRAILER   16
00078 
00079 #define       ETHERMTU      ETH_DATA_LEN
00080 #define       ETHERMIN      (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
00081 
00082 __END_DECLS
00083 
00084 #endif /* net/ethernet.h */