IP字符串转换成可比较大小的数字,具体代码如下所示: 文章来源:www. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include "stdio.h"
#include "arpa/inet.h"
#include <string>
using namespace std;
int main( int argc, char *argv[])
{
string ip= "192.168.1.123" ;
unsigned int x=ntohl(inet_addr(ip.c_str()));
unsigned int y=(unsigned int )192*256*256*256+168*256*256+256+123;
printf ( "x=[%u] ip un[%u]\r\n" ,x,y);
return 1;
}
|
|