diff options
author | David Hankins <dhankins@isc.org> | 2004-06-14 21:08:51 +0000 |
---|---|---|
committer | David Hankins <dhankins@isc.org> | 2004-06-14 21:08:51 +0000 |
commit | 53584b18ca1734a3070cbba8262b21d342a6954e (patch) | |
tree | bc77b8c07fff8f7d1f4782879229c714222122f2 | |
parent | 13a36c8d81d07d30ed737493f48ca22bef9e6d5d (diff) | |
download | isc-dhcp-53584b18ca1734a3070cbba8262b21d342a6954e.tar.gz |
- Use our own snprintf/vsnprintf functions if the system does not offer one.
snprintf/vsnprintf was borrowed from bind9.3.0/lib/isc/print.c, and
modified somewhat to compile in this build environment.
-rw-r--r-- | common/Makefile.dist | 12 | ||||
-rw-r--r-- | common/bpf.c | 6 | ||||
-rw-r--r-- | common/dns.c | 16 | ||||
-rw-r--r-- | common/parse.c | 7 | ||||
-rw-r--r-- | common/upf.c | 6 | ||||
-rw-r--r-- | includes/cf/cygwin32.h | 3 | ||||
-rw-r--r-- | includes/cf/freebsd.h | 2 | ||||
-rw-r--r-- | includes/cf/irix.h | 2 | ||||
-rw-r--r-- | includes/cf/nextstep.h | 3 | ||||
-rw-r--r-- | includes/cf/qnx.h | 1 | ||||
-rw-r--r-- | includes/cf/sample.h | 4 | ||||
-rw-r--r-- | includes/cf/sco.h | 1 | ||||
-rw-r--r-- | includes/cf/sunos4.h | 1 | ||||
-rw-r--r-- | includes/cf/ultrix.h | 4 | ||||
-rw-r--r-- | includes/osdep.h | 8 | ||||
-rw-r--r-- | omapip/Makefile.dist | 3 | ||||
-rw-r--r-- | server/ddns.c | 13 | ||||
-rw-r--r-- | server/dhcp.c | 7 | ||||
-rw-r--r-- | server/failover.c | 18 |
19 files changed, 40 insertions, 77 deletions
diff --git a/common/Makefile.dist b/common/Makefile.dist index 06ecc47f..8d4e043b 100644 --- a/common/Makefile.dist +++ b/common/Makefile.dist @@ -23,13 +23,13 @@ CATMANPAGES = dhcp-options.cat5 dhcp-eval.cat5 SEDMANPAGES = dhcp-options.man5 dhcp-eval.man5 SRC = raw.c parse.c nit.c icmp.c dispatch.c conflex.c upf.c bpf.c socket.c \ - lpf.c dlpi.c packet.c tr.c ethernet.c memory.c print.c options.c \ - inet.c tree.c tables.c alloc.c fddi.c ctrace.c \ - dns.c resolv.c execute.c discover.c comapi.c + lpf.c dlpi.c packet.c tr.c ethernet.c iscprint.c memory.c print.c \ + options.c inet.c tree.c tables.c alloc.c fddi.c ctrace.c dns.c \ + resolv.c execute.c discover.c comapi.c OBJ = raw.o parse.o nit.o icmp.o dispatch.o conflex.o upf.o bpf.o socket.o \ - lpf.o dlpi.o packet.o tr.o ethernet.o memory.o print.o options.o \ - inet.o tree.o tables.o alloc.o fddi.o ctrace.o \ - dns.o resolv.o execute.o discover.o comapi.o + lpf.o dlpi.o packet.o tr.o ethernet.o iscprint.o memory.o print.o \ + options.o inet.o tree.o tables.o alloc.o fddi.o ctrace.o dns.o \ + resolv.o execute.o discover.o comapi.o MAN = dhcp-options.5 dhcp-eval.5 INCLUDES = -I$(TOP) $(BINDINC) -I$(TOP)/includes diff --git a/common/bpf.c b/common/bpf.c index 9768bc27..24e11759 100644 --- a/common/bpf.c +++ b/common/bpf.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: bpf.c,v 1.48.2.4 2004/06/10 17:59:14 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; +"$Id: bpf.c,v 1.48.2.5 2004/06/14 21:08:42 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -90,11 +90,7 @@ int if_register_bpf (info) /* Open a BPF device */ for (b = 0; 1; b++) { -#ifndef NO_SNPRINTF snprintf(filename, sizeof(filename), BPF_FORMAT, b); -#else - sprintf(filename, BPF_FORMAT, b); -#endif sock = open (filename, O_RDWR, 0); if (sock < 0) { if (errno == EBUSY) { diff --git a/common/dns.c b/common/dns.c index 2e9058f8..ea4f3a5d 100644 --- a/common/dns.c +++ b/common/dns.c @@ -33,7 +33,7 @@ #ifndef lint static char copyright[] = -"$Id: dns.c,v 1.35.2.14 2004/06/10 17:59:17 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; +"$Id: dns.c,v 1.35.2.15 2004/06/14 21:08:42 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -530,15 +530,10 @@ isc_result_t ddns_update_a (struct data_string *ddns_fwd_name, if (ddns_addr.len != 4) return ISC_R_INVALIDARG; -#ifndef NO_SNPRINTF + snprintf (ddns_address, 16, "%d.%d.%d.%d", ddns_addr.iabuf[0], ddns_addr.iabuf[1], ddns_addr.iabuf[2], ddns_addr.iabuf[3]); -#else - sprintf (ddns_address, "%d.%d.%d.%d", - ddns_addr.iabuf[0], ddns_addr.iabuf[1], - ddns_addr.iabuf[2], ddns_addr.iabuf[3]); -#endif /* * When a DHCP client or server intends to update an A RR, it first @@ -784,16 +779,9 @@ isc_result_t ddns_remove_a (struct data_string *ddns_fwd_name, if (ddns_addr.len != 4) return ISC_R_INVALIDARG; -#ifndef NO_SNPRINTF snprintf (ddns_address, 16, "%d.%d.%d.%d", ddns_addr.iabuf[0], ddns_addr.iabuf[1], ddns_addr.iabuf[2], ddns_addr.iabuf[3]); -#else - sprintf (ddns_address, "%d.%d.%d.%d", - ddns_addr.iabuf[0], ddns_addr.iabuf[1], - ddns_addr.iabuf[2], ddns_addr.iabuf[3]); -#endif - /* * The entity chosen to handle the A record for this client (either the diff --git a/common/parse.c b/common/parse.c index 53569a00..0a119472 100644 --- a/common/parse.c +++ b/common/parse.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: parse.c,v 1.104.2.15 2004/06/10 17:59:20 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; +"$Id: parse.c,v 1.104.2.16 2004/06/14 21:08:43 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -4796,13 +4796,8 @@ int parse_warn (struct parse *cfile, const char *fmt, ...) unsigned i, lix; do_percentm (mbuf, fmt); -#ifndef NO_SNPRINTF snprintf (fbuf, sizeof fbuf, "%s line %d: %s", cfile -> tlname, cfile -> lexline, mbuf); -#else - sprintf (fbuf, "%s line %d: %s", - cfile -> tlname, cfile -> lexline, mbuf); -#endif va_start (list, fmt); vsnprintf (mbuf, sizeof mbuf, fbuf, list); diff --git a/common/upf.c b/common/upf.c index 00d4f76b..8d01df28 100644 --- a/common/upf.c +++ b/common/upf.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: upf.c,v 1.21.2.2 2004/06/10 17:59:22 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; +"$Id: upf.c,v 1.21.2.3 2004/06/14 21:08:44 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -79,11 +79,7 @@ int if_register_upf (info) /* Open a UPF device */ for (b = 0; 1; b++) { -#ifndef NO_SNPRINTF snprintf(filename, sizeof(filename), "/dev/pf/pfilt%d", b); -#else - sprintf(filename, "/dev/pf/pfilt%d", b); -#endif sock = open (filename, O_RDWR, 0); if (sock < 0) { if (errno == EBUSY) { diff --git a/includes/cf/cygwin32.h b/includes/cf/cygwin32.h index f1986dcd..812180ae 100644 --- a/includes/cf/cygwin32.h +++ b/includes/cf/cygwin32.h @@ -68,7 +68,8 @@ #define VA_DOTDOTDOT ... #define va_dcl #define VA_start(list, last) va_start (list, last) -#define vsnprintf(buf, size, fmt, list) vsprintf (buf, fmt, list) + +/* XXX: System is not believed to have vsnprintf. Someone please verify. */ #define NO_SNPRINTF #ifndef _PATH_DHCPD_PID diff --git a/includes/cf/freebsd.h b/includes/cf/freebsd.h index 94b98e71..651cc6e8 100644 --- a/includes/cf/freebsd.h +++ b/includes/cf/freebsd.h @@ -59,6 +59,8 @@ extern int h_errno; #define va_dcl #define VA_start(list, last) va_start (list, last) +#define NO_SNPRINTF + #ifndef _PATH_DHCPD_PID #define _PATH_DHCPD_PID "/var/run/dhcpd.pid" #endif diff --git a/includes/cf/irix.h b/includes/cf/irix.h index f3ebc579..d03a9177 100644 --- a/includes/cf/irix.h +++ b/includes/cf/irix.h @@ -67,7 +67,7 @@ extern int h_errno; #define VA_start(list, last) va_start (list, last) #define va_dcl -#define vsnprintf(buf, size, fmt, list) vsprintf (buf, fmt, list) +/* XXX: System is not believed to have snprintf/vsnprintf. Please verify. */ #define NO_SNPRINTF #if defined (USE_DEFAULT_NETWORK) diff --git a/includes/cf/nextstep.h b/includes/cf/nextstep.h index 0986150b..38517230 100644 --- a/includes/cf/nextstep.h +++ b/includes/cf/nextstep.h @@ -88,9 +88,10 @@ extern int h_errno; #define VA_DOTDOTDOT ... #define VA_start(list, last) va_start (list, last) #define va_dcl + /* NeXT lacks snprintf */ -#define vsnprintf(buf, size, fmt, list) vsprintf (buf, fmt, list) #define NO_SNPRINTF + /* Porting:: You must define the default network API for your port. This will depend on whether one of the existing APIs will work for diff --git a/includes/cf/qnx.h b/includes/cf/qnx.h index 5ced14b1..5bd6673e 100644 --- a/includes/cf/qnx.h +++ b/includes/cf/qnx.h @@ -108,7 +108,6 @@ typedef int socklen_t; #ifndef __QNXNTO__ # define NO_SNPRINTF -# define vsnprintf( buf, size, fmt, list ) vsprintf( buf, fbuf, list ) #endif #ifdef __QNXNTO__ diff --git a/includes/cf/sample.h b/includes/cf/sample.h index 3d965aca..0f793184 100644 --- a/includes/cf/sample.h +++ b/includes/cf/sample.h @@ -171,10 +171,10 @@ extern int h_errno; sprintf functions which will deposit a limited number of characters into the buffer; that limit is provided in an extra argument. If your system doesn't support this functionality, you must include - the definitions below: */ + the definition below for a dhcp-distribution-local version to be + built and used: */ #if 0 -#define vsnprintf(buf, size, fmt, list) vsprintf (buf, fmt, list) #define NO_SNPRINTF #endif diff --git a/includes/cf/sco.h b/includes/cf/sco.h index 8fd544c1..ce844e48 100644 --- a/includes/cf/sco.h +++ b/includes/cf/sco.h @@ -105,7 +105,6 @@ extern int h_errno; #define va_dcl /* SCO doesn't support limited sprintfs. */ -#define vsnprintf(buf, size, fmt, list) vsprintf (buf, fmt, list) #define NO_SNPRINTF /* By default, use BSD Socket API for receiving and sending packets. diff --git a/includes/cf/sunos4.h b/includes/cf/sunos4.h index c25ce9b8..f6fa5578 100644 --- a/includes/cf/sunos4.h +++ b/includes/cf/sunos4.h @@ -120,7 +120,6 @@ extern int h_errno; #endif /* !__GNUC__*/ /* SunOS doesn't support limited sprintfs. */ -#define vsnprintf(buf, size, fmt, list) vsprintf (buf, fmt, list) #define NO_SNPRINTF /* SunOS doesn't supply strerror... */ diff --git a/includes/cf/ultrix.h b/includes/cf/ultrix.h index 126ebce7..176d4f48 100644 --- a/includes/cf/ultrix.h +++ b/includes/cf/ultrix.h @@ -84,8 +84,10 @@ extern int h_errno; #include <varargs.h> #define VA_DOTDOTDOT va_alist #define VA_start(list, last) va_start (list) -#define vsnprintf(buf, size, fmt, list) vsprintf (buf, fmt, list) + +/* XXX: System is not thought to support snprintf/vsnprintf. Please verify. */ #define NO_SNPRINTF + #define NEED_INET_ATON #define INADDR_LOOPBACK ((u_int32_t)0x7f000001) diff --git a/includes/osdep.h b/includes/osdep.h index 84b3de58..40affe75 100644 --- a/includes/osdep.h +++ b/includes/osdep.h @@ -133,6 +133,14 @@ # endif #endif +/* snprintf/vsnprintf hacks. for systems with no libc versions only. */ +#ifdef NO_SNPRINTF + extern int isc_print_snprintf(char *, size_t, const char *, ...); + extern int isc_print_vsnprintf(char *, size_t, const char *, va_list ap); +# define snprintf isc_print_snprintf +# define vsnprintf isc_print_vsnprintf +#endif + /* Porting:: If you add a new network API, and have it set up so that it can be diff --git a/omapip/Makefile.dist b/omapip/Makefile.dist index 714d3527..4337fb42 100644 --- a/omapip/Makefile.dist +++ b/omapip/Makefile.dist @@ -32,7 +32,8 @@ SRC = protocol.c buffer.c alloc.c result.c connection.c errwarn.c \ OBJ = protocol.o buffer.o alloc.o result.o connection.o errwarn.o \ listener.o dispatch.o generic.o support.o handle.o message.o \ convert.o hash.o auth.o inet_addr.o array.o trace.o mrtrace.o \ - toisc.o + toisc.o ../common/iscprint.o +# XXX: iscprint.o above is a kludge. MAN = omapi.3 diff --git a/server/ddns.c b/server/ddns.c index 57d68f6b..24a6dd72 100644 --- a/server/ddns.c +++ b/server/ddns.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: ddns.c,v 1.15.2.12 2004/06/14 16:39:57 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; +"$Id: ddns.c,v 1.15.2.13 2004/06/14 21:08:50 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -495,21 +495,14 @@ int ddns_updates (struct packet *packet, d1.len + 17, MDL); if (ddns_rev_name.buffer) { ddns_rev_name.data = ddns_rev_name.buffer -> data; -#ifndef NO_SNPRINTF + snprintf ((char *)ddns_rev_name.buffer -> data, 17, "%d.%d.%d.%d.", lease -> ip_addr . iabuf[3], lease -> ip_addr . iabuf[2], lease -> ip_addr . iabuf[1], lease -> ip_addr . iabuf[0]); -#else - sprintf ((char *)ddns_rev_name.buffer -> data, - "%d.%d.%d.%d.", - lease -> ip_addr . iabuf[3], - lease -> ip_addr . iabuf[2], - lease -> ip_addr . iabuf[1], - lease -> ip_addr . iabuf[0]); -#endif + ddns_rev_name.len = strlen ((const char *)ddns_rev_name.data); data_string_append (&ddns_rev_name, &d1); diff --git a/server/dhcp.c b/server/dhcp.c index 8276f798..6746a750 100644 --- a/server/dhcp.c +++ b/server/dhcp.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: dhcp.c,v 1.192.2.32 2004/06/10 17:59:52 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; +"$Id: dhcp.c,v 1.192.2.33 2004/06/14 21:08:51 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -80,13 +80,8 @@ void dhcp (packet) packet -> packet_type < dhcp_type_name_max - 1) { s = dhcp_type_names [packet -> packet_type - 1]; } else { -#if defined (HAVE_SNPRINTF) snprintf (typebuf, sizeof typebuf, "type %d", packet -> packet_type); -#else - sprintf (typebuf, - "type %d", packet -> packet_type); -#endif s = typebuf; } diff --git a/server/failover.c b/server/failover.c index 4705f1b6..28793543 100644 --- a/server/failover.c +++ b/server/failover.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: failover.c,v 1.53.2.28 2004/06/10 17:59:54 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; +"$Id: failover.c,v 1.53.2.29 2004/06/14 21:08:51 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -3399,13 +3399,7 @@ failover_option_t *dhcp_failover_option_printf (unsigned code, char tbuf [256]; va_start (va, fmt); -#if defined (HAVE_SNPRINTF) - /* Presumably if we have snprintf, we also have - vsnprintf. */ vsnprintf (tbuf, sizeof tbuf, fmt, va); -#else - vsprintf (tbuf, fmt, va); -#endif va_end (va); return dhcp_failover_make_option (code, obuf, obufix, obufmax, @@ -4485,19 +4479,13 @@ isc_result_t dhcp_failover_process_bind_update (dhcp_failover_state_t *state, } if (new_binding_state != msg -> binding_status) { char outbuf [100]; -#if !defined (NO_SNPRINTF) + snprintf (outbuf, sizeof outbuf, "%s: invalid state transition: %s to %s", piaddr (lease -> ip_addr), binding_state_print (lease -> binding_state), binding_state_print (msg -> binding_status)); -#else - sprintf (outbuf, - "%s: invalid state transition: %s to %s", - piaddr (lease -> ip_addr), - binding_state_print (lease -> binding_state), - binding_state_print (msg -> binding_status)); -#endif + dhcp_failover_send_bind_ack (state, msg, FTR_FATAL_CONFLICT, outbuf); |