get working on trying to merge to busybox

This commit is contained in:
Russ Dill 2003-12-16 02:25:39 +00:00
parent 09457926fa
commit d47a7c9c39
5 changed files with 52 additions and 30 deletions

View File

@ -100,6 +100,7 @@ static void __attribute__ ((noreturn)) show_usage(void)
exit(0);
}
#else
#define show_usage bb_show_usage
extern void show_usage(void) __attribute__ ((noreturn));
#endif

View File

@ -15,6 +15,7 @@
/* the period of time the client is allowed to use that address */
#define LEASE_TIME (60*60*24*10) /* 10 days of seconds */
#define LEASES_FILE "/var/lib/misc/udhcpd.leases"
/* where to find the DHCP server configuration file */
#define DHCPD_CONF_FILE "/etc/udhcpd.conf"

View File

@ -3,30 +3,36 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <syslog.h>
#include <signal.h>
#include <errno.h>
#include <getopt.h>
#include <time.h>
#include "leases.h"
#include "libbb_udhcp.h"
#define REMAINING 0
#define ABSOLUTE 1
struct lease_t {
unsigned char chaddr[16];
u_int32_t yiaddr;
u_int32_t expires;
};
#ifndef IN_BUSYBOX
static void __attribute__ ((noreturn)) show_usage(void)
{
printf(
"Usage: dumpleases -f <file> -[r|a]\n\n"
" -f, --file=FILENAME Leases file to load\n"
" -r, --remaining Interepret lease times as time remaing\n"
" -a, --absolute Interepret lease times as expire time\n");
exit(0);
}
#else
#define show_usage bb_show_usage
#endif
#ifdef IN_BUSYBOX
int dumpleases_main(int argc, char *argv[])
@ -37,43 +43,34 @@ int main(int argc, char *argv[])
FILE *fp;
int i, c, mode = REMAINING;
long expires;
char file[255] = "/var/lib/misc/udhcpd.leases";
struct lease_t lease;
const char *file = LEASES_FILE;
struct dhcpOfferedAddr lease;
struct in_addr addr;
static struct option options[] = {
static const struct option options[] = {
{"absolute", 0, 0, 'a'},
{"remaining", 0, 0, 'r'},
{"file", 1, 0, 'f'},
{"help", 0, 0, 'h'},
{0, 0, 0, 0}
};
while (1) {
int option_index = 0;
c = getopt_long(argc, argv, "arf:h", options, &option_index);
c = getopt_long(argc, argv, "arf:", options, &option_index);
if (c == -1) break;
switch (c) {
case 'a': mode = ABSOLUTE; break;
case 'r': mode = REMAINING; break;
case 'f':
strncpy(file, optarg, 255);
file[254] = '\0';
break;
case 'h':
printf("Usage: dumpleases -f <file> -[r|a]\n\n");
printf(" -f, --file=FILENAME Leases file to load\n");
printf(" -r, --remaining Interepret lease times as time remaing\n");
printf(" -a, --absolute Interepret lease times as expire time\n");
file = optarg;
break;
default:
show_usage();
}
}
if (!(fp = fopen(file, "r"))) {
perror("could not open input file");
return 0;
}
fp = xfopen(file, "r");
printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at");
/* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */

View File

@ -3,7 +3,6 @@
* Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
*/
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
@ -163,7 +162,7 @@ static struct config_keyword keywords[] = {
{"conflict_time",read_u32,&(server_config.conflict_time),"3600"},
{"offer_time", read_u32, &(server_config.offer_time), "60"},
{"min_lease", read_u32, &(server_config.min_lease), "60"},
{"lease_file", read_str, &(server_config.lease_file), "/var/lib/misc/udhcpd.leases"},
{"lease_file", read_str, &(server_config.lease_file), LEASES_FILE},
{"pidfile", read_str, &(server_config.pidfile), "/var/run/udhcpd.pid"},
{"notify_file", read_str, &(server_config.notify_file), ""},
{"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"},

View File

@ -4,7 +4,7 @@
#define _LIBBB_UDHCP_H
#ifdef IN_BUSYBOX
#include "libbb.h"
#include "busybox.h"
#ifdef CONFIG_FEATURE_UDHCP_SYSLOG
#define SYSLOG
@ -17,12 +17,36 @@
#define COMBINED_BINARY
#include "version.h"
#ifdef CONFIG_INSTALL_NO_USR
#define DEFAULT_SCRIPT "/share/udhcpc/default.script"
#else
#define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script"
#endif
#define xfopen bb_xfopen
#else /* ! BB_VER */
#include <stdlib.h>
#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define xmalloc malloc
#define xcalloc calloc
#define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script"
static inline FILE *xfopen(const char *file, const char *mode)
{
FILE *fp;
if (!(fp = fopen(file, mode))) {
perror("could not open input file");
exit(0);
}
return fp;
}
#endif /* BB_VER */