我需要将使用recvfrom()接收到的rtp数据包存储到.pcap文件中。
我试图打开一个扩展名为.pcap的文件,并直接编写我收到的任何文件(即void *buf),但是当我试图使用wireshark打开该文件时,它给出的错误声明是“不可理解的”--我应该怎么做才能使它成为可以理解的?
我使用的代码:
recvfrom(sockfd, buf, len, flags, (struct sockaddr *)&src_addr->ss, &src_addr->len);
fp=fopen("test.pcap","a+");
fprintf(fp, "%s",buf);在UDP连接中,如何将rtp数据包接收并存储到可理解的.pcap文件中?是否需要在接收到的rtp pcakets中添加额外的内容?
发布于 2014-10-27 07:09:22
您必须添加以下标题,才能将数据包写入pcap。
全局报头
This header starts the libpcap file and will be followed by the first packet header:
typedef struct pcap_hdr_s {
guint32 magic_number; /* magic number */
guint16 version_major; /* major version number */
guint16 version_minor; /* minor version number */
gint32 thiszone; /* GMT to local correction */
guint32 sigfigs; /* accuracy of timestamps */
guint32 snaplen; /* max length of captured packets, in octets */
guint32 network; /* data link type */
} pcap_hdr_t;记录(数据包)报头:
Each captured packet starts with (any byte alignment possible):
typedef struct pcaprec_hdr_s {
guint32 ts_sec; /* timestamp seconds */
guint32 ts_usec; /* timestamp microseconds */
guint32 incl_len; /* number of octets of packet saved in file */
guint32 orig_len; /* actual length of packet */
} pcaprec_hdr_t;有关标题的解释,请查看链接。
检查此链接以获取代码的示例片段。
https://stackoverflow.com/questions/26581858
复制相似问题