mirror of
https://github.com/3proxy/3proxy.git
synced 2025-02-23 10:35:40 +08:00
Support IP_BOUND_IF on MacOS
This commit is contained in:
parent
4ad05d1565
commit
c1beceb24b
10
src/common.c
10
src/common.c
@ -436,6 +436,16 @@ int doconnect(struct clientparam * param){
|
|||||||
if(so._setsockopt(param->remsock, SOL_SOCKET, SO_BINDTODEVICE, param->srv->obindtodevice, strlen(param->srv->obindtodevice) + 1))
|
if(so._setsockopt(param->remsock, SOL_SOCKET, SO_BINDTODEVICE, param->srv->obindtodevice, strlen(param->srv->obindtodevice) + 1))
|
||||||
return 12;
|
return 12;
|
||||||
}
|
}
|
||||||
|
#elseif IP_BOUND_IF
|
||||||
|
if(param->srv->obindtodevice) {
|
||||||
|
int idx;
|
||||||
|
idx = if_nametoindex(param->srv->obindtodevice)
|
||||||
|
if(!idx || so._setsockopt(param->remsock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx)))
|
||||||
|
return 12;
|
||||||
|
#ifndef NOIPV6
|
||||||
|
if(param->srv->family != 4 && so._setsockopt(param->remsock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx))) return 12;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if(SAISNULL(¶m->sinsl)){
|
if(SAISNULL(¶m->sinsl)){
|
||||||
#ifndef NOIPV6
|
#ifndef NOIPV6
|
||||||
|
@ -216,7 +216,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
|||||||
" -u never ask for username\n"
|
" -u never ask for username\n"
|
||||||
" -u2 always ask for username\n"
|
" -u2 always ask for username\n"
|
||||||
#endif
|
#endif
|
||||||
#ifdef SO_BINDTODEVICE
|
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||||
" -Di(DEVICENAME) bind internal interface to device, e.g. eth1\n"
|
" -Di(DEVICENAME) bind internal interface to device, e.g. eth1\n"
|
||||||
" -De(DEVICENAME) bind external interface to device, e.g. eth1\n"
|
" -De(DEVICENAME) bind external interface to device, e.g. eth1\n"
|
||||||
#endif
|
#endif
|
||||||
@ -323,7 +323,7 @@ int MODULEMAINFUNC (int argc, char** argv){
|
|||||||
if(!conf.demon)daemonize();
|
if(!conf.demon)daemonize();
|
||||||
conf.demon = 1;
|
conf.demon = 1;
|
||||||
break;
|
break;
|
||||||
#ifdef SO_BINDTODEVICE
|
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||||
case 'D':
|
case 'D':
|
||||||
if(argv[i][2] == 'i') srv.ibindtodevice = mystrdup(argv[i] + 3);
|
if(argv[i][2] == 'i') srv.ibindtodevice = mystrdup(argv[i] + 3);
|
||||||
else srv.obindtodevice = mystrdup(argv[i] + 3);
|
else srv.obindtodevice = mystrdup(argv[i] + 3);
|
||||||
@ -611,7 +611,25 @@ int MODULEMAINFUNC (int argc, char** argv){
|
|||||||
so._setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int));
|
so._setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
#ifdef SO_BINDTODEVICE
|
#ifdef SO_BINDTODEVICE
|
||||||
if(srv.ibindtodevice) so._setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, srv.ibindtodevice, strlen(srv.ibindtodevice) + 1);
|
if(srv.ibindtodevice && so._setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, srv.ibindtodevice, strlen(srv.ibindtodevice) + 1)) {
|
||||||
|
dolog(&defparam, "failed to bind device");
|
||||||
|
return -12;
|
||||||
|
}
|
||||||
|
#elseif IP_BOUND_IF
|
||||||
|
if(srv.ibindtodevice){
|
||||||
|
int idx;
|
||||||
|
idx = if_nametoindex(srv.ibindtodevice);
|
||||||
|
if(!idx || setsockopt(sockfd, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx))) {
|
||||||
|
dolog(&defparam, "failed to bind device");
|
||||||
|
return -12;
|
||||||
|
}
|
||||||
|
#ifndef NOIPV6
|
||||||
|
if(so._setsockopt(param->remsock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx))) {
|
||||||
|
dolog(&defparam, "failed to bind device");
|
||||||
|
return -12;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
size = sizeof(srv.intsa);
|
size = sizeof(srv.intsa);
|
||||||
@ -974,7 +992,7 @@ void srvfree(struct srvparam * srv){
|
|||||||
if(srv->logtarget) myfree(srv->logtarget);
|
if(srv->logtarget) myfree(srv->logtarget);
|
||||||
if(srv->logformat) myfree(srv->logformat);
|
if(srv->logformat) myfree(srv->logformat);
|
||||||
if(srv->nonprintable) myfree(srv->nonprintable);
|
if(srv->nonprintable) myfree(srv->nonprintable);
|
||||||
#ifdef SO_BINDTODEVICE
|
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||||
if(srv->ibindtodevice) myfree(srv->ibindtodevice);
|
if(srv->ibindtodevice) myfree(srv->ibindtodevice);
|
||||||
if(srv->obindtodevice) myfree(srv->obindtodevice);
|
if(srv->obindtodevice) myfree(srv->obindtodevice);
|
||||||
#endif
|
#endif
|
||||||
|
@ -457,7 +457,7 @@ struct srvparam {
|
|||||||
struct pollfd fds;
|
struct pollfd fds;
|
||||||
FILE *stdlog;
|
FILE *stdlog;
|
||||||
unsigned char * target;
|
unsigned char * target;
|
||||||
#ifdef SO_BINDTODEVICE
|
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||||
char * ibindtodevice;
|
char * ibindtodevice;
|
||||||
char * obindtodevice;
|
char * obindtodevice;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user