finally move buildroot-ng to trunk
[openwrt/staging/wigyori.git] / package / busybox / patches / 300-netmsg.patch
1 # Copyright (C) 2006 OpenWrt.org
2 #
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
5 #
6 diff -ruN busybox-1.2.0-old/include/applets.h busybox-1.2.0-new/include/applets.h
7 --- busybox-1.2.0-old/include/applets.h 2006-07-31 10:47:56.000000000 +0200
8 +++ busybox-1.2.0-new/include/applets.h 2006-07-31 11:21:00.000000000 +0200
9 @@ -200,6 +200,7 @@
10 USE_MV(APPLET(mv, _BB_DIR_BIN, _BB_SUID_NEVER))
11 USE_NAMEIF(APPLET(nameif, _BB_DIR_SBIN, _BB_SUID_NEVER))
12 USE_NC(APPLET(nc, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
13 +USE_NETMSG(APPLET_NOUSAGE(netmsg, netmsg, _BB_DIR_BIN, _BB_SUID_ALWAYS))
14 USE_NETSTAT(APPLET(netstat, _BB_DIR_BIN, _BB_SUID_NEVER))
15 USE_NICE(APPLET(nice, _BB_DIR_BIN, _BB_SUID_NEVER))
16 USE_NOHUP(APPLET(nohup, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
17 diff -ruN busybox-1.2.0-old/networking/Config.in busybox-1.2.0-new/networking/Config.in
18 --- busybox-1.2.0-old/networking/Config.in 2006-07-01 00:42:02.000000000 +0200
19 +++ busybox-1.2.0-new/networking/Config.in 2006-07-31 11:18:01.000000000 +0200
20 @@ -445,6 +445,12 @@
21 help
22 A simple Unix utility which reads and writes data across network
23 connections.
24 +
25 +config CONFIG_NETMSG
26 + bool "netmsg"
27 + default n
28 + help
29 + simple program for sending udp broadcast messages
30
31 config CONFIG_NC_GAPING_SECURITY_HOLE
32 bool "gaping security hole"
33 diff -ruN busybox-1.2.0-old/networking/Makefile.in busybox-1.2.0-new/networking/Makefile.in
34 --- busybox-1.2.0-old/networking/Makefile.in 2006-07-01 00:42:02.000000000 +0200
35 +++ busybox-1.2.0-new/networking/Makefile.in 2006-07-31 11:18:01.000000000 +0200
36 @@ -30,6 +30,7 @@
37 NETWORKING-$(CONFIG_IPTUNNEL) += iptunnel.o
38 NETWORKING-$(CONFIG_NAMEIF) += nameif.o
39 NETWORKING-$(CONFIG_NC) += nc.o
40 +NETWORKING-$(CONFIG_NETMSG) += netmsg.o
41 NETWORKING-$(CONFIG_NETSTAT) += netstat.o
42 NETWORKING-$(CONFIG_NSLOOKUP) += nslookup.o
43 NETWORKING-$(CONFIG_PING) += ping.o
44 diff -ruN busybox-1.2.0-old/networking/netmsg.c busybox-1.2.0-new/networking/netmsg.c
45 --- busybox-1.2.0-old/networking/netmsg.c 1970-01-01 01:00:00.000000000 +0100
46 +++ busybox-1.2.0-new/networking/netmsg.c 2006-07-31 11:18:01.000000000 +0200
47 @@ -0,0 +1,63 @@
48 +/*
49 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
50 + *
51 + * This is free software, licensed under the GNU General Public License v2.
52 + */
53 +#include <sys/types.h>
54 +#include <sys/socket.h>
55 +#include <netinet/in.h>
56 +#include <netdb.h>
57 +#include <stdio.h>
58 +#include <stdlib.h>
59 +#include <string.h>
60 +#include "busybox.h"
61 +
62 +
63 +#ifndef CONFIG_NETMSG
64 +int main(int argc, char **argv)
65 +#else
66 +int netmsg_main(int argc, char **argv)
67 +#endif
68 +{
69 + int s, i;
70 + struct sockaddr_in addr;
71 + int optval = 1;
72 + unsigned char buf[1001];
73 +
74 + if (argc != 3) {
75 + fprintf(stderr, "usage: %s <ip> \"<message>\"\n", argv[0]);
76 + exit(1);
77 + }
78 +
79 + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
80 + perror("Opening socket");
81 + exit(1);
82 + }
83 +
84 + memset(&addr, 0, sizeof(addr));
85 + addr.sin_family = AF_INET;
86 + addr.sin_addr.s_addr = inet_addr(argv[1]);
87 + addr.sin_port = htons(0x1337);
88 +
89 + memset(buf, 0, 1001);
90 + buf[0] = 0xde;
91 + buf[1] = 0xad;
92 +
93 + strncpy(buf + 2, argv[2], 998);
94 +
95 + if (setsockopt (s, SOL_SOCKET, SO_BROADCAST, (caddr_t) &optval, sizeof (optval)) < 0) {
96 + perror("setsockopt()");
97 + goto fail;
98 + }
99 +
100 + if (sendto(s, buf, 1001, 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
101 + perror("sendto()");
102 + goto fail;
103 + }
104 +
105 + return 0;
106 +
107 +fail:
108 + close(s);
109 + exit(1);
110 +}