Skip to content
Snippets Groups Projects
Commit f7297aaf authored by Denis Filatov's avatar Denis Filatov
Browse files

fix mac_address compare

parent 228baffe
No related branches found
No related tags found
No related merge requests found
......@@ -74,6 +74,7 @@ int main(const int32_t p_argc, char* const p_argv[]) {
fprintf(stderr, "Failed to parse command line arguments: MAC address of the OBU missing, exit.\n");
return -1;
}
hex2bin(mac_address, 6, mac_address, 12);
if (udp_nic == NULL) {
fprintf(stderr, "Failed to parse command line arguments: NIC UDP missing, exit.\n");
return -1;
......@@ -224,13 +225,15 @@ int main(const int32_t p_argc, char* const p_argv[]) {
fprintf(stderr, "'recvfrom' operation failure: %s, state=%d.\n", strerror(errno), state);
continue;
}
printf("Received UDP broadcast:%s:%u.\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
// Inject the packet
struct ether_header* eth_header = (struct ether_header*)buffer;
char eth_src[10];
bin2hex(eth_src, 10, (const uint8_t*)(eth_header->ether_shost), 6);
if (strcmp(eth_src, mac_address) != 0) { /* do not inject our own packet - Should never be the case */
// bin2hex(eth_src, 10, (const uint8_t*)(eth_header->ether_shost), 6);
if (memcmp(eth_header->ether_shost, mac_address, 6) != 0) { /* do not inject our own packet - Should never be the case */
printf("Forward UDP packet:%s:%u.\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
pcap_sendpacket(device, buffer, result);
}else{
printf("Skip UDP packet:%s:%u.\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
}
} /* End of 'while' statement */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment