]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/pppoe/pppoe-discovery.c
pppd.8: Document netmask option
[ppp.git] / pppd / plugins / pppoe / pppoe-discovery.c
index 1fe999dbdf55b16fa7bbefe5ce6557b1f848fa26..5b1b2dc05295257f5e79878f64aaf8e7cce1af53 100644 (file)
@@ -10,7 +10,7 @@
  */
 
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdarg.h>
 #include <string.h>
 #include <time.h>
 #include <signal.h>
+#include <sys/time.h>
+#include <stdbool.h>
+#include <stdint.h>
 
 #include "pppoe.h"
 
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_NETPACKET_PACKET_H
-#include <netpacket/packet.h>
-#elif defined(HAVE_LINUX_IF_PACKET_H)
-#include <linux/if_packet.h>
-#endif
-
-#ifdef HAVE_ASM_TYPES_H
-#include <asm/types.h>
-#endif
-
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef HAVE_NET_IF_ARP_H
-#include <net/if_arp.h>
-#endif
-
 int debug;
 int got_sigterm;
 int pppoe_verbose;
 static FILE *debugFile;
 
 void
-fatal(char *fmt, ...)
+fatal(const char *fmt, ...)
 {
     va_list pvar;
     va_start(pvar, fmt);
@@ -67,7 +44,7 @@ fatal(char *fmt, ...)
 }
 
 void
-error(char *fmt, ...)
+error(const char *fmt, ...)
 {
     va_list pvar;
     va_start(pvar, fmt);
@@ -77,7 +54,7 @@ error(char *fmt, ...)
 }
 
 void
-warn(char *fmt, ...)
+warn(const char *fmt, ...)
 {
     va_list pvar;
     va_start(pvar, fmt);
@@ -87,7 +64,7 @@ warn(char *fmt, ...)
 }
 
 void
-info(char *fmt, ...)
+info(const char *fmt, ...)
 {
     va_list pvar;
     va_start(pvar, fmt);
@@ -149,6 +126,17 @@ get_time(struct timeval *tv)
     return gettimeofday(tv, NULL);
 }
 
+int signaled(int signal) {
+    if (signal == SIGTERM)
+        return got_sigterm;
+    return 0;
+}
+
+bool debug_on()
+{
+    return !!debug;
+}
+
 static void
 term_handler(int signum)
 {
@@ -233,7 +221,7 @@ int main(int argc, char *argv[])
                        optarg, strerror(errno));
                exit(1);
            }
-           fprintf(debugFile, "pppoe-discovery from pppd %s\n", VERSION);
+           fprintf(debugFile, "pppoe-discovery from pppd %s\n", PPPD_VERSION);
            break;
        case 'I':
            conn->ifName = xstrdup(optarg);
@@ -251,9 +239,16 @@ int main(int argc, char *argv[])
        }
     }
 
-    /* default interface name */
-    if (!conn->ifName)
-       conn->ifName = xstrdup("eth0");
+    if (optind != argc) {
+       fprintf(stderr, "%s: extra argument '%s'\n", argv[0], argv[optind]);
+       usage();
+       exit(EXIT_FAILURE);
+    }
+
+    if (!conn->ifName) {
+       fprintf(stderr, "Interface was not specified\n");
+       exit(EXIT_FAILURE);
+    }
 
     conn->sessionSocket = -1;
 
@@ -276,7 +271,7 @@ usage(void)
 {
     fprintf(stderr, "Usage: pppoe-discovery [options]\n");
     fprintf(stderr, "Options:\n");
-    fprintf(stderr, "   -I if_name     -- Specify interface (default eth0)\n");
+    fprintf(stderr, "   -I if_name     -- Specify interface (mandatory option)\n");
     fprintf(stderr, "   -D filename    -- Log debugging information in filename.\n");
     fprintf(stderr,
            "   -t timeout     -- Initial timeout for discovery packets in seconds\n"
@@ -288,5 +283,5 @@ usage(void)
            "   -U             -- Use Host-Unique to allow multiple PPPoE sessions.\n"
            "   -W hexvalue    -- Set the Host-Unique to the supplied hex string.\n"
            "   -h             -- Print usage information.\n");
-    fprintf(stderr, "\npppoe-discovery from pppd " VERSION "\n");
+    fprintf(stderr, "\npppoe-discovery from pppd " PPPD_VERSION "\n");
 }