当前位置: 首页 > news >正文

网站建设学费网址大全浏览器app

网站建设学费,网址大全浏览器app,甘肃自助建站系统哪家好,ac68u做网站在进行网络程序的时候避免不了对给定IP是否跨子网段进行判断。相关原理倒是简单&#xff0c; 贴出相关代码: 1 #include <stdio.h>2 #include <math.h>3 #include <string.h>4 #include <stdlib.h>5 #include <unistd.h>6 7 #define ALL_BIT 32…

在进行网络程序的时候避免不了对给定IP是否跨子网段进行判断。相关原理倒是简单, 贴出相关代码:

 1 #include <stdio.h>
 2 #include <math.h>
 3 #include <string.h>
 4 #include <stdlib.h>
 5 #include <unistd.h>
 6  
 7 #define ALL_BIT 32 /* ip address have 32 bits */
 8  
 9 /*
10 ** description: juge the ip_a and ip_b is in the same subnet or not
11 ** this functio is used IPv4 only, and did not check the input parameter's
12 ** correctness, so make sure the value of parameter before call it
13 ** para: sub_mask is a decimal subnet mask , not dotted decimal
14 ** ip_a/ip_b: the ip address string, in dotted decimal
15 ** return: 0 for the same, -1 for the not
16 */
17 int same_subnet (int sub_mask, char *ip_a, char *ip_b)
18 {
19   int mask = 0xFFFFFFFF;
20   mask = mask << (ALL_BIT - sub_mask);
21  
22   double cnt_a = 0.0;
23   double cnt_b = 0.0;
24   double tmp = 0.0;
25  
26   char *token = NULL;
27  
28  int i = 3;
29  
30   for (token = strtok (ip_a, "."); token != NULL; token = strtok (NULL, ".")) {
31     tmp = atoi (token);
32     tmp = tmp * pow (256, i--);  /* what dose this mean? do you understand */
33     cnt_a += tmp;
34   }
35  
36   i = 3; /* reset i */
37   for (token = strtok (ip_b, "."); token != NULL; token = strtok (NULL, ".")) {
38     tmp = atoi (token);
39     tmp = tmp * pow (256, i--);
40     cnt_b += tmp;
41   }
42  
43   unsigned long mask_a = (unsigned long)cnt_a;
44   unsigned long mask_b = (unsigned long)cnt_b;
45  
46   //printf ("mask_a %u\tmask_b %u\n", mask_a, mask_b);
47  
48   mask_a &= mask;   /* get the ip's netmask for compare */
49   mask_b &= mask;
50   //printf ("mask_a %u\tmask_b %u\n", mask_a, mask_b);
51  
52   if (mask_a == mask_b)
53   return 0;
54   else
55     return -1;
56 }
57  
58 /*
59 ** test code
60 */
61 int main (int argc, char **argv)
62 {
63   int i = same_subnet (atoi (argv[1]), argv[2], argv[3]);
64   printf ("%s subnet\n", i == 0? "same":"not same");
65   return 0;
66 }
67  
68  
69  
70 代码在gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)编译通过。

 

转载于:https://www.cnblogs.com/arnold0kang/p/3744130.html

http://www.lbrq.cn/news/2450485.html

相关文章:

  • 全世界做会展介绍的网站排名移投界seo
  • 做外链选择那些网站网络推广方案的内容
  • 做电商网站费用生成关键词的软件
  • ps做的网站怎样在dw里打开市场调研怎么写
  • dede网站本地访问速度慢计算机培训短期速成班
  • python做博客网站百度站长提交
  • 应该怎样做网站地图刷排名有百度手机刷排名
  • 江苏省住房和城乡建设委员会网站今日头条关键词工具
  • 企业网站优化服务主要围绕什么上海seo推广外包
  • 上海画册设计网站seo关键词排名
  • 苏州企业网站制作开发广告优化师
  • 常州软件开发公司汕头seo网站建设
  • 一款蛋糕食品类企业手机网站源码网络营销方案设计
  • 品牌画册设计佛山抖音seo
  • 局域网内的网站建设中国新冠疫苗接种率
  • 深圳建设工程协会网站常州网站建设书生商友
  • 北京市建设工程造价管理协会网站百度 营销怎么收费
  • 个人网页制作多少钱百合seo培训
  • 公司网站建设有什么好处公司推广
  • 虚拟主机哪里好seo页面如何优化
  • 网站后台的搭建成都网站推广
  • 网站开发规划书广州网络公司
  • 专门做优选的网站论坛推广的特点
  • 如何查看网站服务器类型网络推广渠道公司
  • 新手做的网站bt搜索引擎下载
  • 支付网站开发费可以做无形资产重庆百度快照优化排名
  • 批量扫dedecms做的网站抖音关键词搜索指数
  • 公司注册地址和经营地址不一致优化关键词排名软件
  • 网站怎么算抄袭实体店营销方案
  • javascript作业做的网站营销必备十大软件
  • 【基础】go基础学习笔记
  • C++:list(1)list的使用
  • 压测软件JMeter安装配置以及创建桌面快捷方式(详细图解)
  • 微算法科技(NASDAQ: MLGO)研究量子机器学习算法 (Quantum Machine Learning Algorithms),加速机器学习任务
  • React中的antd的表格使用方法
  • k8s:离线部署tomcatV11.0.9,报Cannot find /opt/bitnami/tomcat/bin/setclasspath.sh