#define ENABLE_NIS
#define ENABLE_INFO
/* Define this to enable some compatability with 1.x and 2.x info files */
-// #define ENABLE_INFO_COMPAT
+/* #define ENABLE_INFO_COMPAT */
/* IPV4LL, aka ZeroConf, aka APIPA, aka RFC 3927.
* Needs ARP. */
/* Some systems do not have a working fork.
* The Makefile will attempt to work it out, but if it fails to feel free to
* define it here. */
-// #define THERE_IS_NO_FORK
+/* #define THERE_IS_NO_FORK */
/* Packname name and pathname definitions. */
#include "logger.h"
#include "socket.h"
-static const char *dhcp_message[] = {
- [DHCP_DISCOVER] = "DHCP_DISCOVER",
- [DHCP_OFFER] = "DHCP_OFFER",
- [DHCP_REQUEST] = "DHCP_REQUEST",
- [DHCP_DECLINE] = "DHCP_DECLINE",
- [DHCP_ACK] = "DHCP_ACK",
- [DHCP_NAK] = "DHCP_NAK",
- [DHCP_RELEASE] = "DHCP_RELEASE",
- [DHCP_INFORM] = "DHCP_INFORM",
- [DHCP_INFORM + 1] = NULL
+typedef struct message {
+ int value;
+ const char *name;
+} dhcp_message_t;
+
+static dhcp_message_t dhcp_messages[] = {
+ { DHCP_DISCOVER, "DHCP_DISCOVER" },
+ { DHCP_OFFER, "DHCP_OFFER" },
+ { DHCP_REQUEST, "DHCP_REQUEST" },
+ { DHCP_DECLINE, "DHCP_DECLINE" },
+ { DHCP_ACK, "DHCP_ACK" },
+ { DHCP_NAK, "DHCP_NAK" },
+ { DHCP_RELEASE, "DHCP_RELEASE" },
+ { DHCP_INFORM, "DHCP_INFORM" },
+ { -1, NULL }
};
+static const char *dhcp_message (int type)
+{
+ dhcp_message_t *d;
+ for (d = dhcp_messages; d->name; d++)
+ if (d->value == type)
+ return (d->name);
+
+ return (NULL);
+}
+
size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
unsigned long xid, char type,
const options_t *options)
free (message);
logger (LOG_DEBUG, "sending %s with xid 0x%lx",
- dhcp_message[(int) type], xid);
+ dhcp_message (type), xid);
retval = send_packet (iface, ETHERTYPE_IP, (unsigned char *) packet,
message_length + sizeof (struct ip) +
sizeof (struct udphdr));
* SUCH DAMAGE.
*/
+#define SYSLOG_NAMES
+
+#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
static int loglevel = LOG_WARNING;
static char logprefix[12] = {0};
-static const char *syslog_level_msg[] = {
- [LOG_EMERG] = "EMERGENCY!",
- [LOG_ALERT] = "ALERT!",
- [LOG_CRIT] = "Critical!",
- [LOG_WARNING] = "Warning",
- [LOG_ERR] = "Error",
- [LOG_INFO] = "Info",
- [LOG_DEBUG] = "Debug",
- [LOG_DEBUG + 1] = NULL
-};
-
-static const char *syslog_level[] = {
- [LOG_EMERG] = "LOG_EMERG",
- [LOG_ALERT] = "LOG_ALERT",
- [LOG_CRIT] = "LOG_CRIT",
- [LOG_ERR] = "LOG_ERR",
- [LOG_WARNING] = "LOG_WARNING",
- [LOG_NOTICE] = "LOG_NOTICE",
- [LOG_INFO] = "LOG_INFO",
- [LOG_DEBUG] = "LOG_DEBUG",
- [LOG_DEBUG + 1] = NULL
-};
-
int logtolevel (const char *priority)
{
- int i = 0;
+ CODE *c;
- while (syslog_level[i]) {
- if (!strcmp (priority, syslog_level[i]))
- return i;
- i++;
- }
- return -1;
+ if (isdigit ((int) *priority))
+ return (atoi (priority));
+
+ for (c = prioritynames; c->c_name; c++)
+ if (! strcasecmp (priority, c->c_name))
+ return (c->c_val);
+
+ return (-1);
+}
+
+static const char *leveltolog (int level) {
+ CODE *c;
+
+ for (c = prioritynames; c->c_name; c++)
+ if (c->c_val == level)
+ return (c->c_name);
+
+ return (NULL);
}
void setloglevel (int level)
snprintf (logprefix, sizeof (logprefix), "%s", prefix);
}
-void logger(int level, const char *fmt, ...)
+void logger (int level, const char *fmt, ...)
{
va_list p;
va_list p2;
if (level <= LOG_ERR || level <= loglevel) {
if (level == LOG_DEBUG || level == LOG_INFO)
f = stdout;
- fprintf (f, "%s, %s", syslog_level_msg[level], logprefix);
+ fprintf (f, "%s, %s", leveltolog (level), logprefix);
vfprintf (f, fmt, p);
fputc ('\n', f);
# Setup some good default CFLAGS
CFLAGS?= -O2 -pipe
-CSTD?= c99
# GNU Make way of detecting gcc flags we can use
check_gcc=$(shell if ${CC} $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
done
# Loads of nice flags to ensure our code is good
-CFLAGS+= -pedantic -std=${CSTD} \
+CFLAGS+= -pedantic \
-Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
-Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \
-Wbad-function-cast -Wnested-externs -Wcomment -Winline \
}
if (rset && FD_ISSET (signal_pipe[0], rset)) {
- int buflen = sizeof (sig) * 2;
- char buf[buflen];
+ char buf[16];
size_t bytes;
- memset (buf, 0, buflen);
- bytes = read (signal_pipe[0], buf, buflen);
+ memset (buf, 0, sizeof (buf));
+ bytes = read (signal_pipe[0], buf, sizeof (buf));
if (bytes >= sizeof (sig))
memcpy (&sig, buf, sizeof (sig));