我需要将使用recvfrom()接收的rtp数据包存储到.pcap文件中。
我尝试打开一个扩展名为.pcap的文件并完成直接fwrite收到的任何内容(即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添加任何内容?
答案 0 :(得分:0)
您必须添加以下标头才能将数据包写为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;
检查link以获取标题说明。
请检查此link以获取代码示例代码。