aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/script.c
diff options
context:
space:
mode:
authorGravatar Glenn L McGrath <bug1@ihug.co.nz>2002-12-08 22:17:54 +0000
committerGravatar Glenn L McGrath <bug1@ihug.co.nz>2002-12-08 22:17:54 +0000
commit6b5bd0e5abbfb6b3b925dfd8452c72589569981b (patch)
tree19011ddf9f89ae7b4f9245154520e0605984c6e7 /networking/udhcp/script.c
parentc4698b36682b0bccae2fa1f70460aacaef306313 (diff)
downloadbusybox-6b5bd0e5abbfb6b3b925dfd8452c72589569981b.tar.gz
busybox-6b5bd0e5abbfb6b3b925dfd8452c72589569981b.tar.bz2
Support using ip in udhcpc scripts.
Slightly modified version of patch by Bastian Blank
Diffstat (limited to 'networking/udhcp/script.c')
-rw-r--r--networking/udhcp/script.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 4ce23aafc..1c6f1bd33 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -37,6 +37,8 @@
#include "options.h"
#include "debug.h"
+#include "config.h"
+
/* get a rough idea of how long an option will be (rounding up...) */
static int max_option_length[] = {
[OPTION_IP] = sizeof("255.255.255.255 "),
@@ -62,6 +64,37 @@ static int sprintip(char *dest, char *pre, unsigned char *ip) {
return sprintf(dest, "%s%d.%d.%d.%d ", pre, ip[0], ip[1], ip[2], ip[3]);
}
+#ifdef CONFIG_FEATURE_UDHCPC_IP
+/* convert a netmask (255.255.255.0) into the length (24) */
+static int inet_ntom (const char *src, short *dst)
+{
+ in_addr_t mask, num;
+
+ mask = ntohl(*(unsigned int *)src);
+
+ for (num = mask; num & 1; num >>= 1);
+
+ if (num != 0 && mask != 0)
+ {
+ for (num = ~mask; num & 1; num >>= 1);
+ if (num)
+ return 0;
+ }
+
+ for (num = 0; mask; mask <<= 1)
+ num++;
+
+ *dst = num;
+
+ return 1;
+}
+
+static int sprintprefix(char *dest, char *pre, unsigned char *ip) {
+ short sdest = 0;
+ inet_ntom(ip, &sdest);
+ return sprintf(dest, "%s%hd ", pre, sdest);
+}
+#endif
/* Fill dest with the text of option 'option'. */
static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p)
@@ -84,9 +117,20 @@ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *
*(dest++) = '/';
option += 4;
optlen = 4;
+#ifndef CONFIG_FEATURE_UDHCPC_IP
case OPTION_IP: /* Works regardless of host byte order. */
+#endif
dest += sprintip(dest, "", option);
break;
+#ifdef CONFIG_FEATURE_UDHCPC_IP
+ case OPTION_IP: /* Works regardless of host byte order. */
+ if (type_p->flags & OPTION_PREFIX) {
+ dest += sprintprefix(dest, "", option);
+ } else {
+ dest += sprintip(dest, "", option);
+ }
+ break;
+#endif
case OPTION_BOOLEAN:
dest += sprintf(dest, *option ? "yes " : "no ");
break;