从pcap文件中读数据并组播

本文介绍如何从pcap文件中提取数据,并详细阐述了如何利用这些数据进行UDP组播操作,参考了https://www.tenouk.com/Module41c.html的相关教程。
摘要由CSDN通过智能技术生成
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#define UDP_DEST_PORT 30000
#define UDP_LOCAL_PORT 30000
#define MAX_LINE 1024
//#define SEND_NUM            10
unsigned match_udp(FILE*, int, unsigned char*, long*);
int      dataSend(unsigned char*, long, const char*, int);

const char* ipDst = "239.100.0.100";
typedef struct pcap_pkt_header_t
{
   
    // struct   time_val   ts;           /* time stamp */
    int          wSecond;       /* seconds ????? time_t ?????? */
    int          wMicroseconds; /* and microseconds */
    unsigned int uwcaplen;      /* length of portion present */
    unsigned int uwlen;         /* length this packet (off wire) */
} __attribute__((packed)) pcap_pkt_header_t;
// MAC_HEAD_STRUCT
typedef struct mac_header_t
{
   
    unsigned char  ucaDstMAC[6]; //
    unsigned char  ucaSrcMAC[6]; //
    unsigned short usFrameType;  //
} __attribute__((packed)) mac_header_t;

// IP_PACKET_HEAD
typedef struct ip_header_t
{
   
    unsigned char  ucVer_HLen;     //
    unsigned char  ucTOS;          //
    unsigned short usTotalLen;     //
    unsigned short usID;           //
    unsigned short usFlag_Segment; //
    unsigned char  ucTTL;          //
    unsigned char  ucProtocol;     //
    unsigned short usChecksum;     //
    unsigned int   uwSrcIP;        //
    unsigned int   uwDstIP;        //
} __attribute__((packed)) ip_header_t;

// UDP HEADER
typedef struct udp_header_t
{
                                 // UDP
    unsigned short usSrcPort;  //
    unsigned short usDstPort;  //
    unsigned short usDataLen;  //
    unsigned short usChecksum; //
} __attribute__
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值