mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-09-01 06:45:27 +00:00
Fix debugging statements; add raw data dumper
This commit is contained in:
@@ -75,26 +75,26 @@ void print_lease (lease)
|
|||||||
struct tm *t;
|
struct tm *t;
|
||||||
char tbuf [32];
|
char tbuf [32];
|
||||||
|
|
||||||
printf (" Lease %s",
|
debug (" Lease %s",
|
||||||
piaddr (lease -> ip_addr));
|
piaddr (lease -> ip_addr));
|
||||||
|
|
||||||
t = gmtime (&lease -> starts);
|
t = gmtime (&lease -> starts);
|
||||||
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
||||||
printf (" start %s", tbuf);
|
debug (" start %s", tbuf);
|
||||||
|
|
||||||
t = gmtime (&lease -> ends);
|
t = gmtime (&lease -> ends);
|
||||||
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
||||||
printf (" end %s", tbuf);
|
debug (" end %s", tbuf);
|
||||||
|
|
||||||
t = gmtime (&lease -> timestamp);
|
t = gmtime (&lease -> timestamp);
|
||||||
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
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,
|
print_hw_addr (lease -> hardware_addr.htype,
|
||||||
lease -> hardware_addr.hlen,
|
lease -> hardware_addr.hlen,
|
||||||
lease -> hardware_addr.haddr));
|
lease -> hardware_addr.haddr));
|
||||||
printf (" host %s state %x\n",
|
debug (" host %s state %x",
|
||||||
lease -> host ? lease -> host -> name : "<none>",
|
lease -> host ? lease -> host -> name : "<none>",
|
||||||
lease -> state);
|
lease -> state);
|
||||||
}
|
}
|
||||||
@@ -104,6 +104,7 @@ void dump_packet (tp)
|
|||||||
{
|
{
|
||||||
struct dhcp_packet *tdp = tp -> raw;
|
struct dhcp_packet *tdp = tp -> raw;
|
||||||
|
|
||||||
|
debug ("packet length %d", tp -> packet_length);
|
||||||
debug ("op = %d htype = %d hlen = %d hops = %d",
|
debug ("op = %d htype = %d hlen = %d hops = %d",
|
||||||
tdp -> op, tdp -> htype, tdp -> hlen, tdp -> hops);
|
tdp -> op, tdp -> htype, tdp -> hlen, tdp -> hops);
|
||||||
debug ("xid = %x secs = %d flags = %x",
|
debug ("xid = %x secs = %d flags = %x",
|
||||||
@@ -119,19 +120,36 @@ void dump_packet (tp)
|
|||||||
((unsigned char *)(tdp -> chaddr)) [3],
|
((unsigned char *)(tdp -> chaddr)) [3],
|
||||||
((unsigned char *)(tdp -> chaddr)) [4],
|
((unsigned char *)(tdp -> chaddr)) [4],
|
||||||
((unsigned char *)(tdp -> chaddr)) [5]);
|
((unsigned char *)(tdp -> chaddr)) [5]);
|
||||||
debug ("filename = %s\n", tdp -> file);
|
debug ("filename = %s", tdp -> file);
|
||||||
debug ("server_name = %s\n", tdp -> sname);
|
debug ("server_name = %s", tdp -> sname);
|
||||||
if (tp -> options_valid) {
|
if (tp -> options_valid) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (tp -> options [i].data)
|
if (tp -> options [i].data)
|
||||||
printf (" %s = %s\n",
|
debug (" %s = %s",
|
||||||
dhcp_options [i].name,
|
dhcp_options [i].name,
|
||||||
pretty_print_option
|
pretty_print_option
|
||||||
(i, tp -> options [i].data,
|
(i, tp -> options [i].data,
|
||||||
tp -> options [i].len));
|
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
36
print.c
@@ -75,26 +75,26 @@ void print_lease (lease)
|
|||||||
struct tm *t;
|
struct tm *t;
|
||||||
char tbuf [32];
|
char tbuf [32];
|
||||||
|
|
||||||
printf (" Lease %s",
|
debug (" Lease %s",
|
||||||
piaddr (lease -> ip_addr));
|
piaddr (lease -> ip_addr));
|
||||||
|
|
||||||
t = gmtime (&lease -> starts);
|
t = gmtime (&lease -> starts);
|
||||||
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
||||||
printf (" start %s", tbuf);
|
debug (" start %s", tbuf);
|
||||||
|
|
||||||
t = gmtime (&lease -> ends);
|
t = gmtime (&lease -> ends);
|
||||||
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
||||||
printf (" end %s", tbuf);
|
debug (" end %s", tbuf);
|
||||||
|
|
||||||
t = gmtime (&lease -> timestamp);
|
t = gmtime (&lease -> timestamp);
|
||||||
strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
|
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,
|
print_hw_addr (lease -> hardware_addr.htype,
|
||||||
lease -> hardware_addr.hlen,
|
lease -> hardware_addr.hlen,
|
||||||
lease -> hardware_addr.haddr));
|
lease -> hardware_addr.haddr));
|
||||||
printf (" host %s state %x\n",
|
debug (" host %s state %x",
|
||||||
lease -> host ? lease -> host -> name : "<none>",
|
lease -> host ? lease -> host -> name : "<none>",
|
||||||
lease -> state);
|
lease -> state);
|
||||||
}
|
}
|
||||||
@@ -104,6 +104,7 @@ void dump_packet (tp)
|
|||||||
{
|
{
|
||||||
struct dhcp_packet *tdp = tp -> raw;
|
struct dhcp_packet *tdp = tp -> raw;
|
||||||
|
|
||||||
|
debug ("packet length %d", tp -> packet_length);
|
||||||
debug ("op = %d htype = %d hlen = %d hops = %d",
|
debug ("op = %d htype = %d hlen = %d hops = %d",
|
||||||
tdp -> op, tdp -> htype, tdp -> hlen, tdp -> hops);
|
tdp -> op, tdp -> htype, tdp -> hlen, tdp -> hops);
|
||||||
debug ("xid = %x secs = %d flags = %x",
|
debug ("xid = %x secs = %d flags = %x",
|
||||||
@@ -119,19 +120,36 @@ void dump_packet (tp)
|
|||||||
((unsigned char *)(tdp -> chaddr)) [3],
|
((unsigned char *)(tdp -> chaddr)) [3],
|
||||||
((unsigned char *)(tdp -> chaddr)) [4],
|
((unsigned char *)(tdp -> chaddr)) [4],
|
||||||
((unsigned char *)(tdp -> chaddr)) [5]);
|
((unsigned char *)(tdp -> chaddr)) [5]);
|
||||||
debug ("filename = %s\n", tdp -> file);
|
debug ("filename = %s", tdp -> file);
|
||||||
debug ("server_name = %s\n", tdp -> sname);
|
debug ("server_name = %s", tdp -> sname);
|
||||||
if (tp -> options_valid) {
|
if (tp -> options_valid) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (tp -> options [i].data)
|
if (tp -> options [i].data)
|
||||||
printf (" %s = %s\n",
|
debug (" %s = %s",
|
||||||
dhcp_options [i].name,
|
dhcp_options [i].name,
|
||||||
pretty_print_option
|
pretty_print_option
|
||||||
(i, tp -> options [i].data,
|
(i, tp -> options [i].data,
|
||||||
tp -> options [i].len));
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user