/* protin.c */ /* * 'protin' 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). */ #define DEF_PROTIN /* * Includes */ #include #include #include "vtcpip.h" #include "dfault.h" #include "evtdef.h" #include "hstdef.h" #include "prodef.h" #include "prodat.h" #include "tcpdat.h" #include "mapskt.h" #include "bytprc.h" #include "cticks.h" /* * protinit () * * Calls all the other packet initialization keep this order as * some packet inits require lower layers already be initialized. */ VOID protinit() { /* * dlayer packets */ etherinit(); /* * ARP packets */ arpinit(); /* * ip packets */ ipinit(); /* * tcp packets */ tcpinit(); /* * udp packets */ udpinit(); } /* * nteventinit () * * Setup all the pointers for the event queue -- makes a circular list * which is required for error messages. ( called from Snetinit () ) */ VOID nteventinit() { int i; for(i=0; istate==SCLOSED) { skt = q; } else { sktstate[sknum] = q->state; lasttime[sknum] = q->out.lasttime; } /* * socket # to return */ retval = sknum++; } /* * Scan for STWAIT sockets with a time out */ if(skt==-1) { sknum = 0; while(skt==-1 && sknum WAITTIME) { skt = (struct socket *) mapskt(sknum); } /* * socket # to return */ retval = sknum++; } } /* * Scan for SLAST sockets with a time out */ if(skt==-1) { sknum = 0; while(skt==-1 && sknum LASTTIME) { skt = (struct socket *) mapskt(sknum); } /* * socket # to return */ retval = sknum++; } } /* * None available, get a new one */ if(skt==-1) { for(sknum=0; sktlist[sknum].region; sknum++) if(sknum>=GSCKTS) { /* * out of room for sockets */ ntposterr(500); return(-1); } skt = (struct socket *) mapskt(sknum); retval = sknum; } if(skt==-1) { ntposterr(505); return(-1); } /* * initialize sktlist parameters */ sktlist[retval].region = 1; sktlist[retval].jobnum = jobnum; sktlist[retval].inport = sktlist[retval].outport = 0; for(i=0; i<4; i++) sktlist[retval].remoteip[i] = '\0'; /* * clear the whole socket */ clrskt(skt); /* * queuing parameters */ setupwindow(&skt->in,QUEUESIZE); setupwindow(&skt->out,QUEUESIZE); /* * create a unique sequencial port number */ do { if(++seqnum > 0x3FFF) seqnum = 0x0800; for(i=0; iin.port = sktlist[retval].inport = seqnum; skt->credit = nnwin; skt->sendsize = nnmtu; skt->rto = MINRTO; strncpy(skt->hostname,Scon.me,sizeof(skt->hostname)); movebytes(&skt->tcpout,&ipblank,sizeof(DLAYER)+sizeof(IPLAYER)); skt->tcpout.i.tlen = 0; skt->tcpout.i.protocol = PROTTCP; skt->tcpout.t.source = intswap(seqnum); skt->tcpout.t.seq = longswap(skt->out.nxt); skt->tcps.proto = PROTTCP; movebytes(skt->tcps.source,nnipnum,4); /* * install default maximum segment size which will be * sent out in the first ACK-SYN packet */ skt->tcpout.x.options[0] = 2; skt->tcpout.x.options[1] = 4; nn = intswap(nnseg); movebytes((char *)&skt->tcpout.x.options[2],(char *)&nn,2); skt->tcpout.t.hlen = 24<<2; /* * This socket is allocated for WAITTIME */ skt->state = STWAIT; return(retval); } /* * setupwindow * * Configure information about a window *w* */ VOID setupwindow(w,wsize) register struct window *w; unsigned int wsize; { w->rdptr = w->wtptr = w->queue = w->where; /* * nothing here yet */ w->lasttime = cticks(NULL); w->ack = w->nxt = ((w->lasttime<<12) & 0x0FFFF000L); w->size = wsize - 1; }