Package: netcat / 1.10-41

udp-broadcast.patch Patch series | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Summary: Allow use of broadcast addresses.
Contributor: NetBSD
Merged by: Decklin Foster <decklin@red-bean.com>

Index: netcat-1.10/netcat.c
===================================================================
--- netcat-1.10.orig/netcat.c
+++ netcat-1.10/netcat.c
@@ -166,6 +166,7 @@ unsigned char * stage = NULL;	/* hexdump
 
 /* global cmd flags: */
 USHORT o_alla = 0;
+USHORT o_allowbroad = 0;
 unsigned int o_interval = 0;
 USHORT o_listen = 0;
 USHORT o_nflag = 0;
@@ -641,6 +642,13 @@ newskt:
   rr = setsockopt (nnetfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof (x));
   if (rr == -1)
     holler ("nnetfd reuseaddr failed");		/* ??? */
+#ifdef SO_BROADCAST
+  if (o_allowbroad) {
+    rr = setsockopt (nnetfd, SOL_SOCKET, SO_BROADCAST, &x, sizeof (x));
+    if (rr == -1)
+       holler ("nnetfd reuseaddr failed");         /* ??? */
+  }
+#endif
 #ifdef SO_REUSEPORT	/* doesnt exist everywhere... */
   rr = setsockopt (nnetfd, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
   if (rr == -1)
@@ -1431,12 +1439,14 @@ main (argc, argv)
 
 /* If your shitbox doesn't have getopt, step into the nineties already. */
 /* optarg, optind = next-argv-component [i.e. flag arg]; optopt = last-char */
-  while ((x = getopt (argc, argv, "ae:g:G:hi:lno:p:rs:tuvw:z")) != EOF) {
+  while ((x = getopt (argc, argv, "abe:g:G:hi:lno:p:rs:tuvw:z")) != EOF) {
 /* Debug (("in go: x now %c, optarg %x optind %d", x, optarg, optind)) */
     switch (x) {
       case 'a':
 	bail ("all-A-records NIY");
 	o_alla++; break;
+      case 'b':
+	o_allowbroad++; break;
 #ifdef GAPING_SECURITY_HOLE
       case 'e':				/* prog to exec */
 	pr00gie = optarg;
@@ -1692,6 +1702,7 @@ options:");
 	-e prog			program to exec after connect [dangerous!!]");
 #endif
   holler ("\
+	-b			allow broadcasts\n\
 	-g gateway		source-routing hop point[s], up to 8\n\
 	-G num			source-routing pointer: 4, 8, 12, ...\n\
 	-h			this cruft\n\