summaryrefslogtreecommitdiff
path: root/net/hping/patches/patch-aa
blob: 5f459e5c127aacbf35dabe4f2ad8d55b5e8ac33c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$NetBSD: patch-aa,v 1.2 2003/09/25 22:12:15 recht Exp $

--- main.c.orig	2003-07-31 12:06:55.000000000 +0200
+++ main.c
@@ -166,6 +166,17 @@ int main(int argc, char **argv)
 	char setflags[1024] = {'\0'};
 	int c, hdr_size;
 
+	/* open raw socket */
+	sockraw = open_sockraw();
+	if (sockraw == -1) {
+		printf("[main] can't open raw socket\n");
+		exit(1);
+	}
+	if (getuid() && setuid(getuid()) == -1) {
+		printf("[main] can't drop privs\n");
+		exit(1);
+	}
+
 	if (parse_options(argc, argv) == -1) {
 		printf("hping2: missing host argument\n"
 			"Try `hping2 --help' for more information.\n");
@@ -206,13 +217,6 @@ int main(int argc, char **argv)
 			ifname, ifstraddr, h_if_mtu);
 	}
 
-	/* open raw socket */
-	sockraw = open_sockraw();
-	if (sockraw == -1) {
-		printf("[main] can't open raw socket\n");
-		exit(1);
-	}
-
 	/* set SO_BROADCAST option */
 	socket_broadcast(sockraw);
 	/* set SO_IPHDRINCL option */