nimbuscontrols / EIPScanner

Free implementation of EtherNet/IP in C++
https://eipscanner.readthedocs.io/en/latest/
MIT License
224 stars 90 forks source link

create UDPBoundSocket in forwardOpen #102

Open nicktramp opened 9 months ago

nicktramp commented 9 months ago

After testing with my device (Brooks SLA5800 series MFC), creating a bound socket () right away in the forwardOpen() call (rather than a ) allows EIPScanner to utilize the correct, default port (2222) for Implicit comms. Without this, two separate sockets were created, but only one would have connections handled by the library; this caused the device to eventually time-out the connection after receiving no O->T packets (from the correct port, verified with Wireshark). All existing GTests pass.

I haven't heard feedback, but I'm hopeful this would solve many implicit communications issues, including #64. Note the source port of IO packets in the attached "Working_IO-filtered" capture file. Log output:

[INFO] Registered session 1
[INFO] Send request: service=0x54 epath=[classId=6 objectId=1]
[INFO] Open IO connection O2T_ID=9240597 T2O_ID=618266625 SerialNumber 1
[INFO] Open UDP socket to send data to 192.168.1.100:2222
[INFO] Received: secNum=3 data=[6][8][85][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=4 data=[31][f9][ab][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=5 data=[ab][dd][a3][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=6 data=[71][dd][ba][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=7 data=[87][f0][c2][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=8 data=[57][cb][af][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=9 data=[5f][37][ac][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=10 data=[f7][70][95][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=11 data=[11][9a][9c][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=12 data=[d4][9a][ac][3e][f8][f8][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=13 data=[d7][ab][89][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=14 data=[17][52][a8][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=15 data=[47][6e][a3][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=16 data=[8][b4][a9][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=17 data=[91][23][ab][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=18 data=[7c][be][ab][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=19 data=[32][3a][9d][3e][fa][f6][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=20 data=[f1][fd][7c][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Received: secNum=21 data=[d0][88][8f][3e][38][ff][c7][42][ff][ff][1f][41][0][0][0][0][0][0][0][0][0][0][0][0][27][0][0][0]
[INFO] Close connection connection T2O_ID=618266625
[INFO] Send request: service=0x4e epath=[classId=6 objectId=1]
[INFO] Unregistered session 1

Working_IO-filtered.pcapng.txt

Compare this with the source port of IO packets in the attached "Failing_IO-filtered" capture file. Log Output:

[INFO] Registered session 1
[INFO] Send request: service=0x54 epath=[classId=6 objectId=1]
[INFO] Open IO connection O2T_ID=9240596 T2O_ID=2604400641 SerialNumber 1
[INFO] Open UDP socket to send data to 192.168.1.100:2222
[WARNING] Connection SeriaNumber=1 is closed by timeout
[INFO] IO Closed
[WARNING] Attempt to close an already closed connection
[INFO] Unregistered session 1

Failure_IO-filtered.pcapng.txt