openblt

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

net.h (4354B)


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