]> git.ozlabs.org Git - ppp.git/commitdiff
Add pppoe-discovery program, from Marco D'Itri
authorPaul Mackerras <paulus@samba.org>
Sat, 13 Nov 2004 12:14:59 +0000 (12:14 +0000)
committerPaul Mackerras <paulus@samba.org>
Sat, 13 Nov 2004 12:14:59 +0000 (12:14 +0000)
pppd/plugins/rp-pppoe/Makefile.linux
pppd/plugins/rp-pppoe/pppoe-discovery.c [new file with mode: 0644]

index c20af5774527735b500cb4553a5f513de0b9a61d..5c8ecafc150dcf11bce0a44e589759f902d4ebf0 100644 (file)
 # This program may be distributed according to the terms of the GNU
 # General Public License, version 2 or (at your option) any later version.
 #
 # This program may be distributed according to the terms of the GNU
 # General Public License, version 2 or (at your option) any later version.
 #
-# $Id: Makefile.linux,v 1.4 2004/10/31 22:09:03 paulus Exp $
+# $Id: Makefile.linux,v 1.5 2004/11/13 12:14:59 paulus Exp $
 #***********************************************************************
 
 DESTDIR = @DESTDIR@
 #***********************************************************************
 
 DESTDIR = @DESTDIR@
+BINDIR = $(DESTDIR)/sbin
 LIBDIR = $(DESTDIR)/lib/pppd/$(VERSION)
 
 INSTALL        = install
 LIBDIR = $(DESTDIR)/lib/pppd/$(VERSION)
 
 INSTALL        = install
@@ -23,7 +24,13 @@ VERSION=3.3
 
 COPTS=-O2 -g
 CFLAGS=$(COPTS) -I../../../include/linux
 
 COPTS=-O2 -g
 CFLAGS=$(COPTS) -I../../../include/linux
-all: rp-pppoe.so
+all: rp-pppoe.so pppoe-discovery
+
+pppoe-discovery: libplugin.a pppoe-discovery.o
+       $(CC) -o pppoe-discovery pppoe-discovery.o libplugin.a
+
+pppoe-discovery.o: pppoe-discovery.c
+       $(CC) $(CFLAGS) '-DVERSION="$(VERSION)"' -c -o pppoe-discovery.o pppoe-discovery.c
 
 rp-pppoe.so: libplugin.a plugin.o
        $(CC) -o rp-pppoe.so -shared plugin.o libplugin.a
 
 rp-pppoe.so: libplugin.a plugin.o
        $(CC) -o rp-pppoe.so -shared plugin.o libplugin.a
@@ -31,6 +38,8 @@ rp-pppoe.so: libplugin.a plugin.o
 install: all
        $(INSTALL) -d -m 755 $(LIBDIR)
        $(INSTALL) -s -c -m 4550 rp-pppoe.so $(LIBDIR)
 install: all
        $(INSTALL) -d -m 755 $(LIBDIR)
        $(INSTALL) -s -c -m 4550 rp-pppoe.so $(LIBDIR)
+       $(INSTALL) -d -m 755 $(BINDIR)
+       $(INSTALL) -s -c -m 555 pppoe-discovery $(BINDIR)
 
 clean:
        rm -f *.o *.so
 
 clean:
        rm -f *.o *.so
diff --git a/pppd/plugins/rp-pppoe/pppoe-discovery.c b/pppd/plugins/rp-pppoe/pppoe-discovery.c
new file mode 100644 (file)
index 0000000..bfb8706
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Perform PPPoE discovery
+ *
+ * Copyright (C) 2000-2001 by Roaring Penguin Software Inc.
+ * Copyright (C) 2004 Marco d'Itri <md@linux.it>
+ *
+ * This program may be distributed according to the terms of the GNU
+ * General Public License, version 2 or (at your option) any later version.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+#include "pppoe.h"
+
+char *xstrdup(const char *s);
+void usage(void);
+
+void die(int status)
+{
+       exit(status);
+}
+
+int main(int argc, char *argv[])
+{
+    int opt;
+    PPPoEConnection *conn;
+
+    conn = malloc(sizeof(PPPoEConnection));
+    if (!conn)
+       fatalSys("malloc");
+
+    memset(conn, 0, sizeof(PPPoEConnection));
+
+    while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
+       switch(opt) {
+       case 'S':
+           conn->serviceName = xstrdup(optarg);
+           break;
+       case 'C':
+           conn->acName = xstrdup(optarg);
+           break;
+       case 'U':
+           conn->useHostUniq = 1;
+           break;
+       case 'D':
+           conn->debugFile = fopen(optarg, "w");
+           if (!conn->debugFile) {
+               fprintf(stderr, "Could not open %s: %s\n",
+                       optarg, strerror(errno));
+               exit(1);
+           }
+           fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION);
+           break;
+       case 'I':
+           conn->ifName = xstrdup(optarg);
+           break;
+       case 'A':
+           /* this is the default */
+           break;
+       case 'V':
+       case 'h':
+           usage();
+           exit(0);
+       default:
+           usage();
+           exit(1);
+       }
+    }
+
+    /* default interface name */
+    if (!conn->ifName)
+       conn->ifName = strdup("eth0");
+
+    conn->discoverySocket = -1;
+    conn->sessionSocket = -1;
+    conn->printACNames = 1;
+
+    discovery(conn);
+    exit(0);
+}
+
+void rp_fatal(char const *str)
+{
+    char buf[1024];
+
+    printErr(str);
+    sprintf(buf, "pppoe-discovery: %.256s", str);
+    exit(1);
+}
+
+void fatalSys(char const *str)
+{
+    char buf[1024];
+    int i = errno;
+
+    sprintf(buf, "%.256s: %.256s", str, strerror(i));
+    printErr(buf);
+    sprintf(buf, "pppoe-discovery: %.256s: %.256s", str, strerror(i));
+    exit(1);
+}
+
+void sysErr(char const *str)
+{
+    rp_fatal(str);
+}
+
+char *xstrdup(const char *s)
+{
+    register char *ret = strdup(s);
+    if (!ret)
+       sysErr("strdup");
+    return ret;
+}
+
+void usage(void)
+{
+    fprintf(stderr, "Usage: pppoe-discovery [options]\n");
+    fprintf(stderr, "\nVersion " VERSION "\n");
+}