ethernet.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (C) 1997, 1999, 2001, 2008 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /* Based on the FreeBSD version of this file. Curiously, that file
  15. lacks a copyright in the header. */
  16. #ifndef __NET_ETHERNET_H
  17. #define __NET_ETHERNET_H 1
  18. #include <sys/cdefs.h>
  19. #include <sys/types.h>
  20. #include <linux/if_ether.h> /* IEEE 802.3 Ethernet constants */
  21. __BEGIN_DECLS
  22. /* This is a name for the 48 bit ethernet address available on many
  23. systems. */
  24. struct ether_addr
  25. {
  26. u_int8_t ether_addr_octet[ETH_ALEN];
  27. } __attribute__ ((__packed__));
  28. /* 10Mb/s ethernet header */
  29. struct ether_header
  30. {
  31. u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
  32. u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
  33. u_int16_t ether_type; /* packet type ID field */
  34. } __attribute__ ((__packed__));
  35. /* Ethernet protocol ID's */
  36. #define ETHERTYPE_PUP 0x0200 /* Xerox PUP */
  37. #define ETHERTYPE_SPRITE 0x0500 /* Sprite */
  38. #define ETHERTYPE_IP 0x0800 /* IP */
  39. #define ETHERTYPE_ARP 0x0806 /* Address resolution */
  40. #define ETHERTYPE_REVARP 0x8035 /* Reverse ARP */
  41. #define ETHERTYPE_AT 0x809B /* AppleTalk protocol */
  42. #define ETHERTYPE_AARP 0x80F3 /* AppleTalk ARP */
  43. #define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */
  44. #define ETHERTYPE_IPX 0x8137 /* IPX */
  45. #define ETHERTYPE_IPV6 0x86dd /* IP protocol version 6 */
  46. #define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */
  47. #define ETHER_ADDR_LEN ETH_ALEN /* size of ethernet addr */
  48. #define ETHER_TYPE_LEN 2 /* bytes in type field */
  49. #define ETHER_CRC_LEN 4 /* bytes in CRC field */
  50. #define ETHER_HDR_LEN ETH_HLEN /* total octets in header */
  51. #define ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
  52. #define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
  53. /* make sure ethenet length is valid */
  54. #define ETHER_IS_VALID_LEN(foo) \
  55. ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
  56. /*
  57. * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
  58. * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
  59. * by an ETHER type (as given above) and then the (variable-length) header.
  60. */
  61. #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
  62. #define ETHERTYPE_NTRAILER 16
  63. #define ETHERMTU ETH_DATA_LEN
  64. #define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
  65. __END_DECLS
  66. #endif /* net/ethernet.h */