天嵌二次封装库使用手册  V1.0
tq_network.h
浏览该文件的文档.
1 
2 #ifndef _TQ_NETWORK_H__
3 #define _TQ_NETWORK_H__
4 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <errno.h>
23 #include <unistd.h>
24 #include <netdb.h>
25 #include <net/if.h>
26 #include <arpa/inet.h>
27 #include <sys/ioctl.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <signal.h>
31 #include <netinet/in_systm.h>
32 #include <netinet/ip.h>
33 #include <netinet/ip_icmp.h>
34 #include <unistd.h>
35 #include <sys/time.h>
36 #include <termios.h>
37 #include <sys/un.h>
38 #include <stddef.h>
39 #include <time.h>
40 #include <fcntl.h>
41 #include <poll.h>
42 #include <stddef.h>
43 #include <limits.h>
44 #include <netinet/in.h>
45 #include <error.h>
46 #include <net/route.h>
47 #include <net/if_arp.h>
48 #define MAC_SIZE 18
49 #define IP_SIZE 16
50 #define BUFSIZE 1500
51 #define DATA_LEN 56
52 #define ETHER_ADDR_LEN 6
53 #define UP 1
54 #define DOWN 0
55 
56 static char dns_file_path[] = "/etc/resolv.conf\0";
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
73  int get_ip_by_domain(const char *trgtadd, char *ip, int size);
74 
86  int get_ip(char *dev, char *ip, int size);
93  int get_ip_info(char const* device, char *ip);
94 
106  int get_netmask(char *dev, char *mask, int size);
107 
119  int get_gateway(char *dev, char *gway, int size);
120 
132  int get_mac(char *dev, char *mac, int size);
133 
144  int get_dns(char *dns1, int size1, char *dns2, int size2);
145 
152  int check_ping(const char *target, unsigned int timeout_ms);
153 
161  int check_ping2(const char *iface, const char *target, unsigned int timeout_ms);
162 
168  int detect_eth_cable(char *ifname);
169 
177  int SetIfAddr(char *ifname, char *Ipaddr, char *mask);
178 
185  int set_mac_addr(char *ifname, char *mac);
186 
193  int set_gateway(char *ifname, char *gateway);
194 
203  int set_dns(char *dns1, char *dns2);
204 
211  int if_updown(char *ifname, int flag);
212 
219  int ether_atoe(const char *a, unsigned char *e);
220 
227  char *ether_etoa(const unsigned char *e, char *a);
232  void udhcpc(char *net_interface);
233 #ifdef __cplusplus
234 }
235 #endif
236 #endif
int get_dns(char *dns1, int size1, char *dns2, int size2)
获取本机指定的DNS服务器地址
int check_ping2(const char *iface, const char *target, unsigned int timeout_ms)
网络检测函数,类似于ping命令(指定端口)
int set_mac_addr(char *ifname, char *mac)
设置网卡MAC地址
int get_gateway(char *dev, char *gway, int size)
获取指定网卡设备的网关
int get_ip_by_domain(const char *trgtadd, char *ip, int size)
根据域名获取默认网卡设备的ip地址
int get_mac(char *dev, char *mac, int size)
获取指定网卡设备的mac地址
void udhcpc(char *net_interface)
用udhcpc获取ip地址
int detect_eth_cable(char *ifname)
网卡状态检测
int set_dns(char *dns1, char *dns2)
设置本机DNS服务器地址,DNS地址如114.114.114.114
int check_ping(const char *target, unsigned int timeout_ms)
网络检测函数,类似于ping命令
int get_ip(char *dev, char *ip, int size)
获取指定网卡设备的ip地址
int ether_atoe(const char *a, unsigned char *e)
将以太网地址串表示转换为二进制数据
int if_updown(char *ifname, int flag)
打开关闭网卡
int get_ip_info(char const *device, char *ip)
获取指定网卡设备的ip地址
int SetIfAddr(char *ifname, char *Ipaddr, char *mask)
设置网卡IP地址 子网掩码 网关等信息
int set_gateway(char *ifname, char *gateway)
设置网卡IP地址 子网掩码 网关等信息
int get_netmask(char *dev, char *mask, int size)
获取指定网卡设备的子网掩码
char * ether_etoa(const unsigned char *e, char *a)
将以太网地址二进制数据转换为字符串表示形式