Skip to content

Commit

Permalink
Fix DNS resolution with IPv6 disabled. Merges #208. Fixes #93, #207.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanosg authored and thommey committed Aug 8, 2016
2 parents 1753372 + 9679f7b commit fb4c84d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
3 changes: 3 additions & 0 deletions doc/Changes1.8
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Eggdrop Changes (since version 1.8.0)

1.8.0 (CVS):

- Fix DNS resolution with IPv6 disabled.
Patch by: Geo, thommey / Found by: raclure

- Fix a compilation issue with --disable-ipv6.
Patch by: Geo

Expand Down
51 changes: 40 additions & 11 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,50 @@ int setsockname(sockname_t *addr, char *src, int port, int allowres)
addr->addr.s4.sin_family = AF_INET;
}
#else
int i, count;

egg_bzero(addr, sizeof(sockname_t));
if (!egg_inet_aton(src, &addr->addr.s4.sin_addr) && allowres) {

/* If it's not an IPv4 address, check if its IPv6 (so it can fail/error
* appropriately). If it's not, and allowres is 1, use gethostbyname()
* to try and resolve. If allowres is 0, return AF_UNSPEC to allow
* dns.mod to do it's thing.
* Also, because we can't be sure inet_pton exists on the system, we
* have to resort to hackishly counting :s to see if its IPv6 or not.
* Go internet.
*/
if (!inet_pton(AF_INET, src, &addr->addr.s4.sin_addr)) {
/* Boring way to count :s */
count = 0;
for (i = 0; src[i]; i++) {
if (src[i] == ':') {
count++;
if (count == 2)
break;
}
}
if (count > 1) {
putlog(LOG_MISC, "*", "ERROR: This looks like an IPv6 address, \
but this Eggdrop was not compiled with IPv6 support.");
af = AF_UNSPEC;
}
else if (allowres) {
/* src is a hostname. Attempt to resolve it.. */
if (!sigsetjmp(alarmret, 1)) {
alarm(resolve_timeout);
hp = gethostbyname(src);
alarm(0);
if (!sigsetjmp(alarmret, 1)) {
alarm(resolve_timeout);
hp = gethostbyname(src);
alarm(0);
} else
hp = NULL;
if (hp) {
egg_memcpy(&addr->addr.s4.sin_addr, hp->h_addr, hp->h_length);
af = hp->h_addrtype;
}
} else
hp = NULL;
if (hp) {
egg_memcpy(&addr->addr.s4.sin_addr, hp->h_addr, hp->h_length);
af = hp->h_addrtype;
}
af = AF_UNSPEC;
} else
af = AF_INET;
af = AF_INET;

addr->family = addr->addr.s4.sin_family = AF_INET;
addr->addr.sa.sa_family = addr->family;
Expand Down

0 comments on commit fb4c84d

Please sign in to comment.