jacobschaer / python-doipclient

Pure Python ISO 13400 Client
MIT License
151 stars 50 forks source link

How to choose network interface for DoIp client #44

Open sylvtellier opened 10 months ago

sylvtellier commented 10 months ago

Hello everyone.

Many thanks for this package which works perfectly with udsoncan to connect to an ECU using DoIp.

However, I am encountering a problem choosing the network interface to use to create the DoIPClient client.

I have a classic internal network card and a USB/Ethernet adapter on my computer. My ECU supporting Doip is plugged to the usb/ethernet adapter. The network card is used for other communication. When I simply create my client (as in this package's documentation : address, announcement = DoIPClient.get_entity()), the VehicleIdentificationRequest is sent by default to my internal ethernet card.

I would like this request to go to my usb/ethernet adapter.

If I deactivate the internal network card via the Windows control panel, the VehicleIdentificationRequest goes to my usb/ethernet adapter and I correctly receive the response from my ECU with its IP address, its port and its logical address.

How can we define the communication interface of the DoIP client?

Thanks for your help

sylvtellier commented 10 months ago

re,

I just found my answer using your answer located here : https://github.com/jacobschaer/python-doipclient/issues/33

I didn't understand your answer on first reading. By modifying the line: sock.bind(("", udp_port)) and replacing the "" by IP address of my usb/ethernet adapter, I solved the problem. I also manually put this address in my interface settings. My problem is solved now. On the other hand, it requires me to always use this address for all our adapters on different computers connected to the diagnostic gateway.

what bothers me is that I modified your package to achieve my ends. I don't know if it was the best thing to do.

Maybe you have an opinion or a better solution without modifying your package?

jacobschaer commented 9 months ago

The intention is that your network interface should be associated with an IP in the correct subnet so that the OS will deliver broadcast packets to it. If your NIC isn't in the correct subnet then I wouldn't expect get_entity() to work. For IPv6 with multicast, it's a little more complicated as IGMP requires specifying a source interface anyways hence we allow the user to pass in their desired interface. But in general it's better to let the OS handle such things.

An argument could be made to having get_entity() and await_vehicle_announcement() accept a client_ip specifically for IPV4 that defaults to None - if it's None use INADDR_ANY (""). It's somewhat confusing for IPV6 though as the source_interface and client_ip could potentially not match