This is a complete C language refactoring of the original Python Profinet network administration tool. The program enables communication with Profinet industrial devices through the Discovery and Configuration Protocol (DCP) and RPC mechanisms.
To compile the project, use the provided Makefile:
makeThis will create the executable in the bin/ directory.
make all- Build the project (default)make debug- Build with debug flags and sanitizersmake clean- Remove build artifactsmake install- Install to/usr/local/binmake test- Run tests (placeholder for future implementation)
The C implementation maintains the same command-line interface as the original Python version:
./bin/profinet -i <INTERFACE> <action> [arguments]discover- Discover Profinet devices on the networkget-param <MAC> <param>- Get device parameterset-param <MAC> <param> <value>- Set device parameterread <MAC> <api> <slot> <subslot> <idx>- Read data from deviceread-inm0-filter <MAC>- Read I&M0 filter dataread-inm0 <MAC> <api> <slot> <subslot>- Read I&M0 dataread-inm1 <MAC> <api> <slot> <subslot>- Read I&M1 datawrite-inm1 <MAC> <api> <slot> <subslot> <tag>- Write I&M1 data
# Discover devices
./bin/profinet -i eth0 discover
# Get station name
./bin/profinet -i eth0 get-param 00:11:22:33:44:55 name
# Set station name
./bin/profinet -i eth0 set-param 00:11:22:33:44:55 name "NewStationName"
# Read I&M0 data
./bin/profinet -i eth0 read-inm0 00:11:22:33:44:55 0 0 0The C implementation follows a modular architecture similar to the original Python version:
profinet.h- Core definitions and structuresprotocol.h- Profinet protocol packet structures (DCP, RPC, IOD)util.h/c- Utility functions for networking, MAC/IP conversiondcp.h/c- Discovery and Configuration Protocol implementationrpc.h/c- RPC communication implementationmain.c- CLI interface and main program logic
- Memory Management: Manual allocation/deallocation for all data structures
- Error Handling: Structured error codes instead of Python exceptions
- Packet Construction: Manual byte-level packet assembly instead of Python's automatic serialization
- Socket Operations: Direct use of Linux socket APIs
- Command Line Parsing: Manual parsing instead of Python's argparse
The implementation uses a structured error handling approach with defined error codes:
PROFINET_SUCCESS- Operation completed successfullyPROFINET_ERROR_SOCKET- Socket creation/operation failedPROFINET_ERROR_BIND- Socket bind failedPROFINET_ERROR_SEND- Data send failedPROFINET_ERROR_RECV- Data receive failedPROFINET_ERROR_TIMEOUT- Operation timed outPROFINET_ERROR_INVALID_PARAM- Invalid parameter providedPROFINET_ERROR_MEMORY- Memory allocation failedPROFINET_ERROR_IOCTL- System ioctl operation failed
This implementation targets Linux systems and uses Linux-specific socket operations (AF_PACKET, ioctl for MAC address retrieval). For other platforms, the socket and interface handling code would need to be adapted.
- GCC compiler with C99 support
- Linux operating system
- Network interface with raw socket permissions (typically requires root privileges)
- Some advanced RPC features are implemented as placeholders
- Web GUI component from the original Python version is not included
- Error reporting could be more detailed for better troubleshooting
- Comprehensive test suite is not yet implemented