How to set source address when sending using and UDP socket

前端 未结 2 921
轻奢々
轻奢々 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:49

    When the kernel needs to send something through a socket it performs these steps

    • if the socket is bound, use that source address
    • is the socket is not bound, it looks around for interfaces and selects a source address

    So you need to bind(2) your socket to your desired address. For more information: Source Address Selection.

提交回复
热议问题