300-netmsg.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. --- a/include/applets.h
  2. +++ b/include/applets.h
  3. @@ -257,6 +257,7 @@ USE_MT(APPLET(mt, _BB_DIR_BIN, _BB_SUID_
  4. USE_MV(APPLET(mv, _BB_DIR_BIN, _BB_SUID_NEVER))
  5. USE_NAMEIF(APPLET(nameif, _BB_DIR_SBIN, _BB_SUID_NEVER))
  6. USE_NC(APPLET(nc, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
  7. +USE_NETMSG(APPLET(netmsg, _BB_DIR_BIN, _BB_SUID_ALWAYS))
  8. USE_NETSTAT(APPLET(netstat, _BB_DIR_BIN, _BB_SUID_NEVER))
  9. USE_NICE(APPLET(nice, _BB_DIR_BIN, _BB_SUID_NEVER))
  10. USE_NMETER(APPLET(nmeter, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
  11. --- a/include/usage.h
  12. +++ b/include/usage.h
  13. @@ -2815,6 +2815,9 @@
  14. #endif
  15. +#define netmsg_trivial_usage NOUSAGE_STR
  16. +#define netmsg_full_usage ""
  17. +
  18. #define netstat_trivial_usage \
  19. "[-laentuwxr"USE_FEATURE_NETSTAT_WIDE("W")"]"
  20. #define netstat_full_usage "\n\n" \
  21. --- a/networking/Config.in
  22. +++ b/networking/Config.in
  23. @@ -602,6 +602,12 @@ config NC
  24. A simple Unix utility which reads and writes data across network
  25. connections.
  26. +config NETMSG
  27. + bool "netmsg"
  28. + default n
  29. + help
  30. + simple program for sending udp broadcast messages
  31. +
  32. config NC_SERVER
  33. bool "Netcat server options (-l)"
  34. default n
  35. --- a/networking/Kbuild
  36. +++ b/networking/Kbuild
  37. @@ -24,6 +24,7 @@ lib-$(CONFIG_IP) += ip.o
  38. lib-$(CONFIG_IPCALC) += ipcalc.o
  39. lib-$(CONFIG_NAMEIF) += nameif.o
  40. lib-$(CONFIG_NC) += nc.o
  41. +lib-$(CONFIG_NETMSG) += netmsg.o
  42. lib-$(CONFIG_NETSTAT) += netstat.o
  43. lib-$(CONFIG_NSLOOKUP) += nslookup.o
  44. lib-$(CONFIG_PING) += ping.o
  45. --- /dev/null
  46. +++ b/networking/netmsg.c
  47. @@ -0,0 +1,63 @@
  48. +/*
  49. + * Copyright (C) 2006 Felix Fietkau <[email protected]>
  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;
  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. +}