From: Ted Lemon Date: Thu, 6 Mar 1997 06:55:06 +0000 (+0000) Subject: Options whose format is X now print as colon-seperated hex, so that pretty_print... X-Git-Tag: DHCP-970306~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=17f4dab73cadfb8dfcebdfbaf733c07a6a089dbf;p=thirdparty%2Fdhcp.git Options whose format is X now print as colon-seperated hex, so that pretty_print output can be parsed. do_packet() moved here from dispatch.c --- diff --git a/common/options.c b/common/options.c index 6d18ad5ef..39c7fb8b1 100644 --- a/common/options.c +++ b/common/options.c @@ -42,7 +42,7 @@ #ifndef lint static char copyright[] = -"$Id: options.c,v 1.22 1997/02/22 08:32:04 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: options.c,v 1.23 1997/03/06 06:55:06 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #define DHCP_OPTION_DATA @@ -413,7 +413,13 @@ char *pretty_print_option (code, data, len, emit_commas) char *op = optbuf; unsigned char *dp = data; struct in_addr foo; + char comma; + if (emit_commas) + comma = ','; + else + comma = ' '; + /* Figure out the size of the data. */ for (i = 0; dhcp_options [code].format [i]; i++) { if (!numhunk) { @@ -430,6 +436,13 @@ char *pretty_print_option (code, data, len, emit_commas) fmtbuf [i] = 0; numhunk = 0; break; + case 'X': + fmtbuf [i] = 'x'; + fmtbuf [i + 1] = 0; + hunksize++; + numhunk = 0; + comma = ':'; + break; case 't': fmtbuf [i] = 't'; fmtbuf [i + 1] = 0; @@ -524,6 +537,9 @@ char *pretty_print_option (code, data, len, emit_commas) case 'B': sprintf (op, "%d", *dp++); break; + case 'x': + sprintf (op, "%x", *dp++); + break; case 'f': strcpy (op, *dp++ ? "true" : "false"); break; @@ -531,15 +547,45 @@ char *pretty_print_option (code, data, len, emit_commas) warn ("Unexpected format code %c", fmtbuf [j]); } op += strlen (op); - if (j + 1 < numelem) + if (j + 1 < numelem && comma != ':') *op++ = ' '; } if (i + 1 < numhunk) { - if (emit_commas) - *op++ = ','; - *op++ = ' '; + *op++ = comma; } } return optbuf; } + +void do_packet (interface, packbuf, len, from_port, from, hfrom) + struct interface_info *interface; + unsigned char *packbuf; + int len; + unsigned short from_port; + struct iaddr from; + struct hardware *hfrom; +{ + struct packet tp; + struct dhcp_packet tdp; + + memcpy (&tdp, packbuf, len); + memset (&tp, 0, sizeof tp); + tp.raw = &tdp; + tp.packet_length = len; + tp.client_port = from_port; + tp.client_addr = from; + tp.interface = interface; + tp.haddr = hfrom; + + parse_options (&tp); + if (tp.options_valid && + tp.options [DHO_DHCP_MESSAGE_TYPE].data) + tp.packet_type = + tp.options [DHO_DHCP_MESSAGE_TYPE].data [0]; + if (tp.packet_type) + dhcp (&tp); + else if (tdp.op == BOOTREQUEST) + bootp (&tp); +} +