How to set source address when sending using and UDP socket

前端 未结 2 920
轻奢々
轻奢々 2021-01-13 03:32

I\'ve two pc using VRRP for redundancy. So every PC (Linux) has a physical and a Virtual IP address.

I\'ve a software (C++) with a client/server architecture with UD

2条回答
  •  生来不讨喜
    2021-01-13 03:50

    i'm not sure i understand entirely your question, but in terms of writing C/C++ code on linux at low level, you can import the ip.h header from the linux kernel headers which gives you access to the low level IP packet structure. (UDP works on top of IP)

    #include 
    

    and then look at struct iphdr which is the header for every IP packet sent and that contains a saddr member which you can set programmatically to be the source address.

提交回复
热议问题