summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2024-08-21 15:00:26 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2024-08-21 15:00:26 +0000
commite1434f8d77b34090b98c44d17f9d8c14852b17dd (patch)
treedbd38df8ab3620b97be713e9d2b01a182272012e
parent946c4601784344904ffa39d2928dc2139ee0d298 (diff)
Get rid of inet_aton
OK deraadt
-rw-r--r--usr.sbin/traceroute/traceroute.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c
index 90b37cbe65a..46c7e5d3b6c 100644
--- a/usr.sbin/traceroute/traceroute.c
+++ b/usr.sbin/traceroute/traceroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: traceroute.c,v 1.169 2022/03/24 14:39:08 deraadt Exp $ */
+/* $OpenBSD: traceroute.c,v 1.170 2024/08/21 15:00:25 florian Exp $ */
/* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */
/*
@@ -303,7 +303,6 @@ main(int argc, char *argv[])
char hbuf[NI_MAXHOST];
struct addrinfo hints, *res;
- struct hostent *hp;
struct ip *ip = NULL;
struct iovec rcviov[2];
static u_char *rcvcmsgbuf;
@@ -449,14 +448,16 @@ main(int argc, char *argv[])
case 'g':
if (conf->lsrr >= MAX_LSRR)
errx(1, "too many gateways; max %d", MAX_LSRR);
- if (inet_aton(optarg, &conf->gateway[conf->lsrr]) ==
- 0) {
- hp = gethostbyname(optarg);
- if (hp == 0)
- errx(1, "unknown host %s", optarg);
- memcpy(&conf->gateway[conf->lsrr], hp->h_addr,
- hp->h_length);
- }
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+
+ if (getaddrinfo(optarg, NULL, &hints, &res) != 0)
+ errx(1, "unknown host %s", optarg);
+
+ conf->gateway[conf->lsrr] =
+ ((struct sockaddr_in *)res->ai_addr)->sin_addr;
+ freeaddrinfo(res);
+
if (++conf->lsrr == 1)
conf->lsrrlen = 4;
conf->lsrrlen += 4;
@@ -713,7 +714,8 @@ main(int argc, char *argv[])
if (conf->source) {
memset(&from4, 0, sizeof(from4));
from4.sin_family = AF_INET;
- if (inet_aton(conf->source, &from4.sin_addr) == 0)
+ if (inet_pton(AF_INET, conf->source, &from4.sin_addr)
+ != 1)
errx(1, "unknown host %s", conf->source);
ip->ip_src = from4.sin_addr;
if (ouid != 0 &&