Home | History | Annotate | Line # | Download | only in sboot
etherfun.h revision 1.4.38.1
      1  1.4.38.1   jruoho /*	$NetBSD: etherfun.h,v 1.4.38.1 2011/06/06 09:06:16 jruoho Exp $	*/
      2       1.2    perry 
      3       1.1    chuck /*
      4       1.1    chuck  * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
      5       1.1    chuck  * All rights reserved.
      6       1.1    chuck  *
      7       1.1    chuck  * Redistribution and use in source and binary forms, with or without
      8       1.1    chuck  * modification, are permitted provided that the following conditions
      9       1.1    chuck  * are met:
     10       1.1    chuck  * 1. Redistributions of source code must retain the above copyright
     11       1.1    chuck  *    notice, this list of conditions and the following disclaimer.
     12       1.1    chuck  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1    chuck  *    notice, this list of conditions and the following disclaimer in the
     14       1.1    chuck  *    documentation and/or other materials provided with the distribution.
     15       1.1    chuck  *
     16       1.1    chuck  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.1    chuck  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18       1.1    chuck  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19       1.1    chuck  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20       1.1    chuck  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21       1.1    chuck  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22       1.1    chuck  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23       1.1    chuck  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24       1.1    chuck  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25       1.1    chuck  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26       1.1    chuck  */
     27       1.1    chuck /* etherfun.h */
     28       1.1    chuck 
     29       1.1    chuck /* constants */
     30       1.1    chuck /* ether header */
     31       1.1    chuck #define ETYPE_RARP 0x8035  /* ethertype is RARP */
     32       1.1    chuck #define ETYPE_IP   0x800   /* ethertype is IP   */
     33       1.1    chuck 
     34       1.1    chuck /* rev arp */
     35       1.1    chuck #define PTYPE_IP 0x800     /* Protocol type is IP      */
     36       1.1    chuck #define OPCODE_RARP 3      /* Optype is REVARP request */
     37       1.1    chuck #define OPCODE_REPLY 4     /* Optype is REVARP reply   */
     38       1.1    chuck 
     39       1.1    chuck /* ip header */
     40       1.1    chuck #define  IPP_UDP 17        /* IP Protocol is UDP       */
     41       1.1    chuck #define  IP_VERSION 4      /* IP version number        */
     42       1.1    chuck #define  IP_HLEN 5         /* IP header length is a fixed 50 bytes */
     43       1.1    chuck #define N 1536
     44       1.1    chuck 
     45       1.1    chuck /* tftp header */
     46       1.1    chuck #define FTPOP_ACKN 4      /* Opcode is acknowledge     */
     47       1.1    chuck #define FTPOP_ERR 5       /* Opcode is Error	       */
     48       1.1    chuck #define FTP_PORT 69       /* Standard TFTP port number */
     49       1.1    chuck #define MSG "\0\1xxxxxxxx.147\0octet\0" /* implicit NULL */
     50       1.1    chuck 
     51       1.1    chuck /* data structures */
     52       1.1    chuck 
     53       1.1    chuck struct  ether_header {
     54       1.4  tsutsui 	u_char  ether_dhost[6];
     55       1.4  tsutsui 	u_char  ether_shost[6];
     56       1.4  tsutsui 	u_short ether_type;
     57       1.1    chuck };
     58       1.1    chuck 
     59       1.1    chuck struct  ether_arp {
     60       1.4  tsutsui 	u_short ar_hrd;		/* format of hardware address */
     61       1.4  tsutsui 	u_short ar_pro;		/* format of protocol address */
     62       1.4  tsutsui 	u_char  ar_hln;		/* length of hardware address */
     63       1.4  tsutsui 	u_char  ar_pln;		/* length of protocol address */
     64       1.4  tsutsui 	u_short ar_op;
     65       1.4  tsutsui 	u_char  arp_sha[6];	/* sender hardware address */
     66       1.4  tsutsui 	u_char  arp_spa[4];	/* sender protocol address */
     67       1.4  tsutsui 	u_char  arp_tha[6];	/* target hardware address */
     68       1.4  tsutsui 	u_char  arp_tpa[4];	/* target protocol address */
     69       1.1    chuck };
     70       1.1    chuck 
     71       1.1    chuck struct ip {
     72       1.4  tsutsui 	u_char  ip_v:4,			/* version */
     73       1.4  tsutsui 		ip_hl:4;		/* header length */
     74       1.4  tsutsui 	u_char  ip_tos;			/* type of service */
     75       1.4  tsutsui 	short   ip_len;			/* total length */
     76       1.4  tsutsui 	u_short ip_id;			/* identification */
     77       1.4  tsutsui 	short   ip_off;			/* fragment offset field */
     78       1.4  tsutsui #define IP_DF 0x4000			/* dont fragment flag */
     79       1.4  tsutsui #define IP_MF 0x2000			/* more fragments flag */
     80       1.4  tsutsui #define IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
     81       1.4  tsutsui 	u_char  ip_ttl;			/* time to live */
     82       1.4  tsutsui 	u_char  ip_p;			/* protocol */
     83       1.4  tsutsui 	u_short ip_sum;			/* checksum */
     84       1.1    chuck 	u_char  ip_src[4];
     85       1.4  tsutsui 	u_char  ip_dst[4];		/* source and dest address */
     86       1.1    chuck };
     87       1.1    chuck 
     88       1.1    chuck struct udp {
     89       1.4  tsutsui 	u_short uh_sport;
     90       1.1    chuck 	u_short uh_dport;
     91       1.1    chuck 	short uh_ulen;
     92       1.1    chuck 	u_short uh_sum;
     93       1.1    chuck };
     94       1.1    chuck 
     95       1.1    chuck struct tftph {
     96       1.4  tsutsui 	u_short op_code;
     97       1.4  tsutsui 	u_short block;
     98       1.1    chuck };
     99       1.1    chuck 
    100       1.1    chuck struct tftphr {
    101       1.4  tsutsui 	struct tftph info;
    102       1.4  tsutsui 	char data[1];
    103       1.1    chuck };
    104       1.1    chuck 
    105       1.1    chuck /* globals */
    106       1.1    chuck int last_ack;
    107       1.3      mrg u_char buf[N];
    108       1.1    chuck struct ether_header *eh = (struct ether_header *)buf;
    109       1.1    chuck struct ether_arp *rarp =
    110       1.4  tsutsui     (struct ether_arp *)(buf + sizeof(struct ether_header));
    111       1.1    chuck struct ip *iph = (struct ip *)(buf + sizeof(struct ether_header));
    112       1.1    chuck struct udp *udph = (struct udp *)(buf + sizeof(struct ether_header) +
    113       1.4  tsutsui     sizeof(struct ip));
    114       1.3      mrg u_char *tftp_r = buf + sizeof(struct ether_header) + sizeof(struct ip) +
    115       1.4  tsutsui     sizeof(struct udp);
    116       1.1    chuck struct tftph *tftp_a = (struct tftph *)(buf + sizeof(struct ether_header) +
    117       1.4  tsutsui     sizeof(struct ip) + sizeof(struct udp));
    118       1.1    chuck struct tftphr *tftp = (struct tftphr *)(buf + sizeof(struct ether_header) +
    119       1.4  tsutsui     sizeof(struct ip) + sizeof(struct udp));
    120