加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

c语言实现判断ip地址的类型

(2013-10-08 21:45:18)
标签:

c语言实现判断ip地址

it

分类: socket编程
http://s6/mw690/6abf2c04tx6DgKIKuQB45&690

如果我们必须设置我们的网络,我们就必须确定我们的网络掩码是多少。下表列出A,B,C类地址的网络掩码:
Class Lowest Highest Netmask
A 0.0.0.0 127.255.255.255 255.0.0.0
B 128.0.0.0 191.255.255.255 255.255.0.0
C 192.0.0.0 223.255.255.255 255.255.255.0

有时,在一个网络软件中,我们的软件必须可以分类一个网络地址。有时,这是通过确定一个默认的网络掩码来简单完成的。

#include
#include
#include
#include
#include
#include
#include

int main(int argc ,char *argv[])
{
 unsigned int my_ip;
 unsigned char first;
 my_ip = (inet_addr(argv[1]));
 first = (unsigned char )my_ip;
 if((first&0x80) == 0)
 {
  printf("a\n");
 }
 if((first&0xc0) == 0x80)
 {
  printf("b\n");
 }
 if((first&0xe0) == 0xc0)
 {
  printf("c\n");
 }
 if((first&0xf0) == 0xe0)
 {
  printf("d\n");
 }
 if((first&0xf0) == 0xf0)
 {
  printf("e\n");
 }
 printf("%x\n",my_ip);
 return 0;
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有