Thanks Reto, that works! If I want to bind the socket fd to another interface for the same http server (meaning same address:port), do I need to close/shutdown the existing server first and start a new one? Is there a way to just modify the socket bind without close/shutdown the socket?
Thanks, Bing On Friday, February 16, 2024 at 12:28:11 AM UTC-8 Reto wrote: > On Thu, Feb 15, 2024 at 11:30:53AM -0800, Bing wrote: > > I'm trying to implement a http server and I need to bind the underlying > > socket to a specific VRF instance so that the server only listens on > that > > VRF instance. When some specific event happens, the program needs to > > shutdown the http server. I'm using syscall.SetsockoptString() and > option > > "SO_BINDTODEVICE". > > Pretty sure what you are doing doesn't make sense... aren't you hooking > into > the wrong timing? > > You need to set the socket option prior to binding, not after. > There's a more convenient interface with a syscall.RawConn than what you > are > using. > The attached mod seems to work, maybe try that? > > Cheers, > Reto > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/dfa17e6b-0ef5-43e4-98cf-e2d253c717een%40googlegroups.com.