net.c
来自「mcf5307实验源代码」· C语言 代码 · 共 794 行 · 第 1/3 页
C
794 行
/****************************************************************************/
/* */
/* 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 implicity accepts the terms */
/* of the license. */
/* */
/****************************************************************************/
/****************************************************************************/
/* */
/* FILENAME VERSION */
/* */
/* NET.C 3.2 */
/* */
/* DESCRIPTION */
/* */
/* This file will hold all the routines which are used to interface with */
/* the hardware. They will handle the basic functions of of setup, xmit,*/
/* receive, etc. This file will change depending on the type of chip(s) */
/* you are using to handle the TCP/IP interface. These file are generic */
/* and will need to be changed for your specified interface. This file */
/* will use structure overlays for the chip(s) with the offset defines */
/* from the file chipint.h. */
/* */
/* AUTHOR */
/* */
/* Craig L. Meredith */
/* */
/* DATA STRUCTURES */
/* */
/* Check in file 'chipint.h' */
/* */
/* FUNCTIONS */
/* */
/* netarpme */
/* initbuffer */
/* demux */
/* dlayersend */
/* dlayerinit */
/* dlayershut */
/* NET_Send */
/* */
/* DEPENDENCIES */
/* */
/* other file dependencies */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* Craig L. Meredith 02/03/93 Inital version. */
/* Craig L. Meredith 02/09/94 Release new version. */
/* Craig L. Meredith 02/16/94 Added new macros for the inportb, outportb.*/
/* Craig L. Meredith 02/22/94 Converted the I/O parameter to a ulint. */
/* Also removed the INTEL_80X86 define since */
/* this file is only for the DOS port */
/* Glen Johnson 10/26/94 Modified demux and initbuffer to handle */
/* buffer pointer management. */
/* Glen Johnson 10/05/95 Added the function NET_Send. */
/* */
/****************************************************************************/
/*
*
* 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 *
* *
*****************************************************************************/
#include "target.h"
#include "protocol.h"
#include "tcpdefs.h"
#include "socketd.h"
#include "externs.h"
#include "data.h"
#include "hostform.h"
#include "tcp_errs.h"
#if SNMP_INCLUDED
#include "snmp_g.h"
#endif
#ifdef NU_PPP
#include "ppp.h"
#endif
#ifdef PLUS
#include "nucleus.h"
#else /* !PLUS */
#include "nu_extr.h" /* added during ATI mods - 11/1/92, bgh */
#endif /* !PLUS */
extern int16 SQwait;
extern int16 OKpackets;
#ifdef PROC_29K
/* 29200 initialization found in IOP_NETS.C */
extern uint8 rstat; /* last status from read */
extern void Tao_LoadOldSR(void);
extern void Tao_SaveOldSR(void);
static uint nnirq=3, nnaddr=0xd000, nnioaddr=0x300;
#endif /* PROC_29K */
/* Local Prototypes */
static int16 initbuffer (void);
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* netarpme */
/* */
/* DESCRIPTION */
/* */
/* Send an arp to my address. arpinterpret will notice any response. */
/* Checks for adapters which receive their own broadcast packets. */
/* */
/* CALLED BY */
/* Snetinit */
/* */
/* CALLS */
/* */
/* arp_request */
/* */
/*************************************************************************/
int16 netarpme (uint8 *s)
{
arp_request (s); /* send it */
return (NU_FALSE);
} /* end netarpme() */
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* demux */
/* */
/* DESCRIPTION */
/* */
/* Find the packets in the buffer, determine their lowest level */
/* packet type and call the correct interpretation routines */
/* */
/* the 'all' parameter tells demux whether it should attempt to */
/* empty the input packet buffer or return after the first packet */
/* is dealt with. */
/* */
/* returns the number of packets demuxed */
/* */
/* CALLED BY */
/* bootp */
/* netsleep */
/* NU_EventDispatcher */
/* */
/* CALLS */
/* */
/* NU_Recv_Packet */
/* intswap */
/* arpinterpret */
/* ipinterpret */
/* dll_update_lists */
/* */
/*************************************************************************/
int16 demux (int16 all)
{
uint16 getcode;
int16 nmuxed;
#ifndef POINT_TO_POINT
DLAYER *firstlook;
#else
char *ip_pkt;
#ifdef NU_PPP
PPP_HEADER *ppp_pkt;
uchar *ppp_compress_protocol;
uint16 frame_check, *ppp_protocol;
extern uint16 _silent_discards;
#endif
#endif
nmuxed = 0;
if(!NU_Etopen)
{
return (NU_FALSE);
} /* end NU_Etupdate not defined */
do
{ /* while all flag is on */
#if !defined INTERRUPT
NU_Recv_Packet (); /* NU_NULL operation for 3COM */
#endif
/* If there packets in the buffer, process them. */
if (buffer_list.head != NU_NULL)
{
nmuxed++;
#ifndef POINT_TO_POINT
firstlook=(DLAYER *)(buffer_list.head->packet); /* where packet is */
getcode = firstlook->type; /* where does it belong? */
switch (intswap(getcode))
{ /* what to do with it? */
case EARP:
case ERARP:
arpinterpret ((ARPKT *)firstlook); /* handle ARP packet */
/* We are finished with the ARP packet. */
/* Drop the packet by placing it back on the buffer_freelist. */
dll_update_lists(&buffer_list, &buffer_freelist);
break;
case EIP:
ipinterpret ((IPKT *)firstlook);
break;
default:
/* Deallocate the space taken up by this useless packet. */
/* Drop the packet by placing it back on the buffer_freelist. */
dll_update_lists(&buffer_list, &buffer_freelist);
break;
} /* end switch */
#else
#ifndef NU_PPP
ip_pkt = (char *)buffer_list.head->packet;
ip_pkt -= sizeof(DLAYER);
ipinterpret ((IPKT *)ip_pkt);
#else
/* Get a pointer to the head of the packet. */
ppp_pkt = (PPP_HEADER *)buffer_list.head->packet;
ppp_compress_protocol = (uchar *)buffer_list.head->packet;
/* Now we must check to make sure it is a valid packet before
it is passed on to get interpreted. We have to check for all
combinations of compression. For the first check we will assume
all compression is turned on. */
/* For address and control field compression they are simple omitted.
So there is no need to check for them. */
/* Assume the protocol field is compressed, this will be the
case most of the time. */
switch (*ppp_compress_protocol)
{
case PPP_IP_COMPRESS_PROTOCOL :
(uchar *)ppp_pkt += PPP_WITH_BOTH_COMPRESS_START;
(uchar *)ppp_pkt -= sizeof (DLAYER);
ipinterpret ((struct ip *)ppp_pkt);
break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?