本文介绍了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 fieldsinside 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).

这篇关于C程序来获得IP报头字段从Linux的IP协议栈中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 15:11