Skip to content

Commit

Permalink
Handle link type DLT_EN10MB and DLT_RAW
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed Oct 2, 2023
1 parent bd2bfc4 commit 74aea2d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
45 changes: 24 additions & 21 deletions udpCallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ long int countToFlood = 0;
int asterixTime = 0;
int setMulticastTTL = 0;
long multicastTTLValue = 0;
int datalink;

void waitBeforeSending(struct timeval actual_delta)
{
Expand Down Expand Up @@ -141,31 +142,33 @@ static void callback_handler(u_char *user __attribute__((unused)),
if (caplen != len)
return;

/* Copy the ethernet header */
if (len < sizeof(eth_hdr))
return;
memcpy(&eth_hdr, bytes, sizeof(eth_hdr));
bytes += sizeof(eth_hdr);
len -= sizeof(eth_hdr);
if (datalink == DLT_EN10MB) {
/* Copy the ethernet header */
if (len < sizeof(eth_hdr))
return;
memcpy(&eth_hdr, bytes, sizeof(eth_hdr));
bytes += sizeof(eth_hdr);
len -= sizeof(eth_hdr);

protocol = ntohs(eth_hdr.ether_type);
protocol = ntohs(eth_hdr.ether_type);

/* Check for VLAN data */
if (protocol == ETHERTYPE_VLAN)
{
/* Copy the vlan header */
if (len < sizeof(vlan_hdr))
return;
memcpy(&vlan_hdr, bytes, sizeof(vlan_hdr));
bytes += sizeof(vlan_hdr);
len -= sizeof(vlan_hdr);
/* Check for VLAN data */
if (protocol == ETHERTYPE_VLAN)
{
/* Copy the vlan header */
if (len < sizeof(vlan_hdr))
return;
memcpy(&vlan_hdr, bytes, sizeof(vlan_hdr));
bytes += sizeof(vlan_hdr);
len -= sizeof(vlan_hdr);

protocol = ntohs(vlan_hdr.vlan_tci);
}
protocol = ntohs(vlan_hdr.vlan_tci);
}

/* Discard non IP datagram */
if (protocol != ETHERTYPE_IP)
return;
/* Discard non IP datagram */
if (protocol != ETHERTYPE_IP)
return;
}

/* Copy the IPv4 header */
if (len < sizeof(ip_hdr))
Expand Down
1 change: 1 addition & 0 deletions udpCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ extern int oneByOne;
extern int asterixTime;
extern int setMulticastTTL;
extern long multicastTTLValue;
extern int datalink;

extern void replayAll(pcap_t *pcap);
6 changes: 6 additions & 0 deletions udpReplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ int main(int argc, char* argv[])
return -1;
}

datalink = pcap_datalink(pcap);

if (datalink != DLT_EN10MB)
if (datalink != DLT_RAW) {
printf("datalink = %i not handled\n", datalink);
}
replayAll(pcap);

return 0;
Expand Down

0 comments on commit 74aea2d

Please sign in to comment.