1. 程式人生 > >IP字串轉換成4位元組無符號字元陣列[轉]

IP字串轉換成4位元組無符號字元陣列[轉]

#include <iostream>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
int main(int argc,char **argv)
{
 char *pIP = "192.168.2.22";
 unsigned long lIP = inet_addr(pIP);
 unsigned char * aIP =(unsigned char*) &lIP;
 printf("%d.%d.%d.%d\n", aIP[0], aIP[1], aIP[2], aIP[3]);