210-add_netmsg_util.patch 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. --- a/include/applets.src.h
  2. +++ b/include/applets.src.h
  3. @@ -229,6 +229,7 @@ IF_MT(APPLET(mt, BB_DIR_BIN, BB_SUID_DRO
  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_NOHUP(APPLET(nohup, BB_DIR_USR_BIN, BB_SUID_DROP))
  11. --- a/networking/Config.src
  12. +++ b/networking/Config.src
  13. @@ -639,6 +639,12 @@ config FEATURE_IPCALC_LONG_OPTIONS
  14. help
  15. Support long options for the ipcalc applet.
  16. +config NETMSG
  17. + bool "netmsg"
  18. + default n
  19. + help
  20. + simple program for sending udp broadcast messages
  21. +
  22. config NETSTAT
  23. bool "netstat"
  24. default y
  25. --- a/networking/Kbuild.src
  26. +++ b/networking/Kbuild.src
  27. @@ -27,6 +27,7 @@ lib-$(CONFIG_IP) += ip.o
  28. lib-$(CONFIG_IPCALC) += ipcalc.o
  29. lib-$(CONFIG_NAMEIF) += nameif.o
  30. lib-$(CONFIG_NC) += nc.o
  31. +lib-$(CONFIG_NETMSG) += netmsg.o
  32. lib-$(CONFIG_NETSTAT) += netstat.o
  33. lib-$(CONFIG_NSLOOKUP) += nslookup.o
  34. lib-$(CONFIG_NTPD) += ntpd.o
  35. --- /dev/null
  36. +++ b/networking/netmsg.c
  37. @@ -0,0 +1,65 @@
  38. +/*
  39. + * Copyright (C) 2006 Felix Fietkau <nbd@nbd.name>
  40. + *
  41. + * This is free software, licensed under the GNU General Public License v2.
  42. + */
  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. +//usage:#define netmsg_trivial_usage NOUSAGE_STR
  53. +//usage:#define netmsg_full_usage ""
  54. +
  55. +#ifndef CONFIG_NETMSG
  56. +int main(int argc, char **argv)
  57. +#else
  58. +int netmsg_main(int argc, char **argv)
  59. +#endif
  60. +{
  61. + int s;
  62. + struct sockaddr_in addr;
  63. + int optval = 1;
  64. + unsigned char buf[1001];
  65. +
  66. + if (argc != 3) {
  67. + fprintf(stderr, "usage: %s <ip> \"<message>\"\n", argv[0]);
  68. + exit(1);
  69. + }
  70. +
  71. + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
  72. + perror("Opening socket");
  73. + exit(1);
  74. + }
  75. +
  76. + memset(&addr, 0, sizeof(addr));
  77. + addr.sin_family = AF_INET;
  78. + addr.sin_addr.s_addr = inet_addr(argv[1]);
  79. + addr.sin_port = htons(0x1337);
  80. +
  81. + memset(buf, 0, 1001);
  82. + buf[0] = 0xde;
  83. + buf[1] = 0xad;
  84. +
  85. + strncpy(buf + 2, argv[2], 998);
  86. +
  87. + if (setsockopt (s, SOL_SOCKET, SO_BROADCAST, (caddr_t) &optval, sizeof (optval)) < 0) {
  88. + perror("setsockopt()");
  89. + goto fail;
  90. + }
  91. +
  92. + if (sendto(s, buf, 1001, 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  93. + perror("sendto()");
  94. + goto fail;
  95. + }
  96. +
  97. + return 0;
  98. +
  99. +fail:
  100. + close(s);
  101. + exit(1);
  102. +}