busybox: refresh patches
[librecmc/librecmc.git] / package / busybox / patches / 300-netmsg.patch
1 --- a/include/applets.src.h
2 +++ b/include/applets.src.h
3 @@ -256,6 +256,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.src.h
12 +++ b/include/usage.src.h
13 @@ -1,3 +1,4 @@
14 +
15  /* vi: set sw=8 ts=8: */
16  /*
17   * This file suffers from chronically incorrect tabification
18 @@ -2706,6 +2707,9 @@ INSERT
19         " or\n" \
20         "$ nameif -c /etc/my_mactab_file\n" \
21  
22 +#define netmsg_trivial_usage NOUSAGE_STR
23 +#define netmsg_full_usage ""
24 +
25  #define nmeter_trivial_usage \
26         "format_string"
27  #define nmeter_full_usage "\n\n" \
28 --- a/networking/Config.src
29 +++ b/networking/Config.src
30 @@ -640,6 +640,12 @@ config FEATURE_NAMEIF_EXTENDED
31             new_interface_name  mac=00:80:C8:38:91:B5
32             new_interface_name  00:80:C8:38:91:B5
33  
34 +config NETMSG
35 +       bool "netmsg"
36 +       default n
37 +       help
38 +         simple program for sending udp broadcast messages
39 +
40  config NETSTAT
41         bool "netstat"
42         default y
43 --- a/networking/Kbuild.src
44 +++ b/networking/Kbuild.src
45 @@ -27,6 +27,7 @@ lib-$(CONFIG_IP)           += ip.o
46  lib-$(CONFIG_IPCALC)       += ipcalc.o
47  lib-$(CONFIG_NAMEIF)       += nameif.o
48  lib-$(CONFIG_NC)           += nc.o
49 +lib-$(CONFIG_NETMSG)       += netmsg.o
50  lib-$(CONFIG_NETSTAT)      += netstat.o
51  lib-$(CONFIG_NSLOOKUP)     += nslookup.o
52  lib-$(CONFIG_NTPD)         += ntpd.o
53 --- /dev/null
54 +++ b/networking/netmsg.c
55 @@ -0,0 +1,63 @@
56 +/*
57 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
58 + *
59 + * This is free software, licensed under the GNU General Public License v2.
60 + */
61 +#include <sys/types.h>
62 +#include <sys/socket.h>
63 +#include <netinet/in.h>
64 +#include <netdb.h>
65 +#include <stdio.h>
66 +#include <stdlib.h>
67 +#include <string.h>
68 +#include "busybox.h"
69 +
70 +
71 +#ifndef CONFIG_NETMSG
72 +int main(int argc, char **argv)
73 +#else
74 +int netmsg_main(int argc, char **argv)
75 +#endif
76 +{
77 +       int s;
78 +       struct sockaddr_in addr;
79 +       int optval = 1;
80 +       unsigned char buf[1001];
81 +
82 +       if (argc != 3) {
83 +               fprintf(stderr, "usage: %s <ip> \"<message>\"\n", argv[0]);
84 +               exit(1);
85 +       }
86 +
87 +       if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
88 +               perror("Opening socket");
89 +               exit(1);
90 +       }
91 +
92 +       memset(&addr, 0, sizeof(addr));
93 +       addr.sin_family = AF_INET;
94 +       addr.sin_addr.s_addr = inet_addr(argv[1]);
95 +       addr.sin_port = htons(0x1337);
96 +
97 +       memset(buf, 0, 1001);
98 +       buf[0] = 0xde;
99 +       buf[1] = 0xad;
100 +
101 +       strncpy(buf + 2, argv[2], 998);
102 +
103 +       if (setsockopt (s, SOL_SOCKET, SO_BROADCAST, (caddr_t) &optval, sizeof (optval)) < 0) {
104 +               perror("setsockopt()");
105 +               goto fail;
106 +       }
107 +
108 +       if (sendto(s, buf, 1001, 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
109 +               perror("sendto()");
110 +               goto fail;
111 +       }
112 +
113 +       return 0;
114 +       
115 +fail:
116 +       close(s);
117 +       exit(1);
118 +}