ethernet.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (C) 1997, 1999 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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /* Based on the FreeBSD version of this file. Curiously, that file
  16. lacks a copyright in the header. */
  17. #ifndef __NET_ETHERNET_H
  18. #define __NET_ETHERNET_H 1
  19. #include <sys/cdefs.h>
  20. #include <sys/types.h>
  21. #include <linux/if_ether.h> /* IEEE 802.3 Ethernet constants */
  22. __BEGIN_DECLS
  23. /* This is a name for the 48 bit ethernet address available on many
  24. systems. */
  25. struct ether_addr
  26. {
  27. u_int8_t ether_addr_octet[ETH_ALEN];
  28. } __attribute__ ((__packed__));
  29. /* 10Mb/s ethernet header */
  30. struct ether_header
  31. {
  32. u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
  33. u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
  34. u_int16_t ether_type; /* packet type ID field */
  35. } __attribute__ ((__packed__));
  36. /* Ethernet protocol ID's */
  37. #define ETHERTYPE_PUP 0x0200 /* Xerox PUP */
  38. #define ETHERTYPE_IP 0x0800 /* IP */
  39. #define ETHERTYPE_ARP 0x0806 /* Address resolution */
  40. #define ETHERTYPE_REVARP 0x8035 /* Reverse ARP */
  41. #define ETHER_ADDR_LEN ETH_ALEN /* size of ethernet addr */
  42. #define ETHER_TYPE_LEN 2 /* bytes in type field */
  43. #define ETHER_CRC_LEN 4 /* bytes in CRC field */
  44. #define ETHER_HDR_LEN ETH_HLEN /* total octets in header */
  45. #define ETHER_MIN_LEN (ETH_ZLEN + ETH_CRC_LEN) /* min packet length */
  46. #define ETHER_MAX_LEN (ETH_FRAME_LEN + ETH_CRC_LEN) /* max packet length */
  47. /* make sure ethenet length is valid */
  48. #define ETHER_IS_VALID_LEN(foo) \
  49. ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
  50. /*
  51. * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
  52. * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
  53. * by an ETHER type (as given above) and then the (variable-length) header.
  54. */
  55. #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
  56. #define ETHERTYPE_NTRAILER 16
  57. #define ETHERMTU ETH_DATA_LEN
  58. #define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
  59. __END_DECLS
  60. #endif /* net/ethernet.h */