📄 tools.c
字号:
* this offset, 32bits will be read and returned in the target
* hardware byte order.
*
* INPUTS
*
* unsigned char *ptr Pointer to the start of the memory area.
* unsigned int offset Offset into memory area to get the 32bits
* from.
*
* OUTPUTS
*
* unsigned long The 32bits that were read.
*
************************************************************************/
unsigned long TLS_Get32(unsigned char *ptr, unsigned int offset)
{
unsigned char *p = ptr + offset;
return ((unsigned long)p[0] << 24) +
((unsigned long)p[1] << 16) +
((unsigned long)p[2] << 8) +
(unsigned long)p[3];
} /* TLS_Get32 */
/*************************************************************************
*
* FUNCTION
*
* TLS_Put32
*
* DESCRIPTION
*
* This function takes a memory area and an offset into the area. At
* this offset, 32bits will be written in network byte order.
*
* INPUTS
*
* unsigned char *ptr Pointer to the start of the memory area.
* unsigned int offset Offset into memory area to get the 32bits
* from.
* unsigned long value 32bits to be written to memory
*
* OUTPUTS
*
* None
*
*************************************************************************/
void TLS_Put32(unsigned char *ptr, unsigned int offset, unsigned long value)
{
unsigned char *p = ptr + offset;
*p++ = (unsigned char)(value >> 24);
*p++ = (unsigned char)(value >> 16);
*p++ = (unsigned char)(value >> 8);
*p = (unsigned char)value;
} /* TLS_Put32 */
/*************************************************************************
*
* FUNCTION
*
* TLS_Get16
*
* DESCRIPTION
*
* This function takes a memory area and an offset into the area. At
* this offset, 16bits will be read and returned in the target
* hardware byte order.
*
* INPUTS
*
* unsigned char *ptr Pointer to the start of the memory area.
* unsigned int offset Offset into memory area to get the 32bits
* from.
*
* OUTPUTS
*
* unsigned short The 16bits that were read.
*
************************************************************************/
unsigned short TLS_Get16(unsigned char *ptr, unsigned int offset)
{
unsigned char *p = ptr + offset;
return (unsigned short)((p[0] << 8) + p[1]);
} /* TLS_Get16 */
/*************************************************************************
*
* FUNCTION
*
* TLS_Put16
*
* DESCRIPTION
*
* This function takes a memory area and an offset into the area. At
* this offset, 16bits will be written in network byte order.
*
* INPUTS
*
* unsigned char *ptr Pointer to the start of the memory area.
* unsigned int offset Offset into memory area to get the 32bits
* from.
* unsigned short value 16bits to be written to memory
*
* OUTPUTS
*
* None
*
************************************************************************/
void TLS_Put16(unsigned char *ptr, unsigned int offset, unsigned short value)
{
unsigned char *p = ptr + offset;
*p++ = (unsigned char)(value >> 8);
*p = (unsigned char)value;
} /* TLS_Put16 */
/*************************************************************************
*
* FUNCTION
*
* TLS_IP_Address
*
* DESCRIPTION
*
* This function converts an IP address that is stored in a 4 byte
* array into a 32bit form of the IP address, note that correct
* byte ordering for the target hardware is maintained.
*
* INPUTS
*
* unsigned char *p Pointer to the array storing an IP
* address
*
* OUTPUTS
*
* unsigned long 32bits form of the IP address
*
************************************************************************/
unsigned long TLS_IP_Address(unsigned char *p)
{
return ((unsigned long)p[0] << 24) +
((unsigned long)p[1] << 16) +
((unsigned long)p[2] << 8) +
(unsigned long)p[3];
} /* TLS_IP_Address */
/*************************************************************************
*
* FUNCTION
*
* TLS_Put_String
*
* DESCRIPTION
*
* This function writes a string out to memory.
*
* INPUTS
*
* unsigned char *dest Destination address for the string
* unsigned int offset Offset from the destination to start
* writing
* unsigned char *src Source address of the string to write
* unsigned int size Length of the string to write
*
* OUTPUTS
*
* None
*
************************************************************************/
void *TLS_Put_String(unsigned char *dest, unsigned int offset,
unsigned char *src, unsigned int size)
{
return (memcpy((dest + offset), src, size));
} /* TLS_Put_String */
/*************************************************************************
*
* FUNCTION
*
* TLS_Get_String
*
* DESCRIPTION
*
* This function reads a string of specified length from memory.
*
* INPUTS
*
* unsigned char *src Source address of the string to read
* unsigned int offset Offset from the source address to
* start reading
* unsigned char *dest Destination address for the string
* read
* unsigned int size Length of the string to read
*
* OUTPUTS
*
* None
*
*************************************************************************/
void *TLS_Get_String(unsigned char *src, unsigned int offset,
unsigned char *dest, unsigned int size)
{
return (memcpy(dest, (src + offset), size));
} /* TLS_Get_String */
/*************************************************************************
*
* FUNCTION
*
* TLS_Eq_String
*
* DESCRIPTION
*
* Test two string for equality.
*
* INPUTS
*
* unsigned char *packet Address of one string to compare
* unsigned int offset Offset from the packet address to
* compare at
* unsigned char *local String to compare to
* unsigned int size Length of the strings to compare
*
* OUTPUTS
*
* None
*
*************************************************************************/
int TLS_Eq_String(unsigned char *packet, unsigned int offset,
unsigned char *local, unsigned int size)
{
return (TLS_Comparen((packet + offset), local, size));
} /* TLS_Eq_String */
#if !(IPCHECK_ASM)
/*************************************************************************
*
* FUNCTION
*
* TLS_IP_Check
*
* DESCRIPTION
*
* This function checksums an IP header.
*
* INPUTS
*
* header Pointer to structure to be checksummed
* length Length of header structure
*
* OUTPUTS
*
* UINT16 Checksum value of structure
*
*************************************************************************/
UINT16 TLS_IP_Check (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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -