diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-03-03 08:09:15 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-03-03 08:09:15 +0000 |
commit | a5ac9fede6f5c9cb157cac99c2ff0750e5495482 (patch) | |
tree | 62fb27ab870a7ed1fff28063309370dffe8dc15c /usr.sbin/smtpd/util.c | |
parent | 39b020e742dfb1597fb501ba5f2d86287ff66b20 (diff) |
fix ss_to_text() and ss_to_ptr() so IP addresses are logged correctly
on big-endian machines ...
spotted and tested by landry@ (and I)
Diffstat (limited to 'usr.sbin/smtpd/util.c')
-rw-r--r-- | usr.sbin/smtpd/util.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index 4d06eb3d5cc..d18b734da6c 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.38 2010/11/29 15:25:56 gilles Exp $ */ +/* $OpenBSD: util.c,v 1.39 2011/03/03 08:09:14 gilles Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -199,12 +199,13 @@ ss_to_text(struct sockaddr_storage *ss) in_addr_t addr; addr = ((struct sockaddr_in *)ss)->sin_addr.s_addr; - bsnprintf(p, NI_MAXHOST, - "%d.%d.%d.%d", - addr & 0xff, - (addr >> 8) & 0xff, - (addr >> 16) & 0xff, - (addr >> 24) & 0xff); + addr = ntohl(addr); + bsnprintf(p, NI_MAXHOST, + "%d.%d.%d.%d", + (addr >> 24) & 0xff, + (addr >> 16) & 0xff, + (addr >> 8) & 0xff, + addr & 0xff); } if (ss->ss_family == PF_INET6) { @@ -231,13 +232,13 @@ ss_to_ptr(struct sockaddr_storage *ss) in_addr_t addr; addr = ((struct sockaddr_in *)ss)->sin_addr.s_addr; - - bsnprintf(buffer, sizeof (buffer), - "%d.%d.%d.%d.in-addr.arpa", - (addr >> 24) & 0xff, - (addr >> 16) & 0xff, - (addr >> 8) & 0xff, - addr & 0xff); + addr = ntohl(addr); + bsnprintf(buffer, sizeof (buffer), + "%d.%d.%d.%d.in-addr.arpa", + addr & 0xff, + (addr >> 8) & 0xff, + (addr >> 16) & 0xff, + (addr >> 24) & 0xff); break; } case AF_INET6: { |