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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
$NetBSD: patch-ad,v 1.2 2002/10/08 14:29:37 abs Exp $
--- netcat.c.orig Tue Oct 8 13:24:18 2002
+++ netcat.c
@@ -151,6 +151,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;
@@ -333,6 +334,7 @@ HINF * gethostpoop (name, numeric)
struct in_addr iaddr;
register HINF * poop = NULL;
register int x;
+ int rc;
/* I really want to strangle the twit who dreamed up all these sockaddr and
hostent abstractions, and then forced them all to be incompatible with
@@ -361,9 +363,9 @@ HINF * gethostpoop (name, numeric)
bail ("gethostpoop fuxored");
strcpy (poop->name, unknown); /* preload it */
/* see wzv:workarounds.c for dg/ux return-a-struct inet_addr lossage */
- iaddr.s_addr = inet_addr (name);
+ rc = inet_aton(name, &iaddr);
- if (iaddr.s_addr == INADDR_NONE) { /* here's the great split: names... */
+ if (rc == 0) { /* here's the great split: names... */
if (numeric)
bail ("Can't parse %s as an IP address", name);
hostent = gethostbyname (name);
@@ -620,6 +622,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)
@@ -1314,10 +1323,6 @@ main (argc, argv)
USHORT curport = 0;
char * randports = NULL;
-#ifdef HAVE_BIND
-/* can *you* say "cc -yaddayadda netcat.c -lresolv -l44bsd" on SunLOSs? */
- res_init();
-#endif
/* I was in this barbershop quartet in Skokie IL ... */
/* round up the usual suspects, i.e. malloc up all the stuff we need */
lclend = (SAI *) Hmalloc (sizeof (SA));
@@ -1389,12 +1394,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;
@@ -1642,6 +1649,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\
|