I have a Linux program that sends & receives UDP packets (it is interacting with various remote machines according to a protocol). I would like to "inject" additional UDP packets from a second program so that the return address is the IP/port used by the main program.
For example, imagine that the main program is sending "ping" style UDP packets to various remote hosts, and they send back "pong" packets. I would like the injector program to send a ping somewhere, and have the main program receive the pong. (The main program wouldn't be expecting that pong, because it didn't send out a ping, but that's OK.)
A complex way to do this would be to have the main program accept injected packets from a local pipe or something and then send them out. But it would be easier if the injector could just set the "from" address on a sendto() packet. (I also don't want the injector to steal packets meant for the main program. The injector would probably be short-lived, but if it bound the main program's port, then theoretically the system could deliver pongs to it instead of the main program?)