home *** CD-ROM | disk | FTP | other *** search
- /*
- * PROTINIT.C
- *
- * Packet template initialization routines
- *
- ***************************************************************************
- * *
- * part of: *
- * TCP/UDP/ICMP/IP Network kernel for NCSA Telnet *
- * by Tim Krauskopf *
- * *
- * National Center for Supercomputing Applications *
- * 152 Computing Applications Building *
- * 605 E. Springfield Ave. *
- * Champaign, IL 61820 *
- * *
- * Copyright (c) 1987, Board of Trustees of the University of Illinois *
- * *
- ****************************************************************************
- * 'protinit' initializes packets to make them ready for transmission.
- * For many purposes, pre-initialized packets are created for use by the
- * protocol routines, especially to save time creating packets for
- * transmit.
- *
- * Important note : Assumes that the hardware has been initialized and has
- * set all the useful addresses such as the hardware addresses.
- *
- * As this is a convenient place for it, this file contains many of the
- * data declarations for packets which are mostly static (pre-allocated).
- * Revision history:
- ****************************************************************************
- *
- * 10/87 Initial source release, Tim Krauskopf
- * 5/88 clean up for 2.3 release, JKM
- *
- */
-
- /*
- * Includes
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #if defined(MSC)
- #ifdef __TURBOC__
- #include <alloc.h>
- #else
- #include <malloc.h>
- #endif
- #endif
- #ifdef MEMORY_DEBUG
- #include "memdebug.h"
- #endif
- #include "protocol.h"
- #include "data.h"
- #include "externs.h"
-
- /************************************************************************/
- /*
- * protinit ()
- *
- * Calls all the other packet initialization keep this order as some packet
- * inits require lower layers already be initialized.
- *
- */
- void protinit(void)
- {
- etherinit(); /* dlayer packets */
- arpinit(); /* ARP packets */
- ipinit(); /* ip packets */
- tcpinit(); /* tcp packets */
- udpinit(); /* udp packets */
- }
-
- /*************************************************************************/
- /*
- * neteventinit ()
- *
- * Setup all the pointers for the event queue -- makes a circular list which
- * is required for error messages. ( called from Snetinit () )
- *
- */
-
- void neteventinit (void)
- {
- int i;
-
- for(i=0; i<NEVENTS; i++)
- nnq[i].next=i+1;
- nnq[NEVENTS-1].next=-1;
- nnefirst=0;
- nnelast=0;
- nnefree=1;
- }
-
- /*
- * etherinit ()
- *
- * Setup the ethernet headers ( dlayer ) -- this needs to be done first as it
- * is copied for the other headers
- *
- */
- void etherinit(void)
- {
- movebytes(broadaddr,bseed,DADDLEN);
- movebytes(blankd.dest,broadaddr,DADDLEN); /* some are broadcast */
- movebytes(blankd.me,nnmyaddr,DADDLEN); /* always from me */
- blankd.type=EIP; /* mostly IP packets */
- }
-
- /*************************************************************************/
- /*
- * arpinit ()
- * Setup an arp packet -- also sets up an arp cache
- *
- */
- void arpinit(void)
- {
- int i;
-
- movebytes(&arp.d,&blankd,sizeof(DLAYER));
- arp.d.type=EARP; /* 0x0806 is ARP type */
- arp.hrd=intswap(HTYPE); /* Ether=1 */
- arp.pro=intswap(ARPPRO); /* IP protocol=0x0800 */
- arp.hln=DADDLEN; /* Ethernet hardware length */
- arp.pln=4; /* IP length=4 */
- movebytes(arp.sha,nnmyaddr,DADDLEN); /* sender's hardware addr */
- movebytes(arp.tha,broadaddr,DADDLEN); /* target hardware addr */
- movebytes(arp.spa,nnipnum,4); /* sender's IP addr */
- /*
- * initialize the ARP cache to 0 time, none are gateways to start
- */
- for(i=0; i<CACHELEN; i++) {
- arpc[i].tm=0L;
- arpc[i].gate=0;
- }
- }
-
- /*************************************************************************/
- /*
- * ipinit ()
- *
- * initialize on packet to use for internet transmission -- most packets will
- * be tcp/udp, so they will be initialized at a different layer, but some
- * require a generic ip packet.
- *
- * Also takes a guess at setting a netmask if it hasn't happened by now.
- *
- */
- void ipinit(void)
- {
- movebytes(&blankip.d,&blankd,sizeof(DLAYER));
- blankip.i.versionandhdrlen=0x45; /* smallest header, version 4 */
- blankip.i.service=0; /* normal service */
- blankip.i.tlen=576; /* no data yet, maximum size */
- blankip.i.ident=0;
- blankip.i.frags=0; /* not a fragment of a packet */
- blankip.i.ttl=100; /* 100 seconds should be enough */
- blankip.i.protocol=PROTUDP; /* default to UDP */
- blankip.i.check=0; /* disable checksums for now */
- movebytes(blankip.i.ipsource,nnipnum,4); /* my return address */
- movebytes(blankip.i.ipdest,broadip,4); /* to ? */
-
- /*
- * create a mask which can determine whether a machine is on the same wire
- * or not. RFC950
- * Only set the mask if not previously set.
- * This mask may be replace* orom SnLEN) TcTlmostly I