网络编程基础4-获得网络信息getnetent
来源:互联网 发布:淘宝店招分层素材 编辑:程序博客网 时间:2024/05/22 12:38
/*1.获得网络名,如下文件/etc/networks2.struct netent结构体成员使用*/#include <netdb.h>#include <stdlib.h>#include <stdio.h>int main(){ struct netent *net; int8_t decdotip[16] = {0}; char **p; uint32_t netaddrtype; while((net = getnetent() )!= NULL) { printf("network name : %s\n",net->n_name); if( net->n_aliases[0] == NULL) printf("no alternate network name.\n"); else { for(p=net->n_aliases; *p != NULL; p++ ) { printf("alternate network name: %s\n",*p); } } if(net->n_addrtype == AF_INET) printf("address type AF_INET:%d\n",net->n_addrtype); else printf("address type UNIX_INET:%d\n",net->n_addrtype); /* 得到的是32bit本地主机字节数据 */ netaddrtype = htonl(net->n_net); printf("net number:0x%08x, ip:%s\n",netaddrtype,(char *)inet_ntop(net->n_addrtype, (struct in_addr *)&netaddrtype, decdotip,sizeof(decdotip))); } endnetent(); return 0;}
#if 0/* Description of data base entry for a single network. NOTE: here a poor assumption is made. The network number is expected to fit into an unsigned long int variable. /usr/include/i386-linux-gnu/bits/netdb.h*/struct netent{ char *n_name; /* Official name of network. */ char **n_aliases; /* Alias list. */ int n_addrtype; /* Net address type. */ uint32_t n_net; /* Network number. */};/* Open network data base files and mark them as staying open even after a later search if STAY_OPEN is non-zero. This function is a possible cancellation point and therefore not marked with __THROW. */extern void setnetent (int __stay_open);/* Close network data base files and clear `stay open' flag. This function is a possible cancellation point and therefore not marked with __THROW. */extern void endnetent (void);/* Get next entry from network data base file. Open data base if necessary. This function is a possible cancellation point and therefore not marked with __THROW. */extern struct netent *getnetent (void);/* Return entry from network data base which address match NET and type TYPE. This function is a possible cancellation point and therefore not marked with __THROW. */extern struct netent *getnetbyaddr (uint32_t __net, int __type);/* Return entry from network data base for network with NAME. This function is a possible cancellation point and therefore not marked with __THROW. */extern struct netent *getnetbyname (__const char *__name);#endif
0 0
- 网络编程基础4-获得网络信息getnetent
- 网络编程基础3-获得主机信息hostent
- 网络编程基础5-获得服务端信息getservent
- 网络编程基础6-获得协议信息getprotoent
- 获取网络号、网络名——getnetent(),getnetbyaddr(),getnetbyname()
- 网络编程:网络基础
- 获得当前连接网络信息
- Java网络编程从入门到精通(11):使用NetworkInterface类获得网络接口信息
- Java网络编程从入门到精通(11):使用NetworkInterface类获得网络接口信息
- Java网络编程从入门到精通(11):使用NetworkInterface类获得网络接口信息
- Java网络编程从入门到精通(11):使用NetworkInterface类获得网络接口信息
- 网络信息安全基础
- 获得网络接口信息和网卡信息
- JAVA基础-网络编程
- 网络编程基础:对HTTP协议的头信息详解
- 使用NetworkInterface类获得网络接口信息
- 使用NetworkInterface类获得网络接口信息
- 网络编程基础
- sbt教程
- iOS网络连接判断
- 临时
- mysql 5.6 my.cnf
- QTP之Action间传参
- 网络编程基础4-获得网络信息getnetent
- UITableView删除添加,移动,分区,索引,自定义UITableViewCell
- android 的四种枚举
- HTML学习笔记之多媒体网页效果
- 使用线程池的好处
- PHP程序员的工作职责与薪酬待遇 -兄弟连IT教育
- java基础回顾----多态
- ABOUT FEATURE INTERFACE DEFINITIONS
- 初学者怎样区分 传值,传引用,传指针