admin管理员组文章数量:1530518
2024年3月25日发(作者:)
69 p++;
70 }
71 printf("n");
72 for (l=0; l < 4; l++)
73 printf("%d ",net[l]);
74 printf("/ ");
75 for (l=0; l < 4; l++)
76 printf("%d ",mask[l]);
77 printf("ncal ip & mask:n");
78 for (l=0; l < 4; l++)
79 {
80 printf(" %d ",ip[l]&mask[l]);
81 if ((ip[l]&mask[l]) != net[l])
82 break;
83 int temp = mask[l];
84 while(temp)
85 {
86
87 if (temp & 0x00000001){
88 sum++;
89 }
90 temp = temp >> 1;
91 }
92 }
93 if (l >= 4)
94 {
95 printf("n前缀长度:%d",sum);
96 if (len <= sum)
97 {
98 *n = i;
99 len = sum;
100 }
101 }
102 sum = 0;
103 i++;
104 l = 0;
105 printf("n");
106 }
107 printf("n");
108 }
109 int main()
110 {
111 char ip_addr[20] = "192.168.1.100";
112
113 //ip_addr[13] = '0';
114
115 const char *net_addr_array[100] =
116
117 {
118 "192.168.1.128/255.255.255.192",
119 "192.168.1.0/255.255.255.0",
120 "192.168.1.64/255.255.255.192",
121 "0.0.0.0/0.0.0.0",
122 ""
123 };
124 int *n;
125 n = (int*)malloc(sizeof(int));
126 max_prefix_match(ip_addr, net_addr_array, n);
127 printf("n = %dn",*n);
128
129 }
版权声明:本文标题:IP地址匹配 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1711354175a305482.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论