From f6d60ec6dbd27f0e324321843198f5bc714575bf Mon Sep 17 00:00:00 2001 From: William Deshaies Date: Tue, 24 Feb 2026 11:14:54 -0500 Subject: [PATCH 1/2] Fix interface parsing. Add interface option to configure command. --- src/main.cpp | 11 ++++++----- src/pcapInterface.c | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index df93062..635b0fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,13 +7,16 @@ int main(int argc, char **argv) { app.require_subcommand(); CLI::App *search = app.add_subcommand("search", "Search for Profinet devices on the network."); - CLI::Option *interface = search->add_option("-i,--interface", "Interface to use"); + std::string interfaceName; + CLI::Option *interface = search->add_option("-i,--interface", interfaceName, "Interface to use"); int timeout = 1000; search->add_option("-t,--timeout", timeout, "Time to search for devices in milliseconds"); CLI::App *configure = app.add_subcommand("configure", "Configure Profinet devices on the network."); CLI::Option *device = configure->add_option("device", "The current name of the device to configure. Use EMPTY for blank string.") ->required(true); + std::string configureInterfaceName; + configure->add_option("-i,--interface", configureInterfaceName, "Interface to use"); configure->add_option("-t,--timeout", timeout, "Time to search for devices in milliseconds"); std::string newName; @@ -33,11 +36,10 @@ int main(int argc, char **argv) { try { if (*search) { - ProfinetTool profinetTool(timeout); - if (!interface->empty()) profinetTool = ProfinetTool(interface->as(), timeout); + ProfinetTool profinetTool = interface->empty() ? ProfinetTool(timeout) : ProfinetTool(interfaceName, timeout); profinetTool.searchForDevices(); } else if (*configure) { - ProfinetTool profinetTool(timeout); + ProfinetTool profinetTool = configureInterfaceName.empty() ? ProfinetTool(timeout) : ProfinetTool(configureInterfaceName, timeout); profinetTool.configureDevices(deviceName, newName, newIP, newSubnet, newGateway); } @@ -46,6 +48,5 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - return 0; } diff --git a/src/pcapInterface.c b/src/pcapInterface.c index dcab613..d0c17ad 100644 --- a/src/pcapInterface.c +++ b/src/pcapInterface.c @@ -87,14 +87,24 @@ void profinet_pcap_callback(unsigned char *args, const struct pcap_pkthdr *packe struct ether_header header; memcpy(&header, packet, sizeof(header)); - if (header.ether_type != htons(ETH_P_8021Q)) return; - const int packetLength = packetInfo->len; + int payloadOffset; + + if (header.ether_type == htons(ETH_P_8021Q)) { + /* 802.1Q tagged frame: 4-byte VLAN tag after Ethernet header */ + payloadOffset = (int) sizeof(struct ether_header) + 4; + } else if (header.ether_type == htons(0x8892)) { + /* Untagged Profinet frame */ + payloadOffset = (int) sizeof(struct ether_header); + } else { + return; + } - const int profinetPacketSize = packetLength - (int) sizeof(struct ether_header) - 4; + const int profinetPacketSize = packetLength - payloadOffset; + if (profinetPacketSize <= 0) return; unsigned char profinetPacketRaw[profinetPacketSize]; - memcpy(profinetPacketRaw, packet + sizeof(struct ether_header) + 4, profinetPacketSize); + memcpy(profinetPacketRaw, packet + payloadOffset, profinetPacketSize); struct profinet_dcp_header dcpHeader; memcpy(&dcpHeader, profinetPacketRaw, sizeof(dcpHeader)); From 0e69b2f727a226b6117a19f0d479cb303b899f78 Mon Sep 17 00:00:00 2001 From: William Deshaies Date: Tue, 24 Feb 2026 11:41:08 -0500 Subject: [PATCH 2/2] fix: use -I for --interface in configure to avoid conflict with -i/--ip --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 635b0fa..2a60081 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,7 @@ int main(int argc, char **argv) { CLI::Option *device = configure->add_option("device", "The current name of the device to configure. Use EMPTY for blank string.") ->required(true); std::string configureInterfaceName; - configure->add_option("-i,--interface", configureInterfaceName, "Interface to use"); + configure->add_option("-I,--interface", configureInterfaceName, "Interface to use"); configure->add_option("-t,--timeout", timeout, "Time to search for devices in milliseconds"); std::string newName;