[dhcp-agent-commits] dhcp-agent/src dhcp-libutil.h,NONE,1.1 Makefile.am,1.1.1.1,1.2 dhcp-list.c,1.1.
Status: Alpha
Brought to you by:
actmodern
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv6635/src Modified Files: Makefile.am dhcp-list.c dhcp-log.c dhcp-stringbuffer.c dhcp-util.c dhcp-util.h Added Files: dhcp-libutil.h Removed Files: dhcp-stringbuffer.h Log Message: setup for making a utility library -- zorched makefile.am temporarily until this conversion is over --- NEW FILE: dhcp-libutil.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v 1.1 2002/10/30 05:00:46 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * External interface header file: include this to use the * utility library. * */ #ifndef DHCP_LIBUTIL_H #define DHCP_LIBUTIL_H /* * * * * * * * * * * * Data structures. * * * * * * * * * * * */ /* list object. */ typedef struct list { struct list *next; void *data; } list_t; /* string buffer object. */ typedef struct { int len; int capacity; char *buf; } stringbuffer; /* prototypes. */ /* in case strdup is not available. */ # ifndef HAVE_STRDUP extern char *strdup(char *s); # endif /* HAVE_STRDUP */ /* messaging. */ extern void error_message(const char *func_name, const char *fmt, ...); extern void fatal_message(const char *func_name, const char *fmt, ...); extern void info_message(const char *fmt, ...); extern void warn_message(char *fmt, ...); extern void debug_message(const char *module_name, const char *func, const char *file, const char *fmt, ...); /* verbosity levels. */ extern int get_verbosity_level(void); extern int set_verbosity_level(int verbosity_level_to_set); /* dynamic allocation wrappers. */ extern void *xmalloc(size_t size); extern void *xcalloc(size_t size); extern void xfree(void *p); extern void *xrealloc(void *p, size_t size); /* signal/interrupt handlers. */ extern int check_for_interrupts(void); extern void suspend_for_interrupts(void); extern void block_interrupts(void); extern void add_interrupt_handler(int sigtype, void (*sighandler)(int)); extern void remove_interrupt(int sig); /* alarm handlers. */ extern int had_alarm(void); extern void set_alarm(struct timeval alarm_time); extern void remove_alarm(void); /* string routines -- XXX FIXME: we eventually want everything in * stringbuffer */ extern char *splice_string(const char *s1, const char *s2); extern char *splice_many_strings(int num, char *s, ...); extern int string_matches(const char *s1, const char *s2); extern int hex_string_to_value(char *string, unsigned char *dst); extern int is_string(const char *string, int len); extern char *xstrdup(const char *string); /* random number gen. */ extern uint16_t get_random_uint16(void); extern uint32_t get_random_uint32(void); /* misc. */ extern struct timeval timeval_diff(struct timeval begin, struct timeval end); extern const char *getprogname(void); extern int resolv(char *address, uint32_t *addr); extern int port_for_service(const char *serv, const char *proto); extern int is_seven_bit_clean(const char *data, int len); /* Replacement vsnprintf, snprintf that work the way we want them to. */ extern int snprintf (char *str, size_t count, const char *fmt, ...); extern int vsnprintf (char *str, size_t count, const char *fmt, va_list arg); /* Linked List routines. */ extern list_t *add_to_list(list_t *head, void *datum); extern list_t *add_to_end_of_list(list_t *head, void *datum); extern list_t *remove_from_list(list_t *head, void *datum); extern void purge_list(list_t *head, void (*purge_func)(void *d)); extern void purge_list_internal(void *head); extern list_t *join_lists(list_t *first_list, list_t *second_list); extern list_t *list_find_datum_by(list_t *list, int (*find_func)(void *, void *), void *arg); extern list_t *sort_list(list_t *list, int (*compare)(void *, void *)); /* stringbuffer. */ extern stringbuffer *create_stringbuffer(void); extern void destroy_stringbuffer(stringbuffer *sb); extern void stringbuffer_append(stringbuffer *sb, const char *s); extern stringbuffer *stringbuffer_trim_whitespace(stringbuffer *sb); extern char *stringbuffer_get_last_occurance(stringbuffer *sb, char c); extern void stringbuffer_trim_newline(stringbuffer *sb); extern const char *stringbuffer_getstring(stringbuffer *sb); extern void stringbuffer_aprintf(stringbuffer *sb, const char *fmt, ...); extern void stringbuffer_aprintf_align(stringbuffer *sb, int begin, int end, const char *fmt, ...); extern void stringbuffer_avprintf(stringbuffer *sb, const char *fmt, va_list ap); extern void stringbuffer_append_c(stringbuffer *sb, char c); extern void stringbuffer_clear(stringbuffer *sb); extern const char *stringbuffer_getnextline(stringbuffer *sb, const char *cptr); extern void stringbuffer_marknewlines(stringbuffer *sb); extern void stringbuffer_set(stringbuffer *dest, const char *s); extern void stringbuffer_align(stringbuffer *sb, int begin, int end); extern int stringbuffer_getlen(stringbuffer *sb); /* constants. */ /* stringbuffer chunk allocation size. */ #define STRINGBUFFER_CHUNKSIZE 16 /* Line length for messages before breaking into a new line. */ #define MESSAGE_LINE_LENGTH 60 /* macros. */ /* log message macros. */ #define INFO_MESSAGE(...) { info_message(__VA_ARGS__); } #define ERROR_MESSAGE(...) { error_message(__func__, __VA_ARGS__); } #define WARN_MESSAGE(...) { warn_message(__VA_ARGS__); } #define FATAL_MESSAGE(...) { fatal_message(__func__, __VA_ARGS__); } #define DEBUG_MESSAGE(...) { debug_message(MODULE_NAME, __func__, __FILE__, __VA_ARGS__); } /* Verbosity levels. */ enum verbosity { QUIET_VERBOSITY_LEVEL = 0, ERROR_VERBOSITY_LEVEL, NORMAL_VERBOSITY_LEVEL, WARNING_VERBOSITY_LEVEL, DEBUG_VERBOSITY_LEVEL, MAX_VERBOSITY_LEVEL }; /* Syslog options. */ #define LOG_OPT LOG_PID|LOG_NDELAY /* Options */ #define LOG_FACILITY LOG_DAEMON /* Facility */ #define ERROR_LEVEL LOG_ERR /* Error level */ #define INFO_LEVEL LOG_INFO /* Normal level */ #endif /* DHCP_LIBUTIL_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Makefile.am 29 Oct 2002 17:11:32 -0000 1.1.1.1 --- Makefile.am 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 8,66 **** # Programs we are compiling. ! bin_PROGRAMS = dhcp-sniff dhcp-client ! # Common sources. ! COMMON_SOURCES = \ ! dhcp-util.c dhcp-util.h \ ! dhcp-stringbuffer.c \ ! dhcp-list.c \ ! dhcp-log.c \ ! dhcp-snprintf.c # Main network code. ! RAWNET_SOURCES = \ ! dhcp-net.c \ ! dhcp-align.c \ ! dhcp-com.c \ ! dhcp-eth.c \ ! dhcp-ip.c \ ! dhcp-udp.c \ ! dhcp-arp.c \ ! dhcp-icmp.c \ ! dhcp-rtt.c \ dhcp-interface.c ! dhcp_sniff_SOURCES = \ ! $(COMMON_SOURCES) \ ! $(RAWNET_SOURCES) \ ! dhcp-sniff.c \ ! dhcp-print.c \ ! dhcp-sniffer-ohandlers.c ! dhcp_client_SOURCES = \ ! $(COMMON_SOURCES) \ ! $(RAWNET_SOURCES) \ ! dhcp-client.c \ ! dhcp-daemon.c \ ! dhcp-client-cache.c \ ! dhcp-cache-entry.c \ ! dhcp-client-control.c \ ! dhcp-client-conf.c \ ! dhcp-files.c \ ! dhcp-client-states.c \ ! dhcp-options-strings.c \ ! dhcp-convert.c \ ! dhcp-sysconf.c \ ! dhcp-packet-build.c \ ! dhcp-icmp-discovery.c \ ! dhcp-arp-discovery.c \ ! dhcp-route.c \ ! dhcp-globconf.c \ ! dhcp-parser.c \ ! dhcp-varfile.c \ ! dhcp-timer.c ! dhcp_client_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcp_sniff_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h ../config.h --- 8,66 ---- # Programs we are compiling. ! #bin_PROGRAMS = dhcp-sniff dhcp-client ! lib_LTLIBRARIES = libutil.la ! libutil_la_SOURCES = dhcp-util.c dhcp-util.h \ ! dhcp-stringbuffer.c \ ! dhcp-list.c \ ! dhcp-log.c \ ! dhcp-snprintf.c \ ! dhcp-libutil.h # Main network code. ! # RAWNET_SOURCES = \ ! # dhcp-net.c \ ! # dhcp-align.c \ ! # dhcp-com.c \ ! # dhcp-eth.c \ ! # dhcp-ip.c \ ! # dhcp-udp.c \ ! # dhcp-arp.c \ ! # dhcp-icmp.c \ ! # dhcp-rtt.c \ dhcp-interface.c ! # dhcp_sniff_SOURCES = \ ! # $(COMMON_SOURCES) \ ! # $(RAWNET_SOURCES) \ ! # dhcp-sniff.c \ ! # dhcp-print.c \ ! # dhcp-sniffer-ohandlers.c ! # dhcp_client_SOURCES = \ ! # $(COMMON_SOURCES) \ ! # $(RAWNET_SOURCES) \ ! # dhcp-client.c \ ! # dhcp-daemon.c \ ! # dhcp-client-cache.c \ ! # dhcp-cache-entry.c \ ! # dhcp-client-control.c \ ! # dhcp-client-conf.c \ ! # dhcp-files.c \ ! # dhcp-client-states.c \ ! # dhcp-options-strings.c \ ! # dhcp-convert.c \ ! # dhcp-sysconf.c \ ! # dhcp-packet-build.c \ ! # dhcp-icmp-discovery.c \ ! # dhcp-arp-discovery.c \ ! # dhcp-route.c \ ! # dhcp-globconf.c \ ! # dhcp-parser.c \ ! # dhcp-varfile.c \ ! # dhcp-timer.c ! # dhcp_client_LDADD = @PCAP_LIB@ @DNET_LIB@ ! # dhcp_sniff_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h ../config.h Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-list.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-list.c 29 Oct 2002 17:11:25 -0000 1.1.1.1 --- dhcp-list.c 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 24,29 **** #define MODULE_NAME "dhcp-list" - #include <dhcp-agent.h> #include <dhcp-util.h> list_t *add_to_list(list_t *head, void *datum) --- 24,29 ---- #define MODULE_NAME "dhcp-list" #include <dhcp-util.h> + #include <dhcp-libutil.h> list_t *add_to_list(list_t *head, void *datum) Index: dhcp-log.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-log.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-log.c 29 Oct 2002 17:11:25 -0000 1.1.1.1 --- dhcp-log.c 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 25,29 **** */ ! #include <dhcp-agent.h> void init_log(const char *s) --- 25,30 ---- */ ! #include <dhcp-util.h> ! #include <dhcp-libutil.h> void init_log(const char *s) Index: dhcp-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-stringbuffer.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-stringbuffer.c 29 Oct 2002 17:11:30 -0000 1.1.1.1 --- dhcp-stringbuffer.c 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 33,38 **** #define MODULE_NAME "dhcp-stringbuffer" - #include <dhcp-agent.h> #include <dhcp-util.h> /* * * * * * * * * * * * * --- 33,38 ---- #define MODULE_NAME "dhcp-stringbuffer" #include <dhcp-util.h> + #include <dhcp-libutil.h> /* * * * * * * * * * * * * Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-util.c 29 Oct 2002 17:11:31 -0000 1.1.1.1 --- dhcp-util.c 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 27,33 **** #define MODULE_NAME "dhcp-util" - #include <dhcp-agent.h> #include <dhcp-util.h> static int verbosity_level = DEBUG_VERBOSITY_LEVEL; --- 27,34 ---- #define MODULE_NAME "dhcp-util" #include <dhcp-util.h> + #include <dhcp-libutil.h> + static int interactive = 1; static int verbosity_level = DEBUG_VERBOSITY_LEVEL; Index: dhcp-util.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-util.h 29 Oct 2002 17:11:34 -0000 1.1.1.1 --- dhcp-util.h 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 21,24 **** --- 21,27 ---- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * + * Internal libutil header. We include what we need from the + * system here. + * */ *************** *** 26,102 **** #define DHCP_UTIL_H ! #include <dhcp-stringbuffer.h> ! ! /* Utility functions. */ ! ! /* in case strdup is not available. */ ! ! # ifndef HAVE_STRDUP ! extern char *strdup(char *s); ! # endif /* HAVE_STRDUP */ ! ! /* messaging. */ ! extern void error_message(const char *func_name, const char *fmt, ...); ! extern void fatal_message(const char *func_name, const char *fmt, ...); ! extern void info_message(const char *fmt, ...); ! extern void warn_message(char *fmt, ...); ! extern void debug_message(const char *module_name, const char *func, const char *file, const char *fmt, ...); ! ! /* verbosity levels. */ ! extern int get_verbosity_level(void); ! extern int set_verbosity_level(int verbosity_level_to_set); ! ! /* dynamic allocation wrappers. */ ! extern void *xmalloc(size_t size); ! extern void *xcalloc(size_t size); ! extern void xfree(void *p); ! extern void *xrealloc(void *p, size_t size); ! /* signal/interrupt handlers. */ ! extern int check_for_interrupts(void); ! extern void suspend_for_interrupts(void); ! extern void block_interrupts(void); ! extern void add_interrupt_handler(int sigtype, void (*sighandler)(int)); ! extern void remove_interrupt(int sig); ! ! /* alarm handlers. */ ! extern int had_alarm(void); ! extern void set_alarm(struct timeval alarm_time); ! extern void remove_alarm(void); ! ! /* sigio handlers -- FIXME: we don't want these anymore really. */ ! extern void track_sigio(void); ! extern int had_io(void); ! ! /* string routines -- XXX FIXME: we eventually want everything in ! * stringbuffer */ ! ! extern char *splice_string(const char *s1, const char *s2); ! extern char *splice_many_strings(int num, char *s, ...); ! extern int string_matches(const char *s1, const char *s2); ! extern int hex_string_to_value(char *string, unsigned char *dst); ! extern int is_string(const char *string, int len); ! extern char *xstrdup(const char *string); ! /* random number gen. */ ! extern uint16_t get_random_uint16(void); ! extern uint32_t get_random_uint32(void); ! /* misc. */ ! extern struct timeval timeval_diff(struct timeval begin, struct timeval end); ! extern const char *getprogname(void); ! extern int resolv(char *address, uint32_t *addr); ! extern int port_for_service(const char *serv, const char *proto); ! extern int is_seven_bit_clean(const char *data, int len); ! /* macros. */ ! /* log message macros. */ ! #define INFO_MESSAGE(...) { info_message(__VA_ARGS__); } ! #define ERROR_MESSAGE(...) { error_message(__func__, __VA_ARGS__); } ! #define WARN_MESSAGE(...) { warn_message(__VA_ARGS__); } ! #define FATAL_MESSAGE(...) { fatal_message(__func__, __VA_ARGS__); } ! #define DEBUG_MESSAGE(...) { debug_message(MODULE_NAME, __func__, __FILE__, __VA_ARGS__); } #endif /* DHCP_UTIL_H */ --- 29,60 ---- #define DHCP_UTIL_H ! #define __STDC_FORMAT_MACROS /* we need the C99 type macros. */ ! #ifdef HAVE_CONFIG_H ! #include "config.h" ! #endif ! #include <stdlib.h> ! #include <stdio.h> + #include <sys/types.h> + #include <sys/time.h> + #include <sys/stat.h> ! #include <string.h> ! #include <errno.h> ! #include <ctype.h> ! #include <unistd.h> ! #include <syslog.h> ! #include <signal.h> ! #include <stdarg.h> ! #include <inttypes.h> ! #include <dnet.h> ! /* XXX -- ??? -- what's the deal with this? must remember. */ ! /* must be placed in main source of each binary. ! * if not available. */ ! extern const char *__progname; #endif /* DHCP_UTIL_H */ --- dhcp-stringbuffer.h DELETED --- |