fix busybox applet lookup (thanks, Stefan Weil)
[openwrt/svn-archive/archive.git] / openwrt / package / busybox / patches / 300-netmsg.patch
1 diff -Nur busybox-1.1.1/include/applets.h busybox-1.1.1-owrt/include/applets.h
2 --- busybox-1.1.1/include/applets.h 2006-04-01 18:26:21.000000000 +0200
3 +++ busybox-1.1.1-owrt/include/applets.h 2006-04-01 18:36:28.000000000 +0200
4 @@ -197,6 +197,7 @@
5 USE_MV(APPLET(mv, mv_main, _BB_DIR_BIN, _BB_SUID_NEVER))
6 USE_NAMEIF(APPLET(nameif, nameif_main, _BB_DIR_SBIN, _BB_SUID_NEVER))
7 USE_NC(APPLET(nc, nc_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
8 +USE_NETMSG(APPLET_NOUSAGE(netmsg, netmsg_main, _BB_DIR_BIN, _BB_SUID_ALWAYS))
9 USE_NETSTAT(APPLET(netstat, netstat_main, _BB_DIR_BIN, _BB_SUID_NEVER))
10 USE_NICE(APPLET(nice, nice_main, _BB_DIR_BIN, _BB_SUID_NEVER))
11 USE_NOHUP(APPLET(nohup, nohup_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
12 diff -Nur busybox-1.1.1/networking/Config.in busybox-1.1.1-owrt/networking/Config.in
13 --- busybox-1.1.1/networking/Config.in 2006-03-22 22:16:19.000000000 +0100
14 +++ busybox-1.1.1-owrt/networking/Config.in 2006-04-01 18:35:32.000000000 +0200
15 @@ -451,6 +451,12 @@
16 help
17 A simple Unix utility which reads and writes data across network
18 connections.
19 +
20 +config CONFIG_NETMSG
21 + bool "netmsg"
22 + default n
23 + help
24 + simple program for sending udp broadcast messages
25
26 config CONFIG_NC_GAPING_SECURITY_HOLE
27 bool "gaping security hole"
28 diff -Nur busybox-1.1.1/networking/Makefile.in busybox-1.1.1-owrt/networking/Makefile.in
29 --- busybox-1.1.1/networking/Makefile.in 2006-03-22 22:16:19.000000000 +0100
30 +++ busybox-1.1.1-owrt/networking/Makefile.in 2006-04-01 18:35:32.000000000 +0200
31 @@ -30,6 +30,7 @@
32 NETWORKING-$(CONFIG_IPTUNNEL) += iptunnel.o
33 NETWORKING-$(CONFIG_NAMEIF) += nameif.o
34 NETWORKING-$(CONFIG_NC) += nc.o
35 +NETWORKING-$(CONFIG_NETMSG) += netmsg.o
36 NETWORKING-$(CONFIG_NETSTAT) += netstat.o
37 NETWORKING-$(CONFIG_NSLOOKUP) += nslookup.o
38 NETWORKING-$(CONFIG_PING) += ping.o
39 diff -Nur busybox-1.1.1/networking/netmsg.c busybox-1.1.1-owrt/networking/netmsg.c
40 --- busybox-1.1.1/networking/netmsg.c 1970-01-01 01:00:00.000000000 +0100
41 +++ busybox-1.1.1-owrt/networking/netmsg.c 2006-04-01 18:35:32.000000000 +0200
42 @@ -0,0 +1,58 @@
43 +#include <sys/types.h>
44 +#include <sys/socket.h>
45 +#include <netinet/in.h>
46 +#include <netdb.h>
47 +#include <stdio.h>
48 +#include <stdlib.h>
49 +#include <string.h>
50 +#include "busybox.h"
51 +
52 +
53 +#ifndef CONFIG_NETMSG
54 +int main(int argc, char **argv)
55 +#else
56 +int netmsg_main(int argc, char **argv)
57 +#endif
58 +{
59 + int s, i;
60 + struct sockaddr_in addr;
61 + int optval = 1;
62 + unsigned char buf[1001];
63 +
64 + if (argc != 3) {
65 + fprintf(stderr, "usage: %s <ip> \"<message>\"\n", argv[0]);
66 + exit(1);
67 + }
68 +
69 + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
70 + perror("Opening socket");
71 + exit(1);
72 + }
73 +
74 + memset(&addr, 0, sizeof(addr));
75 + addr.sin_family = AF_INET;
76 + addr.sin_addr.s_addr = inet_addr(argv[1]);
77 + addr.sin_port = htons(0x1337);
78 +
79 + memset(buf, 0, 1001);
80 + buf[0] = 0xde;
81 + buf[1] = 0xad;
82 +
83 + strncpy(buf + 2, argv[2], 998);
84 +
85 + if (setsockopt (s, SOL_SOCKET, SO_BROADCAST, (caddr_t) &optval, sizeof (optval)) < 0) {
86 + perror("setsockopt()");
87 + goto fail;
88 + }
89 +
90 + if (sendto(s, buf, 1001, 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
91 + perror("sendto()");
92 + goto fail;
93 + }
94 +
95 + return 0;
96 +
97 +fail:
98 + close(s);
99 + exit(1);
100 +}