#include <sys/ioctl.h>
#include <sys/socket.h>
-#include "iputils_common.h"
-
int do_reload = 1;
int debug;
char *ifname;
char *tftp_dir = "/etc/tftpboot";
+static const char *progname = "rarpd";
+
extern int ether_ntohost(char *name, unsigned char *ea);
-void usage(void) __attribute__((noreturn));
struct iflink
{
uint32_t ipaddr;
} *rarp_db;
-void usage(void)
+static void print_usage(FILE *f)
+{
+ fprintf(f, "Usage: %s [options] [interface]\n", progname);
+ if (f != stdout)
+ fprintf(f, "Try %s -H for more information.\n", progname);
+}
+
+static void print_help(void)
{
- fprintf(stderr,
- "\nUsage:\n"
- " rarpd [options] [interface]\n"
- "\nOptions:\n"
- " -A listen also arp messages\n"
- " -a listen on all the interfaces\n"
- " -b <dir> tftpd boot directory\n"
- " -d debug mode\n"
- " -e /etc/ethers markup alone is fine\n"
- " -v verbose mode\n"
- " -V print version and exit\n"
- "\nFor more details see rarpd(8).\n"
- );
- exit(1);
+ print_usage(stdout);
+ putchar('\n');
+
+ puts("Options:");
+ puts(" -A listen also arp messages");
+ puts(" -a listen on all the interfaces");
+ puts(" -b <dir> tftpd boot directory");
+ puts(" -d debug mode");
+ puts(" -e /etc/ethers markup alone is fine");
+ puts(" -v verbose mode");
+ puts(" -V print version and then exit");
+ puts(" -H print this message and then exit");
+ putchar('\n');
+
+ puts("For more information, see the rarpd(8) man page.");
}
static void print_version(void)
int psize;
int opt;
- atexit(close_stdout);
+ if (argc > 0)
+ progname = argv[0];
+
opterr = 0;
- while ((opt = getopt(argc, argv, "aAb:dvoeV")) != EOF) {
+ while ((opt = getopt(argc, argv, "aAb:dvoeVH")) != EOF) {
switch (opt) {
case 'a':
++all_ifaces;
case 'V':
print_version();
return 0;
+ case 'H':
+ print_help();
+ return 0;
default:
- usage();
+ print_usage(stderr);
+ return EXIT_FAILURE;
}
}
if (argc > optind) {
- if (argc > optind+1)
- usage();
+ if (argc > optind+1) {
+ print_usage(stderr);
+ return EXIT_FAILURE;
+ }
ifname = argv[optind];
}
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
if (ioctl(pset[0].fd, SIOCGIFINDEX, &ifr)) {
- error(0, errno, "ioctl(SIOCGIFINDEX)");
- usage();
+ fprintf(stderr, "%s: %s: ioctl(SIOCGIFINDEX): %s\n",
+ progname, ifname, strerror(errno));
+ print_usage(stderr);
+ return EXIT_FAILURE;
}
ifidx = ifr.ifr_ifindex;
}
pset[0] = pset[1];
psize--;
}
- if (psize == 0)
- error(1, errno, "failed to bind any socket");
+ if (psize == 0) {
+ fprintf(stderr, "%s: error: failed to bind any socket\n", progname);
+ return EXIT_FAILURE;
+ }
if (!debug) {
- if (daemon(0, 0) < 0)
- error(1, errno, "failed to daemon()");
+ if (daemon(0, 0) < 0) {
+ fprintf(stderr, "%s: error: daemon() failed: %s\n",
+ progname, strerror(errno));
+ return EXIT_FAILURE;
+ }
}
openlog("rarpd", LOG_PID | LOG_CONS, LOG_DAEMON);