summaryrefslogtreecommitdiff
path: root/sbin/ping
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-07-23 02:30:23 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-07-23 02:30:23 +0000
commit044b0623deaa9b4d719bd49315d026fd9bf19a2e (patch)
tree05f44e9d153e07f94b94d7087355c1ba222f60db /sbin/ping
parent531304824736a0a4a97331ce4a0cf9370549c82c (diff)
open socket as soon as possible, and then revoke privs
Diffstat (limited to 'sbin/ping')
-rw-r--r--sbin/ping/ping.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index 6238501b403..e273b633881 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ping.c,v 1.4 1996/07/22 21:12:23 deraadt Exp $ */
+/* $OpenBSD: ping.c,v 1.5 1996/07/23 02:30:22 deraadt Exp $ */
/* $NetBSD: ping.c,v 1.20 1995/08/11 22:37:58 cgd Exp $ */
/*
@@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: ping.c,v 1.4 1996/07/22 21:12:23 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: ping.c,v 1.5 1996/07/23 02:30:22 deraadt Exp $";
#endif
#endif /* not lint */
@@ -182,7 +182,7 @@ main(argc, argv)
struct protoent *proto;
struct in_addr saddr;
register int i;
- int ch, fdmask, hold, packlen, preload;
+ int ch, fdmask, hold = 1, packlen, preload;
u_char *datap, *packet;
char *target, hnamebuf[MAXHOSTNAMELEN];
u_char ttl = MAXTTL, loop = 1, df = 0;
@@ -191,6 +191,14 @@ main(argc, argv)
char rspace[3 + 4 * NROUTES + 1]; /* record route space */
#endif
+ if (!(proto = getprotobyname("icmp")))
+ errx(1, "unknown protocol icmp");
+ if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0)
+ err(1, "socket");
+
+ /* revoke privs */
+ setuid(getuid());
+
preload = 0;
datap = &outpack[8 + sizeof(struct timeval)];
while ((ch = getopt(argc, argv, "DI:LRS:c:dfh:i:l:np:qrs:T:t:vw:")) != EOF)
@@ -324,12 +332,6 @@ main(argc, argv)
ident = getpid() & 0xFFFF;
- if (!(proto = getprotobyname("icmp")))
- errx(1, "unknown protocol icmp");
- if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0)
- err(1, "socket");
- hold = 1;
-
if (options & F_SADDR) {
if (IN_MULTICAST(ntohl(to->sin_addr.s_addr)))
moptions |= MULTICAST_IF;