/*判断两段IP地址区间不重叠*/
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main()
{
char *strwanAclIpStart="192.168.3.1";
char *strwanAclIpEnd="192.168.3.2";
char *wanAclIpStart="172.18.18.1";
char *wanAclIpEnd="172.18.18.25";
struct in_addr ips,ipe,tmps,tmpe;
unsigned long ip1, ip2, ip3, ip4;
unsigned long v1, v2, v3,v4;
inet_aton(strwanAclIpStart, &ips);
inet_aton(strwanAclIpEnd, &ipe);
inet_aton(wanAclIpStart, &tmps);
inet_aton(wanAclIpEnd, &tmpe);
ip1 = ips.s_addr;
ip2 = ipe.s_addr;
ip3 = tmps.s_addr;
ip4 = tmpe.s_addr;
/* 我的第一个 C 程序 */
printf("%x %x %x %x\n", ip1,ip2,ip3,ip4);
printf("%d %d %d %d\n", ip1,ip2,ip3,ip4);
v1 = ntohl(ip1);
v2 = ntohl(ip2);
v3 = ntohl(ip3);
v4 = ntohl(ip4);
printf("%x %x %x %x\n", v1,v2,v3,v4);
printf("%ul %ul %ul %ul\n", v1,v2,v3,v4);
if((ip3 < ip1) && (ip4 < ip1) || (ip3 > ip2) && (ip4 > ip2))
{
}
else
{
printf("11111111111111111\n");
}
if( (v3 < v1) && (v4 < v1) || (v3 > v2) && (v4 > v2) ){
}
else
{
printf("11111111111111111\n");
}
return 0;
}
04-03
791
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)