📄 new_ip.c
字号:
/*************************************************************************/
/* */
/* 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. */
/* */
/*************************************************************************/
/******************************************************************************/
/* */
/* FILENAME VERSION */
/* */
/* NEW_IP.C 3.2 */
/* */
/* DESCRIPTION */
/* */
/* This file contains the source for utility routines used by many */
/* of the TCP/IP files. Formerly, they were in assembly language. */
/* They have been converted to C files for portability. */
/* */
/* AUTHOR */
/* */
/* Barbara G. Harwell, Accelerated Technology Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* No data structures defined in this file. */
/* */
/* FUNCTIONS */
/* */
/* ipcheck Checksums an IP header */
/* tcpcheck Checksums a TCP header */
/* longswap Swaps 4 bytes of a long number */
/* intswap Swaps 2 bytes of a number */
/* comparen Compares 2 strings for equality */
/* */
/* DEPENDENCIES */
/* */
/* NUCLEUS.H */
/* EXTERNS.H */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* Barbara G. Harwell 10/06/92 Initial version. */
/* */
/******************************************************************************/
#ifdef PLUS
#include "nucleus.h"
#else
#include "nu_defs.h" /* added during ATI mods - 10/20/92, bgh */
#include "nu_extr.h"
#endif
#include "externs.h"
#ifdef MSC
#include<time.h>
#endif
#if !(IPCHECK_ASM)
/************************************************************************/
/* */
/* FUNCTION "ipcheck" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function checksums an IP header. */
/* */
/* AUTHOR */
/* */
/* B. Harwell, Accelerated Technology */
/* */
/* HISTORY */
/* */
/* created - 12/22/92 */
/* */
/* CALLED FROM */
/* */
/* IP.C */
/* TCP.C */
/* UDP.C */
/* */
/* ROUTINES CALLED */
/* */
/* N/A */
/* */
/* INPUTS */
/* */
/* header Pointer to structure to be checksummed */
/* length Length of header structure */
/* */
/* OUTPUTS */
/* */
/* sum Checksum value of structure */
/* */
/************************************************************************/
uint16 ipcheck (uint16 *header, uint16 length)
{
uint32 sum;
for (sum = 0; length > 0; length--)
{
sum += *header++;
/* check for a carry over 16 bits */
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
return ((int16)~sum);
}
#endif /* IPCHECK_ASM */
#if !(TCPCHECK_ASM)
/************************************************************************/
/* */
/* FUNCTION "tcpcheck" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function checksums a TCP header. */
/* */
/* AUTHOR */
/* */
/* B. Harwell, Accelerated Technology */
/* */
/* HISTORY */
/* */
/* created - 12/22/92 */
/* */
/* CALLED FROM */
/* */
/* IP.C */
/* TCP.C */
/* UDP.C */
/* */
/* ROUTINES CALLED */
/* */
/* N/A */
/* */
/* INPUTS */
/* */
/* pseudoheader Pointer to header to be checksummed */
/* tcpheader Pointer to structure to be checksummed */
/* length Length of tcpheader structure */
/* */
/* OUTPUTS */
/* */
/* sum Checksum value of structure */
/* */
/************************************************************************/
uint16 tcpcheck (uint16 *pseudoheader, uint16 *tcpheader, uint16 length)
{
register uint32 sum =0;
register uint16 *pshdr = pseudoheader;
register uint16 *tcphdr = tcpheader;
/* This used to be a loop. The loop was removed to save a few
cycles. The header length is always 6 16-bit words. */
sum += *pshdr++;
sum += *pshdr++;
sum += *pshdr++;
sum += *pshdr++;
sum += *pshdr++;
sum += *pshdr++;
/* Code to pad for the blank byte on odd number TCP packet length. */
if (length % 2)
{
((char *)tcphdr)[length] = 0;
length += 1;
}
/* Make into 16-bit entities not bytes. */
length >>= 1;
for (; length > 0; length--)
{
sum += *tcphdr++;
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
return ((int16)~sum);
}
#endif /* !(TCPCHECK_ASM) */
#if !(LONGSWAP_ASM)
/************************************************************************/
/* */
/* FUNCTION "longswap" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function swaps 4 bytes of a long number. */
/* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -