summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/dhcpd/parse.c120
-rw-r--r--usr.sbin/dhcpd/print.c186
2 files changed, 144 insertions, 162 deletions
diff --git a/usr.sbin/dhcpd/parse.c b/usr.sbin/dhcpd/parse.c
index 853c6ae8ff0..4d26936c8cc 100644
--- a/usr.sbin/dhcpd/parse.c
+++ b/usr.sbin/dhcpd/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.3 2004/04/14 01:27:49 henning Exp $ */
+/* $OpenBSD: parse.c,v 1.4 2004/04/15 22:22:21 hshoexer Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -43,7 +43,8 @@
#include "dhcpd.h"
#include "dhctoken.h"
-/* Skip to the semicolon ending the current statement. If we encounter
+/*
+ * Skip to the semicolon ending the current statement. If we encounter
* braces, the matching closing brace terminates the statement. If we
* encounter a right brace but haven't encountered a left brace, return
* leaving the brace in the token buffer for the caller. If we see a
@@ -60,9 +61,9 @@
void
skip_to_semi(FILE *cfile)
{
- int token;
- char *val;
- int brace_count = 0;
+ int token;
+ char *val;
+ int brace_count = 0;
do {
token = peek_token(&val, cfile);
@@ -95,8 +96,8 @@ skip_to_semi(FILE *cfile)
int
parse_semi(FILE *cfile)
{
- int token;
- char *val;
+ int token;
+ char *val;
token = next_token(&val, cfile);
if (token != SEMI) {
@@ -113,9 +114,9 @@ parse_semi(FILE *cfile)
char *
parse_string(FILE *cfile)
{
- char *val;
- int token;
- char *s;
+ char *val;
+ int token;
+ char *s;
token = next_token(&val, cfile);
if (token != STRING) {
@@ -139,12 +140,12 @@ parse_string(FILE *cfile)
char *
parse_host_name(FILE *cfile)
{
- char *val;
- int token;
- int len = 0;
- char *s;
- char *t;
- pair c = NULL;
+ char *val;
+ int token;
+ int len = 0;
+ char *s;
+ char *t;
+ pair c = NULL;
/* Read a dotted hostname... */
do {
@@ -159,7 +160,7 @@ parse_host_name(FILE *cfile)
if (!(s = malloc(strlen(val) + 1)))
error("can't allocate temp space for hostname.");
strlcpy(s, val, strlen(val) + 1);
- c = cons((caddr_t)s, c);
+ c = cons((caddr_t) s, c);
len += strlen(s) + 1;
/*
* Look for a dot; if it's there, keep going, otherwise
@@ -176,8 +177,8 @@ parse_host_name(FILE *cfile)
t = s + len;
*--t = '\0';
while (c) {
- pair cdr = c->cdr;
- int l = strlen((char *)c->car);
+ pair cdr = c->cdr;
+ int l = strlen((char *)c->car);
t -= l;
memcpy(t, (char *)c->car, l);
/* Free up temp space. */
@@ -207,10 +208,10 @@ parse_ip_addr(FILE *cfile, struct iaddr *addr)
void
parse_hardware_param(FILE *cfile, struct hardware *hardware)
{
- char *val;
- int token;
- int hlen;
- unsigned char *t;
+ char *val;
+ int token;
+ int hlen;
+ unsigned char *t;
token = next_token(&val, cfile);
switch (token) {
@@ -247,8 +248,8 @@ parse_hardware_param(FILE *cfile, struct hardware *hardware)
parse_warn("hardware address too long");
} else {
hardware->hlen = hlen;
- memcpy((unsigned char *)&hardware->haddr[0],
- t, hardware->hlen);
+ memcpy((unsigned char *)&hardware->haddr[0], t,
+ hardware->hlen);
if (hlen < sizeof(hardware->haddr))
memset(&hardware->haddr[hlen], 0,
sizeof(hardware->haddr) - hlen);
@@ -268,8 +269,8 @@ parse_hardware_param(FILE *cfile, struct hardware *hardware)
void
parse_lease_time(FILE *cfile, time_t *timep)
{
- char *val;
- int token;
+ char *val;
+ int token;
token = next_token(&val, cfile);
if (token != NUMBER) {
@@ -279,7 +280,7 @@ parse_lease_time(FILE *cfile, time_t *timep)
}
convert_num((unsigned char *)timep, val, 10, 32);
/* Unswap the number - convert_num returns stuff in NBO. */
- *timep = ntohl(*timep); /* XXX */
+ *timep = ntohl(*timep); /* XXX */
parse_semi(cfile);
}
@@ -296,12 +297,12 @@ unsigned char *
parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
int separator, int base, int size)
{
- char *val;
- int token;
- unsigned char *bufp = buf, *s = NULL;
- char *t;
- int count = 0;
- pair c = NULL;
+ char *val;
+ int token;
+ unsigned char *bufp = buf, *s = NULL;
+ char *t;
+ int count = 0;
+ pair c = NULL;
if (!bufp && *max) {
bufp = malloc(*max * size / 8);
@@ -331,7 +332,6 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
parse_warn("unexpected end of file");
break;
}
-
/* Allow NUMBER_OR_NAME if base is 16. */
if (token != NUMBER &&
(base != 16 || token != NUMBER_OR_NAME)) {
@@ -364,7 +364,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
*max = count;
}
while (c) {
- pair cdr = c->cdr;
+ pair cdr = c->cdr;
convert_num(s, (char *)c->car, base, size);
s -= size / 8;
/* Free up temp space. */
@@ -378,17 +378,16 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
void
convert_num(unsigned char *buf, char *str, int base, int size)
{
- char *ptr = str;
- int negative = 0;
- u_int32_t val = 0;
- int tval;
- int max;
+ char *ptr = str;
+ int negative = 0;
+ u_int32_t val = 0;
+ int tval;
+ int max;
if (*ptr == '-') {
negative = 1;
ptr++;
}
-
/* If base wasn't specified, figure it out from the data. */
if (!base) {
if (ptr[0] == '0') {
@@ -403,7 +402,6 @@ convert_num(unsigned char *buf, char *str, int base, int size)
} else
base = 10;
}
-
do {
tval = *ptr++;
/* XXX assumes ASCII... */
@@ -445,7 +443,6 @@ convert_num(unsigned char *buf, char *str, int base, int size)
break;
}
}
-
if (negative)
switch (size) {
case 8:
@@ -487,14 +484,14 @@ convert_num(unsigned char *buf, char *str, int base, int size)
* clock.
*/
time_t
-parse_date(FILE *cfile)
+parse_date(FILE * cfile)
{
- struct tm tm;
- int guess;
- char *val;
- int token;
- static int months[11] = { 31, 59, 90, 120, 151, 181,
- 212, 243, 273, 304, 334 };
+ struct tm tm;
+ int guess;
+ char *val;
+ int token;
+ static int months[11] = {31, 59, 90, 120, 151, 181,
+ 212, 243, 273, 304, 334};
/* Day of week... */
token = next_token(&val, cfile);
@@ -526,7 +523,6 @@ parse_date(FILE *cfile)
skip_to_semi(cfile);
return (NULL);
}
-
/* Month... */
token = next_token(&val, cfile);
if (token != NUMBER) {
@@ -545,7 +541,6 @@ parse_date(FILE *cfile)
skip_to_semi(cfile);
return (NULL);
}
-
/* Month... */
token = next_token(&val, cfile);
if (token != NUMBER) {
@@ -574,7 +569,6 @@ parse_date(FILE *cfile)
skip_to_semi(cfile);
return (NULL);
}
-
/* Minute... */
token = next_token(&val, cfile);
if (token != NUMBER) {
@@ -593,7 +587,6 @@ parse_date(FILE *cfile)
skip_to_semi(cfile);
return (NULL);
}
-
/* Minute... */
token = next_token(&val, cfile);
if (token != NUMBER) {
@@ -615,18 +608,15 @@ parse_date(FILE *cfile)
skip_to_semi(cfile);
return (NULL);
}
-
/* Guess the time value... */
guess = ((((((365 * (tm.tm_year - 70) + /* Days in years since '70 */
- (tm.tm_year - 69) / 4 + /* Leap days since '70 */
- (tm.tm_mon /* Days in months this year */
- ? months[tm.tm_mon - 1]
- : 0) +
- (tm.tm_mon > 1 && /* Leap day this year */
- !((tm.tm_year - 72) & 3)) +
- tm.tm_mday - 1) * 24) + /* Day of month */
- tm.tm_hour) * 60) +
- tm.tm_min) * 60) + tm.tm_sec;
+ (tm.tm_year - 69) / 4 + /* Leap days since '70 */
+ (tm.tm_mon /* Days in months this year */
+ ? months[tm.tm_mon - 1] : 0) +
+ (tm.tm_mon > 1 && /* Leap day this year */
+ !((tm.tm_year - 72) & 3)) +
+ tm.tm_mday - 1) * 24) + /* Day of month */
+ tm.tm_hour) * 60) + tm.tm_min) * 60) + tm.tm_sec;
/*
* This guess could be wrong because of leap seconds or other
diff --git a/usr.sbin/dhcpd/print.c b/usr.sbin/dhcpd/print.c
index 155d4c6a688..9ac209e2280 100644
--- a/usr.sbin/dhcpd/print.c
+++ b/usr.sbin/dhcpd/print.c
@@ -1,6 +1,6 @@
-/* print.c
+/* $Id: print.c,v 1.3 2004/04/15 22:22:21 hshoexer Exp $ */
- Turn data structures into printable text. */
+/* Turn data structures into printable text. */
/*
* Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
@@ -42,157 +42,149 @@
#include "dhcpd.h"
-char *print_hw_addr (htype, hlen, data)
- int htype;
- int hlen;
- unsigned char *data;
+char *
+print_hw_addr(int htype, int hlen, unsigned char *data)
{
- static char habuf [49];
- char *s;
- int i;
+ static char habuf[49];
+ char *s;
+ int i;
if (htype == 0 || hlen == 0) {
goto bad;
} else {
- int slen = sizeof(habuf);
+ int slen = sizeof(habuf);
s = habuf;
for (i = 0; i < hlen; i++) {
- int j;
- j = snprintf (s, slen, "%02x", data [i]);
+ int j;
+ j = snprintf(s, slen, "%02x", data[i]);
if (j <= 0)
goto bad;
- s += strlen (s);
+ s += strlen(s);
slen -= (strlen(s) + 1);
*s++ = ':';
}
*--s = 0;
}
return habuf;
- bad:
- strlcpy (habuf, "<null>", sizeof habuf);
+bad:
+ strlcpy(habuf, "<null>", sizeof habuf);
return habuf;
}
-void print_lease (lease)
- struct lease *lease;
+void
+print_lease(struct lease *lease)
{
- struct tm *t;
- char tbuf [32];
-
- debug (" Lease %s",
- piaddr (lease -> ip_addr));
-
- t = gmtime (&lease -> starts);
- strftime (tbuf, sizeof tbuf, "%Y/%m/%d %H:%M:%S", t);
- debug (" start %s", tbuf);
-
- t = gmtime (&lease -> ends);
- strftime (tbuf, sizeof tbuf, "%Y/%m/%d %H:%M:%S", t);
- debug (" end %s", tbuf);
-
- t = gmtime (&lease -> timestamp);
- strftime (tbuf, sizeof tbuf, "%Y/%m/%d %H:%M:%S", t);
- debug (" stamp %s", tbuf);
-
- debug (" hardware addr = %s",
- print_hw_addr (lease -> hardware_addr.htype,
- lease -> hardware_addr.hlen,
- lease -> hardware_addr.haddr));
- debug (" host %s ",
- lease -> host ? lease -> host -> name : "<none>");
+ struct tm *t;
+ char tbuf[32];
+
+ debug(" Lease %s", piaddr(lease->ip_addr));
+
+ t = gmtime(&lease->starts);
+ strftime(tbuf, sizeof tbuf, "%Y/%m/%d %H:%M:%S", t);
+ debug(" start %s", tbuf);
+
+ t = gmtime(&lease->ends);
+ strftime(tbuf, sizeof tbuf, "%Y/%m/%d %H:%M:%S", t);
+ debug(" end %s", tbuf);
+
+ t = gmtime(&lease->timestamp);
+ strftime(tbuf, sizeof tbuf, "%Y/%m/%d %H:%M:%S", t);
+ debug(" stamp %s", tbuf);
+
+ debug(" hardware addr = %s",
+ print_hw_addr(lease->hardware_addr.htype,
+ lease->hardware_addr.hlen, lease->hardware_addr.haddr));
+ debug(" host %s ", lease->host ? lease->host->name : "<none>");
}
-void dump_packet (tp)
- struct packet *tp;
+void
+dump_packet(struct 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",
- tdp -> xid, tdp -> secs, tdp -> flags);
- debug ("ciaddr = %s", inet_ntoa (tdp -> ciaddr));
- debug ("yiaddr = %s", inet_ntoa (tdp -> yiaddr));
- debug ("siaddr = %s", inet_ntoa (tdp -> siaddr));
- debug ("giaddr = %s", inet_ntoa (tdp -> giaddr));
- debug ("chaddr = %02x:%02x:%02x:%02x:%02x:%02x",
- ((unsigned char *)(tdp -> chaddr)) [0],
- ((unsigned char *)(tdp -> chaddr)) [1],
- ((unsigned char *)(tdp -> chaddr)) [2],
- ((unsigned char *)(tdp -> chaddr)) [3],
- ((unsigned char *)(tdp -> chaddr)) [4],
- ((unsigned char *)(tdp -> chaddr)) [5]);
- debug ("filename = %s", tdp -> file);
- debug ("server_name = %s", tdp -> sname);
- if (tp -> options_valid) {
- int i;
+ 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", tdp->xid, tdp->secs,
+ tdp->flags);
+ debug("ciaddr = %s", inet_ntoa(tdp->ciaddr));
+ debug("yiaddr = %s", inet_ntoa(tdp->yiaddr));
+ debug("siaddr = %s", inet_ntoa(tdp->siaddr));
+ debug("giaddr = %s", inet_ntoa(tdp->giaddr));
+ debug("chaddr = %02x:%02x:%02x:%02x:%02x:%02x",
+ ((unsigned char *)(tdp->chaddr))[0],
+ ((unsigned char *)(tdp->chaddr))[1],
+ ((unsigned char *)(tdp->chaddr))[2],
+ ((unsigned char *)(tdp->chaddr))[3],
+ ((unsigned char *)(tdp->chaddr))[4],
+ ((unsigned char *)(tdp->chaddr))[5]);
+ 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)
- debug (" %s = %s",
- dhcp_options [i].name,
- pretty_print_option
- (i, tp -> options [i].data,
- tp -> options [i].len, 1, 1));
+ if (tp->options[i].data)
+ debug(" %s = %s", dhcp_options[i].name,
+ pretty_print_option(i, tp->options[i].data,
+ tp->options[i].len, 1, 1));
}
}
- debug ("%s", "");
+ debug("%s", "");
}
-void dump_raw (buf, len)
- unsigned char *buf;
- int len;
+void
+dump_raw(unsigned char *buf, int len)
{
- int i, j;
- char lbuf [80];
- int llen = sizeof(lbuf);
- int lbix = 0;
+ int i, j;
+ char lbuf[80];
+ int llen = sizeof(lbuf);
+ int lbix = 0;
- lbuf [0] = 0;
+ lbuf[0] = 0;
for (i = 0; i < len; i++) {
if ((i & 15) == 0) {
if (lbix)
- note (lbuf);
- j = snprintf (lbuf, llen, "%03x:", i);
+ note(lbuf);
+ j = snprintf(lbuf, llen, "%03x:", i);
if (j >= llen)
return;
- lbix+=j;
- llen-=j;
+ lbix += j;
+ llen -= j;
} else if ((i & 7) == 0) {
- lbuf [lbix++] = ' ';
+ lbuf[lbix++] = ' ';
len--;
}
- j = snprintf (&lbuf [lbix], llen, " %02x", buf [i]);
+ j = snprintf(&lbuf[lbix], llen, " %02x", buf[i]);
if (j >= llen)
return;
lbix += j;
llen -= j;
}
- note (lbuf);
+ note(lbuf);
}
-void hash_dump (table)
- struct hash_table *table;
+void
+hash_dump(struct hash_table *table)
{
- int i;
+ int i;
struct hash_bucket *bp;
if (!table)
return;
- for (i = 0; i < table -> hash_count; i++) {
- if (!table -> buckets [i])
+ for (i = 0; i < table->hash_count; i++) {
+ if (!table->buckets[i])
continue;
- note ("hash bucket %d:", i);
- for (bp = table -> buckets [i]; bp; bp = bp -> next) {
- if (bp -> len)
- dump_raw (bp -> name, bp -> len);
+ note("hash bucket %d:", i);
+ for (bp = table->buckets[i]; bp; bp = bp->next) {
+ if (bp->len)
+ dump_raw(bp->name, bp->len);
else
- note ((char *)bp -> name);
+ note((char *) bp->name);
}
}
}