ネットワークプログラミングヘッダファイルのまとめ
3525 ワード
( /usr/include )
, 。 。
ip
ip ,
linux/ip.h struct iphdr
netinet/ip.h , struct iphdr struct ip
, , netinet/ip.h struct iphdr;
tcp
linux/tcp.h struct tcphdr
netinet/tcp.h struct tcphdr
, netinet , linux 。
udp
linux/udp.h struct udphdr
netinet/udp.h struct udphdr
icmp
linux/icmp.h struct icmphdr
netinet/ip_icmp.h struct icmphdr
arp
linux/if_arp.h struct arphdr
net/if_arp.h struct arphdr // netinet ,net。
linux/if_ether.h struct ethhdr
netinet if_ether.h struct ethhdr, , ,
linux/if_ether.h, struct ethhdr.
。
,netinet/if_ether.h struct ether_arp , arp ( arp ) 。
, 。
, 。
netinet/in.h ip struct sockaddr_in (struct in_addr sockaddr_in ) htons , 。
, ( ip )
arpa/inet.h inet_ntoa inet_aton inet_pton 。( )。
sys/socket.h socket API socket,bind listen , send ,sendmsg,setsockopt, 。 netinet/in.h 。
......................................................................
#include
//udp
struct udphdr
{
u_int16_t source;
u_int16_t dest;
u_int16_t len;
u_int16_t check;
};
........................................................................
#include
struct icmphdr
{
u_int8_t type;//0--reques,8---reply,11----timeout;
u_int8_t code;
u_int16_t checksum;
........
};
..........................................................................
#include
struct iphdr
{
#if defined(__LITTLE_ENDIAN_BITFIELD)
__u8 ihl:4,
version:4;
#elif defined (__BIG_ENDIAN_BITFIELD)
__u8 version:4,
ihl:4;
#else
#error "Please fix "
#endif
__u8 tos;
__be16 tot_len;
__be16 id;
__be16 frag_off;
__u8 ttl;
__u8 protocol; // 1--icmp 6---tcp 17---udp
__sum16 check;
__be32 saddr;
__be32 daddr;
/*The options start here. */
};
.........................................................................
#include
struct tcphdr {
__be16 source;
__be16 dest;
__be32 seq;
__be32 ack_seq;
#if defined(__LITTLE_ENDIAN_BITFIELD)
__u16 res1:4,
doff:4,
fin:1,
syn:1,
rst:1,
psh:1,
ack:1,
urg:1,
ece:1,
cwr:1;
#elif defined(__BIG_ENDIAN_BITFIELD)
__u16 doff:4,
res1:4,
cwr:1,
ece:1,
urg:1,
ack:1,
psh:1,
rst:1,
syn:1,
fin:1;
#else
#error "Adjust your defines"
#endif
__be16 window;
__sum16 check;
__be16 urg_ptr;
}
.........................................................................
#include
struct ethhdr
{
unsigned char h_dest[6];
unsigned char h_source[6];
__be16 h_proto;//0x0806---arp,0x0800--ip,0x0835---rarp.
}
.........................................................................
#include
struct arphdr
{
unsigned short hard_type;// , 0x0001( )
unsigned short protocol;// , 0x0800(IP)
unsigned char hard_length;
.....
unsigned short operation_type;// ,1,ARP ,2,ARP
// http://baike.baidu.com/view/121586.htm?fr=aladdin
}