linux 下网络编程结构体定义对应的头文件

来源:互联网 发布:excel多列重复数据筛选 编辑:程序博客网 时间:2024/06/06 01:07

netinet/if_ether.h   ether_arp的数据结构

netinet/ether.h    以太祯的网络字节和ascii字节的转换,包括ether_ntoa(),ether_aton这样的函数定义

netinet/ip.h   这个头文件和linux/ip.h似乎很相似,也有iphdr的数据结构,同时还包括了timestamp结构,我的理解是,linux文件夹下的 ip.h是linux黑客编写的ip头文件,而这个则是gnu一开始就定义的头文件,同时还包括了bsd中的ipheader结构定义。同理的还有该目录 下的tcp.h等文件

linux/ip.h   iphdr的数据结构,以及一些ip层的数据定义,同理的还有tcp.h,udp.h等等

linux/if.h    主要的socket头文件,似乎修改自unix的if.h,定义了网卡的接口信息的宏,例如IFF_UP.另外有数个重要的interface的数据结构定义,包括ifreq,ifconf,ifmap

linux/if_packet.h    原始数据包的数据结构定义,包括sockaddr_pkt,sockaddr_ll,想接收原始数据包的不能错过这个文件。同理的还有if_ppp.h,if_tun.h等等

netinet/in.h    这个文件作的事情就多了。端口宏定义,著名ip(比如loopback),结构sockaddr_in,网络字节转换(ntoh,hton。。。。)。。。反正太多了,没事的话就把这个文件加到头文件包含里吧

netdb.h    文件如其名,包括结构hostent(主机环境),获得主机的信息的几个函数(gethostbyname)。似乎这个就是定义主机的各项环境,例如hostname等等

net/bpf.h  berkeley的数据包过滤头文件,想用bpf进行包过滤的要重视一下这个文件

net/ethernet.h 包括几个以太网的数据结构,ether_addr(mac帧结构),ether_header(以太帧的头部)

-------------------------------

<sys/types.h>                    //primitive system data types(包含很多类型重定义,如pid_t、int8_t等)  
<sys/socket.h>         //与套接字相关的函数声明和结构体定义,如socket()、bind()、connect()及struct sockaddr的定义等
<sys/ioctl.h>             //I/O控制操作相关的函数声明,如ioctl()
<stdlib.h>                   //某些结构体定义和宏定义,如EXIT_FAILURE、EXIT_SUCCESS等
<netdb.h>                  //某些结构体定义、宏定义和函数声明,如struct hostent、struct servent、gethostbyname()、gethostbyaddr()、herror()等
<arpa/inet.h>           //某些函数声明,如inet_ntop()、inet_ntoa()等
<netinet/in.h>          //某些结构体声明、宏定义,如struct sockaddr_in、PROTO_ICMP、INADDR_ANY等

------------------------------

linux下socket编写常用头文件
 
#include <sys/socket.h>   //connect,send,recv,setsockopt等
#include <sys/types.h>     

#include <netinet/in.h>     // sockaddr_in, "man 7 ip" ,htons
#include <poll.h>             //poll,pollfd
#include <arpa/inet.h>   //inet_addr,inet_aton
#include <unistd.h>        //read,write
#include <netdb.h>         //gethostbyname

#include <error.h>         //perror
#include <stdio.h>
#include <errno.h>         //errno

#include <string.h>          // memset
#include <string>
#include <iostream>
0 0
原创粉丝点击