openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

net.h (4363B)


      1 /* $Id: //depot/blt/netboot/net.h#3 $
      2 **
      3 ** Copyright 1998 Brian J. Swetland
      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 #pragma pack(2)
     29 
     30 /*
     31 typedef unsigned char uint8;
     32 typedef unsigned short uint16;
     33 typedef unsigned int uint32;
     34 */
     35 
     36 typedef struct 
     37 {
     38     uint8  dst[6];
     39     uint8  src[6];    
     40     uint16 type;    
     41 } net_ether;
     42 
     43 typedef struct 
     44 {
     45     uint8  ip_hdr_len:4;
     46     uint8  ip_version:4;
     47     uint8  ip_tos;
     48     uint16 ip_len;
     49     
     50     uint16 ip_id;
     51     uint16 ip_off;
     52     
     53     uint8  ip_ttl;
     54     uint8  ip_proto;    
     55     uint16 ip_chk;
     56     
     57     uint32 ip_src;
     58     uint32 ip_dst;        
     59 } net_ip;
     60 
     61 #define IP_PROTO_ICMP   1
     62 #define IP_PROTO_IGMP   2
     63 #define IP_PROTO_TCP    6
     64 #define IP_PROTO_UDP   17
     65 
     66 #define IP_TOS_MIN_DELAY  0x10
     67 #define IP_TOS_MAX_THRU   0x08
     68 #define IP_TOS_MAX_RELY   0x04
     69 #define IP_TOS_MIN_COST   0x02
     70 
     71 #define IP_FLAG_CE 0x8000
     72 #define IP_FLAG_DF 0x4000
     73 #define IP_FLAG_MF 0x2000
     74 #define IP_FLAG_MASK 0x1FFF
     75 
     76 typedef struct 
     77 {
     78     uint16 udp_src;
     79     uint16 udp_dst;
     80 
     81     uint16 udp_len;
     82     uint16 udp_chk;    
     83 } net_udp;
     84 
     85 typedef struct
     86 {
     87     uint8  icmp_type;
     88     uint8  icmp_code;
     89     uint16 icmp_chk;
     90 } net_icmp;
     91 
     92 typedef struct
     93 {
     94     net_icmp ping_icmp;    
     95     uint16   ping_id;
     96     uint16   ping_seq;    
     97 } net_icmp_ping;
     98 
     99 typedef struct
    100 {
    101     uint16 arp_hard_type;
    102     uint16 arp_prot_type;    
    103     uint8  arp_hard_size;
    104     uint8  arp_prot_size;
    105     uint16 arp_op;    
    106     uint8  arp_enet_sender[6];
    107     uint32 arp_ip_sender;
    108     uint8  arp_enet_target[6];
    109     uint32 arp_ip_target;    
    110 } net_arp;
    111 
    112 #define ARP_OP_REQUEST  1
    113 #define ARP_OP_REPLY    2
    114 #define RARP_OP_REQUEST 3
    115 #define RARP_OP_REPLY   4
    116 
    117 /* yeah, ugly as shit */
    118 #define ntohs(n) ( (((n) & 0xFF00) >> 8) | (((n) & 0x00FF) << 8) )
    119 #define htons(n) ( (((n) & 0xFF00) >> 8) | (((n) & 0x00FF) << 8) )
    120 #define ntohl(n) ( (((n) & 0xFF000000) >> 24) | (((n) & 0x00FF0000) >> 8) | (((n) & 0x0000FF00) << 8) | (((n) & 0x000000FF) << 24) )
    121 #define htonl(n) ( (((n) & 0xFF000000) >> 24) | (((n) & 0x00FF0000) >> 8) | (((n) & 0x0000FF00) << 8) | (((n) & 0x000000FF) << 24) )
    122 
    123 /*
    124 typedef struct 
    125 {
    126     uint32 ip;    
    127     uint16 flags;
    128     uint8  hw[6];   
    129 } net_arp_table;
    130 
    131 typedef struct 
    132 {
    133     uint32 dest;
    134     uint32 gw;
    135     uint32 mask;
    136     uint16 flags;
    137     net_iface *iface;    
    138 } net_route_table;
    139 
    140 
    141 typedef struct 
    142 {
    143     char name[8];
    144     uint32 addr;
    145     uint32 bcast;
    146     uint32 mask;
    147     uint16 flags;
    148     uint16 mtu;
    149     uint32 metric;
    150     
    151     uint32 stat_rx_packets;
    152     uint32 stat_rx_errors;
    153     uint32 stat_rx_dropped;
    154     uint32 stat_rx_overruns;
    155 
    156     uint32 stat_tx_packets;
    157     uint32 stat_tx_errors;
    158     uint32 stat_tx_dropped;
    159     uint32 stat_tx_overruns;
    160 
    161     void (*send)(void);
    162     void (*init)(void);    
    163     void (*add_proto)(net_proto *proto, uint16 id);
    164     
    165 } net_iface;
    166 
    167 #define IF_UP         0x0001
    168 #define IF_BROADCAST  0x0002
    169 #define IF_PROMISC    0x0004
    170 #define IF_LOOPBACK   0x0008
    171 #define IF_MULTICAST  0x0010
    172 #define IF_RUNNING    0x0020
    173 */