eth.h (3167B)
1 /* $Id: //depot/blt/include/blt/network/eth.h#1 $ 2 ** 3 ** Copyright 1999 Sidney Cammeresi 4 ** All rights reserved. 5 ** 6 ** Redistribution and use in source and binary forms, with or without 7 ** modification, are permitted provided that the following conditions 8 ** are met: 9 ** 1. Redistributions of source code must retain the above copyright 10 ** notice, this list of conditions, and the following disclaimer. 11 ** 2. Redistributions in binary form must reproduce the above copyright 12 ** notice, this list of conditions, and the following disclaimer in the 13 ** documentation and/or other materials provided with the distribution. 14 ** 3. The name of the author may not be used to endorse or promote products 15 ** derived from this software without specific prior written permission. 16 ** 17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /* 30 * XXX all multibyte quanities are in network byte order 31 */ 32 33 #ifndef _BLT_NETWORK_ETH_H_ 34 #define _BLT_NETWORK_ETH_H_ 35 36 #include <blt/types.h> 37 38 #pragma pack(2) 39 40 #define ETH_PROT_IP 0x0800 41 #define ETH_PROT_ARP 0x0806 42 #define ETH_PROT_RARP 0x8035 43 44 #define ETH_ARP_OP_REQUEST 1 45 #define ETH_ARP_OP_REPLY 2 46 #define ETH_RARP_OP_REQUEST 3 47 #define ETH_RARP_OP_REPLY 4 48 49 struct mbuf; 50 51 typedef struct __eth_drv_t 52 { 53 const char *name; 54 void (*output) (int num, struct mbuf *); 55 struct __eth_drv_t *next; 56 } eth_drv_t; 57 58 typedef struct __eth_dev_t 59 { 60 eth_drv_t *dev_driver; 61 int dev_num; 62 char dev_addr[6]; 63 void *dev_data; 64 struct __eth_dev_t *next; 65 } eth_dev_t; 66 67 typedef struct 68 { 69 uint8 dst[6]; 70 uint8 src[6]; 71 uint16 frame_type; 72 } ether_header; 73 74 typedef struct 75 { 76 ether_header header; 77 uint16 hard_type; 78 uint16 prot_type; 79 uint8 hard_size; 80 uint8 prot_size; 81 uint16 op; 82 uint8 send_eth_addr[6]; 83 uint8 send_ip_addr[4]; 84 uint8 targ_eth_addr[6]; 85 uint8 targ_ip_addr[4]; 86 uint8 __pad__[18]; 87 } arp_packet; 88 89 typedef struct __eth_prot_t 90 { 91 const char *name; 92 int num; 93 void (*input) (struct mbuf *); 94 struct __eth_prot_t *next; 95 } eth_prot_t; 96 97 char eth_broadcast_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 98 99 #ifdef _NETWORK 100 101 extern eth_drv_t *drvlist; 102 extern eth_dev_t *devlist; 103 extern eth_prot_t *protlist; 104 105 void register_eth_driver (eth_drv_t *drv); 106 void unregister_eth_driver (eth_drv_t *drv); 107 void register_eth_device (eth_dev_t *dev); 108 void unregister_eth_device (eth_dev_t *dev); 109 void register_eth_protocol (eth_prot_t *prot); 110 void unregister_eth_protocol (eth_prot_t *prot); 111 void eth_input (struct mbuf *mbuf); 112 113 #endif 114 115 #endif 116