1 | --- a/include/applets.h |
2 | +++ b/include/applets.h |
3 | @@ -278,6 +278,7 @@ IF_MT(APPLET(mt, _BB_DIR_BIN, _BB_SUID_D |
4 | IF_MV(APPLET(mv, _BB_DIR_BIN, _BB_SUID_DROP)) |
5 | IF_NAMEIF(APPLET(nameif, _BB_DIR_SBIN, _BB_SUID_DROP)) |
6 | IF_NC(APPLET(nc, _BB_DIR_USR_BIN, _BB_SUID_DROP)) |
7 | +IF_NETMSG(APPLET(netmsg, _BB_DIR_BIN, _BB_SUID_REQUIRE)) |
8 | IF_NETSTAT(APPLET(netstat, _BB_DIR_BIN, _BB_SUID_DROP)) |
9 | IF_NICE(APPLET(nice, _BB_DIR_BIN, _BB_SUID_DROP)) |
10 | IF_NMETER(APPLET(nmeter, _BB_DIR_USR_BIN, _BB_SUID_DROP)) |
11 | --- a/include/usage.h |
12 | +++ b/include/usage.h |
13 | @@ -3101,6 +3101,9 @@ |
14 | |
15 | #endif |
16 | |
17 | +#define netmsg_trivial_usage NOUSAGE_STR |
18 | +#define netmsg_full_usage "" |
19 | + |
20 | #define netstat_trivial_usage \ |
21 | "[-laentuwxr"IF_FEATURE_NETSTAT_WIDE("W")IF_FEATURE_NETSTAT_PRG("p")"]" |
22 | #define netstat_full_usage "\n\n" \ |
23 | --- a/networking/Config.in |
24 | +++ b/networking/Config.in |
25 | @@ -617,6 +617,12 @@ config NC |
26 | A simple Unix utility which reads and writes data across network |
27 | connections. |
28 | |
29 | +config NETMSG |
30 | + bool "netmsg" |
31 | + default n |
32 | + help |
33 | + simple program for sending udp broadcast messages |
34 | + |
35 | config NC_SERVER |
36 | bool "Netcat server options (-l)" |
37 | default n |
38 | --- a/networking/Kbuild |
39 | +++ b/networking/Kbuild |
40 | @@ -25,6 +25,7 @@ lib-$(CONFIG_IP) += ip.o |
41 | lib-$(CONFIG_IPCALC) += ipcalc.o |
42 | lib-$(CONFIG_NAMEIF) += nameif.o |
43 | lib-$(CONFIG_NC) += nc.o |
44 | +lib-$(CONFIG_NETMSG) += netmsg.o |
45 | lib-$(CONFIG_NETSTAT) += netstat.o |
46 | lib-$(CONFIG_NSLOOKUP) += nslookup.o |
47 | lib-$(CONFIG_PING) += ping.o |
48 | --- /dev/null |
49 | +++ b/networking/netmsg.c |
50 | @@ -0,0 +1,63 @@ |
51 | +/* |
52 | + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org> |
53 | + * |
54 | + * This is free software, licensed under the GNU General Public License v2. |
55 | + */ |
56 | +#include <sys/types.h> |
57 | +#include <sys/socket.h> |
58 | +#include <netinet/in.h> |
59 | +#include <netdb.h> |
60 | +#include <stdio.h> |
61 | +#include <stdlib.h> |
62 | +#include <string.h> |
63 | +#include "busybox.h" |
64 | + |
65 | + |
66 | +#ifndef CONFIG_NETMSG |
67 | +int main(int argc, char **argv) |
68 | +#else |
69 | +int netmsg_main(int argc, char **argv) |
70 | +#endif |
71 | +{ |
72 | + int s; |
73 | + struct sockaddr_in addr; |
74 | + int optval = 1; |
75 | + unsigned char buf[1001]; |
76 | + |
77 | + if (argc != 3) { |
78 | + fprintf(stderr, "usage: %s <ip> \"<message>\"\n", argv[0]); |
79 | + exit(1); |
80 | + } |
81 | + |
82 | + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
83 | + perror("Opening socket"); |
84 | + exit(1); |
85 | + } |
86 | + |
87 | + memset(&addr, 0, sizeof(addr)); |
88 | + addr.sin_family = AF_INET; |
89 | + addr.sin_addr.s_addr = inet_addr(argv[1]); |
90 | + addr.sin_port = htons(0x1337); |
91 | + |
92 | + memset(buf, 0, 1001); |
93 | + buf[0] = 0xde; |
94 | + buf[1] = 0xad; |
95 | + |
96 | + strncpy(buf + 2, argv[2], 998); |
97 | + |
98 | + if (setsockopt (s, SOL_SOCKET, SO_BROADCAST, (caddr_t) &optval, sizeof (optval)) < 0) { |
99 | + perror("setsockopt()"); |
100 | + goto fail; |
101 | + } |
102 | + |
103 | + if (sendto(s, buf, 1001, 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) { |
104 | + perror("sendto()"); |
105 | + goto fail; |
106 | + } |
107 | + |
108 | + return 0; |
109 | + |
110 | +fail: |
111 | + close(s); |
112 | + exit(1); |
113 | +} |
114 | |