net.c
来自「mcf5307实验源代码」· C语言 代码 · 共 794 行 · 第 1/3 页
C
794 行
default :
/* Since it failed on the assumption try checking it one
more time without protocol field compression. */
ppp_protocol = (uint16 *)buffer_list.head->packet;
switch (intswap(*ppp_protocol))
{
case PPP_IP_PROTOCOL :
(uchar *)ppp_pkt += PPP_WITH_ADDR_COMPRESS_START;
(uchar *)ppp_pkt -= sizeof (DLAYER);
ipinterpret ((struct ip *)ppp_pkt);
break;
case PPP_IP_CONTROL_PROTOCOL :
PPP_NCP_IP_Interpret ((uchar *)ppp_pkt +
PPP_WITH_ADDR_COMPRESS_START);
break;
case PPP_CHAP_PROTOCOL :
PPP_CHAP_Interpret ((uchar *)ppp_pkt +
PPP_WITH_ADDR_COMPRESS_START);
break;
case PPP_PAP_PROTOCOL :
PPP_PAP_Interpret ((uchar *)ppp_pkt +
PPP_WITH_ADDR_COMPRESS_START);
break;
default :
/* Try checking it without address and control field
compression. */
/* Check the address and control fields. No compression. */
if ((ppp_pkt->address == PPP_HDLC_ADDRESS) &&
(ppp_pkt->control == PPP_HDLC_CONTROL))
/* Assume the protocol field is compressed, this
will be the case most of the time. */
switch (intswap (ppp_pkt->protocol) >> 8)
{
case PPP_IP_COMPRESS_PROTOCOL :
(uchar *)ppp_pkt += PPP_WITH_PROT_COMPRESS_START;
(uchar *)ppp_pkt -= sizeof (DLAYER);
ipinterpret ((struct ip *)ppp_pkt);
break;
default :
/* Since it failed on the assumption try checking
it one more time without protocol field
compression. */
switch (intswap(ppp_pkt->protocol))
{
case PPP_IP_PROTOCOL :
(uchar *)ppp_pkt += PPP_PROTOCOL_START;
(uchar *)ppp_pkt -= sizeof (DLAYER);
ipinterpret ((struct ip *)ppp_pkt);
break;
case PPP_IP_CONTROL_PROTOCOL :
PPP_NCP_IP_Interpret ((uchar *)ppp_pkt +
PPP_PROTOCOL_START);
break;
case PPP_LINK_CONTROL_PROTOCOL :
PPP_LCP_Interpret ((uchar *)ppp_pkt +
PPP_PROTOCOL_START);
break;
case PPP_CHAP_PROTOCOL :
PPP_CHAP_Interpret ((uchar *)ppp_pkt +
PPP_PROTOCOL_START);
break;
case PPP_PAP_PROTOCOL :
PPP_PAP_Interpret ((uchar *)ppp_pkt +
PPP_PROTOCOL_START);
break;
default :
/* This pkt must be corrupted so just
discard it. */
_silent_discards++;
dll_update_lists(&buffer_list, &buffer_freelist);
break;
} /* switch - no compression */
} /* switch - just protocol field compression */
else /* if address and control fields ok */
{
/* This pkt must be corrupted so just
discard it. */
_silent_discards++;
dll_update_lists(&buffer_list, &buffer_freelist);
}
} /* switch - just address and control field compresssion */
} /* switch - all compression */
#endif
#endif
} /* end if */
else
{
all = 0;
}
} while (all); /* should we look for more to deal with? */
return nmuxed; /* no packets anymore */
} /* end demux() */
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* dlayersend */
/* */
/* DESCRIPTION */
/* */
/* This particular dlayer routine is for Ethernet. It will have to be */
/* replaced for any other dlayer. */
/* */
/* Ethernet addresses are resolved at higher levels because they */
/* will only need to be resolved once per logical connection, instead */
/* of once per packet. Not too layer-like, but hopefully modular. */
/* */
/* CALLED BY */
/* rarp */
/* netusend */
/* neticmpturn */
/* tcpreset */
/* netusend */
/* NET_Send */
/* */
/* CALLS */
/* */
/* NU_Xmit_Packet */
/* */
/*************************************************************************/
int16 dlayersend (DLAYER *ptr, uint16 size)
{
sshort ret;
int16 i;
if (size & 0x01)
size += 1;
for (i = 0; i < SQwait; i++)
;
if ((++OKpackets) > 10)
{
SQwait -= 10;
OKpackets = 0;
} /* end if */
if (SQwait < 10)
SQwait = 10;
#ifdef NU_PPP
ret = NU_Xmit_Packet ((uchar *) ptr, size, PPP_IP_PROTOCOL);
#else
ret = NU_Xmit_Packet ((uchar *) ptr, size);
#endif
/* automatic, immediate retry once */
if (ret)
{
#ifdef NU_PPP
if (ret == NU_Xmit_Packet ((uchar *) ptr, size, PPP_IP_PROTOCOL))
#else
if (ret == NU_Xmit_Packet ((uchar *) ptr, size))
#endif
{
NU_Tcp_Log_Error (TCP_NET_JAM, TCP_RECOVERABLE, __FILE__, __LINE__);
}
} /* end if */
return ret;
} /* end dlayersend() */
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* dlayerinit */
/* */
/* DESCRIPTION */
/* */
/* Do machine dependent initializations of whatever hardware we have */
/* (happens to be ethernet board here ) */
/* */
/* CALLED BY */
/* netinit */
/* */
/* CALLS */
/* */
/* initbuffer */
/* NU_Etopen */
/* */
/*************************************************************************/
int16 dlayerinit (void)
{
int16 my_var;
#ifdef PROC_29K
if (initbuffer () || !NU_Etopen)
#else
if (initbuffer())
#endif
{
return (-10);
}
/* Call (*NU_Etopen) first to be sure any board/driver initializations are
taken care of. */
#ifdef PROC_29K
my_var = ((*NU_Etopen)(nnmyaddr, nnirq, nnaddr, nnioaddr));
#else
my_var = NU_Etopen (&nnmyaddr[0], Scon.irqnum, Scon.address, Scon.ioaddr);
#endif
#ifdef PROC_29K
/* Read the MACE address. */
(*NU_Get_Address)(nnmyaddr, nnaddr, nnioaddr);
#endif /* PROC_29K */
return (my_var);
} /* end dlayerinit */
void dlayershut (void )
{
/* Empty function */
/* Used to call NU_Etclose, but that function does nothing */
}
#ifdef NOT_USED
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* statcheck */
/* */
/* DESCRIPTION */
/* */
/* Look at the connection status of the memory buffers to see if the */
/* allocation schemes are working. Only used as a debug tool. */
/* */
/* CALLED BY */
/* */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?