#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
bool IsIpv4(char*str)
{
char* ptr;
int count = 0;
const char *p = str;
//1、判断是不是三个 ‘.’
//2、判断是不是先导0
//3、判断是不是四部分数
//4、第一个数不能为0
while(*p !='\0')
{
if(*p == '.')
count++;
p++;
}
if(count != 3)
return false;
count = 0;
ptr = strtok(str,".");
while(ptr != NULL)
{
count++;
if(ptr[0] == '0' && isdigit(ptr[1]))
return false;
int a = atoi(ptr);
if(count == 1 && a == 0)
return false;
if(a<0 || a>255)
return false;
ptr = strtok(NULL,".");
}
if(count == 4)
return true;
else
return false;
}
int main()
{
char ipv4String[64]={0};
char
ipv4 子网c语言计算
最新推荐文章于 2024-06-05 12:37:55 发布