-
Notifications
You must be signed in to change notification settings - Fork 704
Added support to for SO_BINDTODEVICE on listening socket #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Added support to for SO_BINDTODEVICE on listening socket #494
Conversation
Yes that would be very useful, especially for VPNs! Like you could easily turn one off an on in selective applications or use several at once. |
{ | ||
int listenfd; | ||
int ret; | ||
int ipv6=1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int ipv6=1; | |
int ipv6 = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BlankEclair: please refrain on suggesting whitespace changes on random PRs you absolutely are not involved with. if i want such changes, i will ask for them myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry--I overzealously commented on the inconsistency
It won't happen again
log_message(LOG_ERR, "socket() failed: %s", strerror(errno)); | ||
return -1; | ||
} | ||
ipv6=0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ipv6=0; | |
ipv6 = 0; |
|
||
strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); | ||
if (setsockopt(listenfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0) { | ||
log_message(LOG_ERR, "setsockopt(SO_BINDTODEVICE,%s) failed: %s", interface, strerror (errno)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not read the surrounding tinyproxy code, but I think it should be
log_message(LOG_ERR, "setsockopt(SO_BINDTODEVICE,%s) failed: %s", interface, strerror (errno)); | |
log_message(LOG_ERR, "setsockopt(SO_BINDTODEVICE,%s) failed: %s", interface, strerror(errno)); |
I added support to bind the listen statement to an interface, not an IP address. The backgroubnd is IPv6, where I have trouble binding to all IPv6 adresses of an inferface on boot, because the IPv6 adresses are not usabel, yet.
With this pull-request the listen-statement in the config file accepts an interface name and tinyproxy does setsockopt(SO_BINDTODEVICE) on the interface to bind the socket to an interface.