Hello All,
I'd like to propose a new applet, gethostbyname.
all this applet does is to get a host name and return the first ip address.
the reason for this applet is that I have a embedded boot image build
with busybox what queries me on boot for a hostname and runs a bin which
tries to connect to it for data.
as the image is build based on uclibc and the bin is statically compiled
glibc, there are some functions which doesn't work, gethostbyname is one
of them.
previously I've used nslookup and parsed the output but I encountered
two networks the other day that have different output which probably
depends on the dhcp server config.
my only way to get around it with minimal effort is to create small
applet for busybox that does that for me.
I'm using busybox 1.19.2 so this is a bit old but if this package will
be accepted, I'll modify it to latest version.
Thanks.
diff -Nupr busybox-1.19.2.orig/include/applets.src.h busybox-1.19.2/include/applets.src.h
--- busybox-1.19.2.orig/include/applets.src.h 2012-07-02 09:44:06.000000000 +0300
+++ busybox-1.19.2/include/applets.src.h 2012-07-02 09:54:38.000000000 +0300
@@ -178,6 +178,7 @@ IF_HEAD(APPLET_NOEXEC(head, head, BB_DIR
IF_HEXDUMP(APPLET_NOEXEC(hexdump, hexdump, BB_DIR_USR_BIN, BB_SUID_DROP, hexdump))
IF_HOSTID(APPLET_NOFORK(hostid, hostid, BB_DIR_USR_BIN, BB_SUID_DROP, hostid))
IF_HOSTNAME(APPLET(hostname, BB_DIR_BIN, BB_SUID_DROP))
+IF_GETHOSTBYNAME(APPLET(gethostbyname, BB_DIR_BIN, BB_SUID_DROP))
IF_HTTPD(APPLET(httpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
IF_HWCLOCK(APPLET(hwclock, BB_DIR_SBIN, BB_SUID_DROP))
IF_IFCONFIG(APPLET(ifconfig, BB_DIR_SBIN, BB_SUID_DROP))
diff -Nupr busybox-1.19.2.orig/networking/Config.src busybox-1.19.2/networking/Config.src
--- busybox-1.19.2.orig/networking/Config.src 2012-07-02 09:44:06.000000000 +0300
+++ busybox-1.19.2/networking/Config.src 2012-07-02 09:54:38.000000000 +0300
@@ -159,6 +159,12 @@ config HOSTNAME
help
Show or set the system's host name.
+config GETHOSTBYNAME
+ bool "gethostbyname"
+ default n
+ help
+ returns the ip of the given host or N/A if not found
+
config HTTPD
bool "httpd"
default y
diff -Nupr busybox-1.19.2.orig/networking/gethostbyname.c busybox-1.19.2/networking/gethostbyname.c
--- busybox-1.19.2.orig/networking/gethostbyname.c 1970-01-01 02:00:00.000000000 +0200
+++ busybox-1.19.2/networking/gethostbyname.c 2012-07-02 10:00:13.000000000 +0300
@@ -0,0 +1,37 @@
+/* vi: set sw=4 ts=4: */
+/* gethostbyname
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ *
+ *
+ */
+
+//usage:#define gethostbyname_trivial_usage
+//usage: "gethostbyname hostname\n"
+//usage:#define gethostbyname_full_usage "\n\n"
+//usage: "Query the nameserver for the IP address of the given HOST\n"
+//usage:
+
+#include "libbb.h"
+#include "inet_common.h"
+
+int gethostbyname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int gethostbyname_main(int argc, char **argv) {
+ struct hostent *tmp = 0;
+
+ if (argc < 2) {
+ bb_show_usage();
+ }
+
+ tmp = gethostbyname(argv[1]);
+
+ if (!tmp) {
+ printf("N/A\n");
+ return EXIT_SUCCESS;
+ }
+
+ if (tmp->h_addr_list[0]) {
+ printf("%s\n", inet_ntoa((struct in_addr) *((struct in_addr *) tmp->h_addr_list[0])));
+ }
+ return EXIT_SUCCESS;
+}
diff -Nupr busybox-1.19.2.orig/networking/Kbuild.src busybox-1.19.2/networking/Kbuild.src
--- busybox-1.19.2.orig/networking/Kbuild.src 2012-07-02 09:44:06.000000000 +0300
+++ busybox-1.19.2/networking/Kbuild.src 2012-07-02 09:54:38.000000000 +0300
@@ -17,6 +17,7 @@ lib-$(CONFIG_FTPD) += ftpd.o
lib-$(CONFIG_FTPGET) += ftpgetput.o
lib-$(CONFIG_FTPPUT) += ftpgetput.o
lib-$(CONFIG_HOSTNAME) += hostname.o
+lib-$(CONFIG_GETHOSTBYNAME) += gethostbyname.o
lib-$(CONFIG_HTTPD) += httpd.o
lib-$(CONFIG_IFCONFIG) += ifconfig.o interface.o
lib-$(CONFIG_IFENSLAVE) += ifenslave.o interface.o
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox