X-Git-Url: https://git.draconx.ca/gitweb/rarpd-dx.git/blobdiff_plain/7848d2e1002e486171bd4e6a1b8d84d64f389af4..0bf68d0c2640d1bd7a50e8438a89164e68d03e0d:/src/rarpd.c diff --git a/src/rarpd.c b/src/rarpd.c index 76b92e5..2374fb0 100644 --- a/src/rarpd.c +++ b/src/rarpd.c @@ -32,10 +32,6 @@ #include #include -#if HAVE_ERROR_H -#include -#endif - int do_reload = 1; int debug; @@ -48,8 +44,9 @@ int listen_arp; 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 { @@ -80,22 +77,30 @@ struct rarp_map 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 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 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) @@ -588,8 +593,11 @@ int main(int argc, char **argv) int psize; int opt; + 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; @@ -621,13 +629,19 @@ int main(int argc, char **argv) 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]; } @@ -639,8 +653,10 @@ int main(int argc, char **argv) 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; } @@ -681,12 +697,17 @@ int main(int argc, char **argv) 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);