2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-30 22:05:23 +00:00

Fix debugging statements; add raw data dumper

This commit is contained in:
Ted Lemon
1996-02-29 18:32:57 +00:00
parent a3e52198fc
commit 0366d39ed5
2 changed files with 66 additions and 30 deletions

View File

@@ -75,26 +75,26 @@ void print_lease (lease)
struct tm *t;
char tbuf [32];
printf (" Lease %s",
debug (" Lease %s",
piaddr (lease -> ip_addr));
t = gmtime (&lease -> starts);
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
printf (" start %s", tbuf);
debug (" start %s", tbuf);
t = gmtime (&lease -> ends);
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
printf (" end %s", tbuf);
debug (" end %s", tbuf);
t = gmtime (&lease -> timestamp);
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
printf (" stamp %s\n", tbuf);
debug (" stamp %s", tbuf);
printf (" hardware addr = %s",
debug (" hardware addr = %s",
print_hw_addr (lease -> hardware_addr.htype,
lease -> hardware_addr.hlen,
lease -> hardware_addr.haddr));
printf (" host %s state %x\n",
debug (" host %s state %x",
lease -> host ? lease -> host -> name : "<none>",
lease -> state);
}
@@ -104,6 +104,7 @@ void dump_packet (tp)
{
struct dhcp_packet *tdp = tp -> raw;
debug ("packet length %d", tp -> packet_length);
debug ("op = %d htype = %d hlen = %d hops = %d",
tdp -> op, tdp -> htype, tdp -> hlen, tdp -> hops);
debug ("xid = %x secs = %d flags = %x",
@@ -119,19 +120,36 @@ void dump_packet (tp)
((unsigned char *)(tdp -> chaddr)) [3],
((unsigned char *)(tdp -> chaddr)) [4],
((unsigned char *)(tdp -> chaddr)) [5]);
debug ("filename = %s\n", tdp -> file);
debug ("server_name = %s\n", tdp -> sname);
debug ("filename = %s", tdp -> file);
debug ("server_name = %s", tdp -> sname);
if (tp -> options_valid) {
int i;
for (i = 0; i < 256; i++) {
if (tp -> options [i].data)
printf (" %s = %s\n",
debug (" %s = %s",
dhcp_options [i].name,
pretty_print_option
(i, tp -> options [i].data,
tp -> options [i].len));
}
}
debug ("");
}
void dump_raw (buf, len)
unsigned char *buf;
int len;
{
int i;
for (i = 0; i < len; i++) {
if ((i & 15) == 0)
fprintf (stderr, "\n%03x:", i);
else if ((i & 7) == 0)
fprintf (stderr, " ");
fprintf (stderr, " %02x", buf [i]);
}
fprintf (stderr, "\n");
}

36
print.c
View File

@@ -75,26 +75,26 @@ void print_lease (lease)
struct tm *t;
char tbuf [32];
printf (" Lease %s",
debug (" Lease %s",
piaddr (lease -> ip_addr));
t = gmtime (&lease -> starts);
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
printf (" start %s", tbuf);
debug (" start %s", tbuf);
t = gmtime (&lease -> ends);
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
printf (" end %s", tbuf);
debug (" end %s", tbuf);
t = gmtime (&lease -> timestamp);
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
printf (" stamp %s\n", tbuf);
debug (" stamp %s", tbuf);
printf (" hardware addr = %s",
debug (" hardware addr = %s",
print_hw_addr (lease -> hardware_addr.htype,
lease -> hardware_addr.hlen,
lease -> hardware_addr.haddr));
printf (" host %s state %x\n",
debug (" host %s state %x",
lease -> host ? lease -> host -> name : "<none>",
lease -> state);
}
@@ -104,6 +104,7 @@ void dump_packet (tp)
{
struct dhcp_packet *tdp = tp -> raw;
debug ("packet length %d", tp -> packet_length);
debug ("op = %d htype = %d hlen = %d hops = %d",
tdp -> op, tdp -> htype, tdp -> hlen, tdp -> hops);
debug ("xid = %x secs = %d flags = %x",
@@ -119,19 +120,36 @@ void dump_packet (tp)
((unsigned char *)(tdp -> chaddr)) [3],
((unsigned char *)(tdp -> chaddr)) [4],
((unsigned char *)(tdp -> chaddr)) [5]);
debug ("filename = %s\n", tdp -> file);
debug ("server_name = %s\n", tdp -> sname);
debug ("filename = %s", tdp -> file);
debug ("server_name = %s", tdp -> sname);
if (tp -> options_valid) {
int i;
for (i = 0; i < 256; i++) {
if (tp -> options [i].data)
printf (" %s = %s\n",
debug (" %s = %s",
dhcp_options [i].name,
pretty_print_option
(i, tp -> options [i].data,
tp -> options [i].len));
}
}
debug ("");
}
void dump_raw (buf, len)
unsigned char *buf;
int len;
{
int i;
for (i = 0; i < len; i++) {
if ((i & 15) == 0)
fprintf (stderr, "\n%03x:", i);
else if ((i & 7) == 0)
fprintf (stderr, " ");
fprintf (stderr, " %02x", buf [i]);
}
fprintf (stderr, "\n");
}