summaryrefslogtreecommitdiffstats
path: root/honeypot.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2012-06-04 04:28:39 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2012-06-04 04:30:32 +0200
commit3d1a2e3ba9952de3dcdf5a79329e8fd06f2e87e6 (patch)
treec3ed3a9afa5235d2d811b28e3c368d4bf6035442 /honeypot.c
parentProper string size. (diff)
downloadtelnet-password-honeypot-3d1a2e3ba9952de3dcdf5a79329e8fd06f2e87e6.tar.xz
telnet-password-honeypot-3d1a2e3ba9952de3dcdf5a79329e8fd06f2e87e6.zip
Properly convert ipv6 mapped ipv4 addresses.
Diffstat (limited to 'honeypot.c')
-rw-r--r--honeypot.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/honeypot.c b/honeypot.c
index 59f48c2..8bff054 100644
--- a/honeypot.c
+++ b/honeypot.c
@@ -499,11 +499,16 @@ int main(int argc, char *argv[])
}
if (!child) {
char ipaddr[INET6_ADDRSTRLEN];
+ struct in6_addr *v6;
memset(ipaddr, 0, sizeof(ipaddr));
- if (connection_addr.ss_family == AF_INET6)
- inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)&connection_addr)->sin6_addr), ipaddr, INET6_ADDRSTRLEN);
- else if (connection_addr.ss_family == AF_INET)
- inet_ntop(AF_INET, &(((struct sockaddr_in *)&connection_addr)->sin_addr), ipaddr, INET6_ADDRSTRLEN);
+ if (connection_addr.ss_family == AF_INET6) {
+ v6 = &(((struct sockaddr_in6 *)&connection_addr)->sin6_addr);
+ if (v6->s6_addr32[0] == 0 && v6->s6_addr32[1] == 0 && v6->s6_addr16[4] == 0 && v6->s6_addr16[5] == 0xFFFF)
+ inet_ntop(AF_INET, &v6->s6_addr32[3], ipaddr, INET_ADDRSTRLEN);
+ else
+ inet_ntop(AF_INET6, v6, ipaddr, INET6_ADDRSTRLEN);
+ } else if (connection_addr.ss_family == AF_INET)
+ inet_ntop(AF_INET, &(((struct sockaddr_in *)&connection_addr)->sin_addr), ipaddr, INET_ADDRSTRLEN);
printf("Forked process %d for connection %s.\n", getpid(), ipaddr);
handle_connection(connection_fd, ipaddr);
}