mirror of
https://github.com/3proxy/3proxy.git
synced 2025-02-23 02:25:40 +08:00
Always select between IPV6_BOUND_IF and IP_BOUND_IF
This commit is contained in:
parent
3dc698eccd
commit
c98621aeef
20
src/common.c
20
src/common.c
@ -414,6 +414,14 @@ int doconnect(struct clientparam * param){
|
|||||||
}
|
}
|
||||||
if(!*SAPORT(¶m->sinsr))*SAPORT(¶m->sinsr) = *SAPORT(¶m->req);
|
if(!*SAPORT(¶m->sinsr))*SAPORT(¶m->sinsr) = *SAPORT(¶m->req);
|
||||||
if ((param->remsock=so._socket(SASOCK(¶m->sinsr), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {return (11);}
|
if ((param->remsock=so._socket(SASOCK(¶m->sinsr), SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {return (11);}
|
||||||
|
if(SAISNULL(¶m->sinsl)){
|
||||||
|
#ifndef NOIPV6
|
||||||
|
if(*SAFAMILY(¶m->sinsr) == AF_INET6) param->sinsl = param->srv->extsa6;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
param->sinsl = param->srv->extsa;
|
||||||
|
}
|
||||||
|
*SAPORT(¶m->sinsl) = 0;
|
||||||
setopts(param->remsock, param->srv->srvsockopts);
|
setopts(param->remsock, param->srv->srvsockopts);
|
||||||
|
|
||||||
so._setsockopt(param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
so._setsockopt(param->remsock, SOL_SOCKET, SO_LINGER, (char *)&lg, sizeof(lg));
|
||||||
@ -440,21 +448,13 @@ int doconnect(struct clientparam * param){
|
|||||||
if(param->srv->obindtodevice) {
|
if(param->srv->obindtodevice) {
|
||||||
int idx;
|
int idx;
|
||||||
idx = if_nametoindex(param->srv->obindtodevice);
|
idx = if_nametoindex(param->srv->obindtodevice);
|
||||||
if(!idx || so._setsockopt(param->remsock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx)))
|
if(!idx || (*SAFAMILY(¶m->sinsl) == AF_INET && so._setsockopt(param->remsock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx))))
|
||||||
return 12;
|
return 12;
|
||||||
#ifndef NOIPV6
|
#ifndef NOIPV6
|
||||||
if(param->srv->family != 4 && so._setsockopt(param->remsock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx))) return 12;
|
if(*SAFAMILY(¶m->sinsl) == AF_INET6 && so._setsockopt(param->remsock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx))) return 12;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(SAISNULL(¶m->sinsl)){
|
|
||||||
#ifndef NOIPV6
|
|
||||||
if(*SAFAMILY(¶m->sinsr) == AF_INET6) param->sinsl = param->srv->extsa6;
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
param->sinsl = param->srv->extsa;
|
|
||||||
}
|
|
||||||
*SAPORT(¶m->sinsl) = 0;
|
|
||||||
if(so._bind(param->remsock, (struct sockaddr*)¶m->sinsl, SASIZE(¶m->sinsl))==-1) {
|
if(so._bind(param->remsock, (struct sockaddr*)¶m->sinsl, SASIZE(¶m->sinsl))==-1) {
|
||||||
return 12;
|
return 12;
|
||||||
}
|
}
|
||||||
|
@ -619,12 +619,12 @@ int MODULEMAINFUNC (int argc, char** argv){
|
|||||||
if(srv.ibindtodevice){
|
if(srv.ibindtodevice){
|
||||||
int idx;
|
int idx;
|
||||||
idx = if_nametoindex(srv.ibindtodevice);
|
idx = if_nametoindex(srv.ibindtodevice);
|
||||||
if(!idx || setsockopt(sock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx))) {
|
if(!idx || (*SAFAMILY(&srv.intsa) == AF_INET && setsockopt(sock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx)))) {
|
||||||
dolog(&defparam, (unsigned char *)"failed to bind device");
|
dolog(&defparam, (unsigned char *)"failed to bind device");
|
||||||
return -12;
|
return -12;
|
||||||
}
|
}
|
||||||
#ifndef NOIPV6
|
#ifndef NOIPV6
|
||||||
if(so._setsockopt(sock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx))) {
|
if((*SAFAMILY(&srv.intsa) == AF_INET6 && so._setsockopt(sock, IPPROTO_IPV6, IPV6_BOUND_IF, &idx, sizeof(idx)))) {
|
||||||
dolog(&defparam, (unsigned char *)"failed to bind device");
|
dolog(&defparam, (unsigned char *)"failed to bind device");
|
||||||
return -12;
|
return -12;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user