1

Since there is no support of IP_PKTINFO in python(for IPv4), are there no multihomed UDP python servers out there in production?

If there are ( and I expect there shall be), how do they handle the problem of sending the response UDP packets to the interface from which they received the request!


EDIT for clarification

Lets say I have a UDP server with multiple interfaces (consider 2 here), each with IP 172.217.163.68 and 172.217.163.69 respectively. The server has socket bind call on 0.0.0.0. Now if a request packet comes on 172.217.163.68, the server processes it, forms a response packet, and then sends on what interface? There is no way it knows about the interface from which request packet arrived, so it can't fill the sending interface IP. This is because there is no support for IP_PKTINFO in python.

Also it should be noted that we can't make use of the default route here. If default route gets used, then from the perspective of the client, it sent request to 172.217.163.68 but is getting response from 172.217.163.69, which is obviously wrong.

Piyush Deshmukh
  • 519
  • 1
  • 7
  • 14

1 Answers1

0

UDP servers use recvfrom and sendto to get the source IP address and to send back the response:

Receive:message, address = socket.recvfrom(1024)

Send: socket.sendto(message, address)

You can see an example UDP server in python in this question

Malt
  • 28,965
  • 9
  • 65
  • 105
  • `sendto` and `recvfrom` are used w.r.t. to the client. On the server side, I am more of interested in something like 'sendfrom' so that I have a control on from which interface should I send a packet. Edited the question for clarification. – Piyush Deshmukh Mar 19 '19 at 05:46