Skip to content

Commit

Permalink
remove usage of s6_addr16 and s6_addr32
Browse files Browse the repository at this point in the history
it turns out that those macros are not portable at all. rather than
adding workarounds to make it work for every single platform, just
use plain s6_addr instead.
  • Loading branch information
rofl0r committed Jan 9, 2018
1 parent d28f4df commit 2f3d33d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
8 changes: 0 additions & 8 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ if [ -z "$CC" ] ; then
CC=cc
fi

check_compile 'whether netinet/in.h defines s6_addr16' "" \
'#include <netinet/in.h>\nint main(int a, char**c){struct in6_addr x={.s6_addr32[0]=a};return x.s6_addr16[0]; }' \
|| {
check_compile 'whether netinet/in.h defines __u6_addr.__u6_addr16' \
'-Ds6_addr16=__u6_addr.__u6_addr16 -Ds6_addr32=__u6_addr.__u6_addr32' \
'#include <netinet/in.h>\nint main(int a, char**c){struct in6_addr x={.s6_addr32[0]=a};return x.s6_addr16[0]; }'
}

check_define __OpenBSD__ && \
check_compile_run 'whether OpenBSDs fclose() (illegally) calls close()' \
'#include <stdio.h>\n#include<stdlib.h>\nint close(int x){exit(0);}int main(){fclose(stdin);return 1;}' && \
Expand Down
7 changes: 3 additions & 4 deletions src/libproxychains.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ int close(int fd) {
return -1;
}
static int is_v4inv6(const struct in6_addr *a) {
return a->s6_addr32[0] == 0 && a->s6_addr32[1] == 0 &&
a->s6_addr16[4] == 0 && a->s6_addr16[5] == 0xffff;
return !memcmp(a->s6_addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
}
int connect(int sock, const struct sockaddr *addr, unsigned int len) {
INIT();
Expand Down Expand Up @@ -360,7 +359,7 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
: ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
struct in_addr v4inv6;
if(v6 && is_v4inv6(p_addr_in6)) {
memcpy(&v4inv6.s_addr, &p_addr_in6->s6_addr32[3], 4);
memcpy(&v4inv6.s_addr, &p_addr_in6->s6_addr[12], 4);
v6 = dest_ip.is_v6 = 0;
p_addr_in = &v4inv6;
}
Expand Down Expand Up @@ -455,7 +454,7 @@ int pc_getnameinfo(const struct sockaddr *sa, socklen_t salen,
unsigned scopeid = 0;
if(v6) {
if(is_v4inv6(&((struct sockaddr_in6*)sa)->sin6_addr)) {
memcpy(v4inv6buf, &((struct sockaddr_in6*)sa)->sin6_addr.s6_addr32[3], 4);
memcpy(v4inv6buf, &((struct sockaddr_in6*)sa)->sin6_addr.s6_addr[12], 4);
ip = v4inv6buf;
v6 = 0;
} else
Expand Down

0 comments on commit 2f3d33d

Please sign in to comment.