I'm not sure I fully understand your question, but from the point of writing low-level C / C ++ code on Linux, you can import the ip.h header from the Linux kernel headers, giving you access to the low-level IP packet structure. (UDP works over IP)
#include <linux/ip.h>
and then look at struct iphdr , which is the header for each IP packet sent and contains the saddr element, which you can programmatically specify as the source address.
source share