C程序来获得IP报头字段从Linux的IP协议栈中的值
问题描述:
我开发一个程序中,我需要知道IP报头字段我program.Since内部IP报头为20个字节的值:
I am developing a program in which i need to know the values of IP header fields inside my program.Since the IP header is of 20 bytes:
struct ipheader {
unsigned char ip_hl:4, ip_v:4; /* this means that each member is 4 bits */
unsigned char ip_tos;
unsigned short int ip_len;
unsigned short int ip_id;
unsigned short int ip_off;
unsigned char ip_ttl;
unsigned char ip_p;
unsigned short int ip_sum;
unsigned int ip_src;
unsigned int ip_dst;
};
有什么办法,我可以知道这些字段的值
我的C程序中?
Is there any way that i can know the values of these fields inside my C program?
答
一些这些值可以设置/通过检索的setsockopt()/的getsockopt()
要求在 SOL_IP / IPPROTO / IP
的水平。请咨询您的OS的文档。(例如:在Linux上人7 IP
)
Some of those values can be set/retrieved via setsockopt()/getsockopt()
calls at the SOL_IP/IPPROTO/IP
level. Consult your OS' documentation (e.g: on Linux man 7 ip
).