📄 sockutil.cpp
字号:
#include "stdafx.h"
#include "sockutil.h"
#include <stdlib.h>
#include <string.h>
/*++
Routine Description:
Convert the ip to the format we have to compare
Arguments:
ip - string that represent a ip address
Return Value:
ip
--*/
unsigned long inet_addr(const char *sIp)
{
int octets[4];
int i;
const char * auxCad = sIp;
unsigned long lIp = 0;
//we extract each octet of the ip address
//atoi will get characters until it found a non numeric character(in our case '.')
for(i = 0; i < 4; i++)
{
octets[i] = atoi(auxCad);
if(octets[i] < 0 || octets[i] > 255)
return 0;
lIp |= (octets[i] << (i*8));
//update auxCad to point to the next octet
auxCad = strchr(auxCad, '.');
if(auxCad == NULL && i!=3)
return -1;
auxCad++;
}
return lIp;
}
/*++
Routine Description:
Convert the port to the format we have to compare
Arguments:
port - port to convert
Return Value:
port converted
--*/
unsigned short htons(unsigned short port)
{
unsigned short portRet;
portRet = ((port << 8) | (port >> 8));
return portRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -