protinit.c
来自「mcf5307实验源代码」· C语言 代码 · 共 781 行 · 第 1/3 页
C
781 行
/*************************************************************************/
/* */
/* CopyrIght (c) 1993 - 1996 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*
*
* Portions of this program were written by: */
/****************************************************************************
* *
* 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 *
****************************************************************************
* '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).
****************************************************************************/
/****************************************************************************/
/* */
/* FILENAME VERSION */
/* */
/* protinit.c 3.2 */
/* */
/* DESCRIPTION */
/* */
/* */
/* AUTHOR */
/* */
/* DATA STRUCTURES */
/* */
/* global compenent data stuctures defined in this file */
/* */
/* FUNCTIONS */
/* */
/* protinit */
/* timerinit */
/* etherinit */
/* ipinit */
/* udpinit */
/* tcpinit */
/* makeport */
/* makeuport */
/* setupwindow */
/* get_unique_port_number */
/* */
/* */
/* DEPENDENCIES */
/* */
/* No other file dependencies */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* Tim Krauskopf 10/87 Initial source release. */
/* JKM 5/88 Clean up for new release */
/* Craig L. Meredith 02/09/94 Release 1.0.G1.B version */
/* Glen Johnson 10/26/94 Updated setupwindow for release */
/* 1.0.G1.E */
/* Maiqi Qian 12/06/96 Fixed the time wrap around (spr0229) */
/* Maiqi Qian 01/29/96 Fixed the bugs in makeport. */
/* MQ 02/20/97 Fixed bug in get_unique_port_number. */
/* */
/****************************************************************************/
#ifdef PLUS
#include "nucleus.h"
#else
#include "nu_defs.h" /* added during ATI mods - 10/20/92, bgh */
#include "nu_extr.h"
#endif
#include "protocol.h"
#include "socketd.h"
#include "target.h"
#include "externs.h"
#include "data.h"
#include "netevent.h"
#include "tcp_errs.h"
#include "tcpdefs.h"
#include "tcp.h"
#include "sockext.h"
#include "dns.h"
#if SNMP_INCLUDED
#include "snmp_g.h"
#endif
/* Local Prototypes */
static void setupwindow (struct window *, uint16);
static void ipinit (void);
static void tcpinit (void);
static void udpinit (void);
static void etherinit (void);
static void tcp_timerinit (void);
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* tcp_timerinit */
/* */
/* DESCRIPTION */
/* */
/* Initialize the head and tail pointers of both the tcp_timerlist */
/* and the tcptimer_freelist to 0. */
/* */
/* CALLED BY */
/* protinit */
/* */
/* CALLS */
/* */
/* */
/*************************************************************************/
static void tcp_timerinit()
{
/* Initialize the head and tail pointers to 0 */
tcptimer_freelist.flink = tcptimer_freelist.blink = (tqe_t *)0;
tcp_timerlist.flink = tcp_timerlist.blink = (tqe_t *)0;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* protinit */
/* */
/* DESCRIPTION */
/* */
/* Calls all the other packet initialization keep this order as some */
/* packet inits require lower layers already be initialized. */
/* */
/* CALLED BY */
/* netinit */
/* */
/* CALLS */
/* */
/* etherinit */
/* tcp_timerinit */
/* arpint */
/* ipinit */
/* tcpinit */
/* udpinit */
/* ODH_Init */
/* DNS_Initialize */
/* */
/*************************************************************************/
STATUS protinit(VOID)
{
#if SNMP_INCLUDED
SNMP_Initialize();
#endif
etherinit(); /* dlayer packets */
tcp_timerinit(); /* init new timer stuff */
ARP_Init(); /* ARP packets */
ipinit(); /* ip packets */
tcpinit(); /* tcp packets */
udpinit(); /* udp packets */
ODH_Init(); /* Init ODH global variables. */
return (DNS_Initialize());
} /* protinit */
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* etherinit */
/* */
/* DESCRIPTION */
/* */
/* Setup the ethernet headers ( dlayer ) -- this needs to be done */
/* first as it is copied for the other headers */
/* */
/* CALLED BY */
/* protinit */
/* */
/* CALLS */
/* */
/* intswap */
/* */
/*************************************************************************/
static void etherinit (void)
{
/* some are broadcast */
memcpy ((void *)blankd.dest, (const void *)broadaddr, DADDLEN);
/* always from me */
memcpy ((void *)blankd.me, (const void *)nnmyaddr, DADDLEN); /* always from me */
blankd.type = intswap (EIP); /* mostly IP packets */
#ifdef INTERRUPT
/* vector number used for interrupt handler */
NU_Vect_Number = -1;
#endif
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* ipinit */
/* */
/* DESCRIPTION */
/* */
/* 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.*/
/* */
/* CALLED BY */
/* protinit */
/* */
/* CALLS */
/* */
/* netsetmask */
/* */
/*************************************************************************/
static void ipinit(void)
{
uint32 ip_addr;
#if SNMP_INCLUDED
UNSIGNED dest;
#endif
memcpy ((void *)&blankip.d, (const void *)&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 */
/* my return address */
memcpy ((void *)blankip.i.ipsource, (const void *)nnipnum, 4);
/* to ? */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?