*/
request->dict = dict_dhcpv4;
-#if 0
- /*
- * @todo - print hex packets here!
- */
if (DEBUG_ENABLED3) {
RDEBUG("proto_dhcpv4 decode packet");
fr_dhcpv4_print_hex(fr_log_fp, data, data_len);
}
-#endif
client = address->radclient;
return -1;
}
-#if 0
if (DEBUG_ENABLED3) {
RDEBUG("proto_dhcpv4 encode packet");
fr_dhcpv4_print_hex(fr_log_fp, buffer, data_len);
}
-#endif
return data_len;
}
fr_dict_autofree(dhcpv4_dict);
}
+
+static char const *short_header_names[] = {
+ "opcode",
+ "hwtype",
+ "hwaddrlen",
+ "hop_count",
+ "xid",
+ "seconds",
+ "flags",
+ "ciaddr",
+ "yiaddr",
+ "siaddr",
+ "giaddr",
+ "chaddr",
+ "server_hostname",
+ "boot_filename",
+};
+
+static void print_hex_data(uint8_t const *ptr, int attrlen, int depth)
+{
+ int i;
+ static char const tabs[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
+
+ for (i = 0; i < attrlen; i++) {
+ if ((i > 0) && ((i & 0x0f) == 0x00))
+ fprintf(fr_log_fp, "%.*s", depth, tabs);
+ fprintf(fr_log_fp, "%02x ", ptr[i]);
+ if ((i & 0x0f) == 0x0f) fprintf(fr_log_fp, "\n");
+ }
+ if ((i & 0x0f) != 0) fprintf(fr_log_fp, "\n");
+}
+
+/** Print a raw RADIUS packet as hex.
+ *
+ */
+void fr_dhcpv4_print_hex(FILE *fp, uint8_t const *packet, size_t packet_len)
+{
+ int i;
+ uint8_t const *attr, *end;
+
+ end = packet + packet_len;
+ attr = packet;
+
+ for (i = 0; i < 14; i++) {
+ fprintf(fp, "\t%s: ", short_header_names[i]);
+ print_hex_data(attr, dhcp_header_sizes[i], 2);
+ attr += dhcp_header_sizes[i];
+ }
+
+ while (attr < end) {
+ fprintf(fp, "\t\t");
+
+ fprintf(fp, "%02x %02x ", attr[0], attr[1]);
+
+ print_hex_data(attr + 2, attr[1], 3);
+
+ /*
+ * "End of option" option.
+ */
+ if (attr[0] == 255) break;
+
+ attr += attr[1] + 2;
+ }
+}
ssize_t fr_dhcpv4_encode(uint8_t *buffer, size_t buflen, int code, uint32_t xid, VALUE_PAIR *vps);
int fr_dhcpv4_init(void);
void fr_dhcpv4_free(void);
+void fr_dhcpv4_print_hex(FILE *fp, uint8_t const *packet, size_t packet_len);
/*
* decode.c