例1:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
void main()
{
char *ip = "127.0.0";
long addr;
if (inet_pton(AF_INET, ip, (void *)&addr) <= 0) {
printf("Invalid ip address.\n");
return -1;
}
return 0;
}