Hands-On-Network-Programming-with-C icon indicating copy to clipboard operation
Hands-On-Network-Programming-with-C copied to clipboard

chapter 4: getaddrinfo() and destination IP of packet

Open ghenry opened this issue 3 years ago • 2 comments

Hi Lewis,

Have you ever done this with a UDP package?

https://stackoverflow.com/questions/5281409/get-destination-address-of-a-received-udp-packet

Looks like you can't use recvfrom and have to switch to recvmsg to use IP_PKTINFO

I'll dig into the book again.

Thanks for reading.

Gavin.

ghenry avatar Nov 25 '21 14:11 ghenry

Hi Gavin,

No, I haven't done it like that using only one socket before. What I have done, is opened a separate socket on each interface, and then the receiving address is determined by which socket it comes in on. Using multiple sockets will probably be more portable, but otherwise, the Stack Overflow solution might be simpler and I suspect would perform slightly better (no socket multiplexing).

codeplea avatar Nov 25 '21 15:11 codeplea

Thanks Lewis :-)

ghenry avatar Nov 25 '21 15:11 ghenry