X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fplugins%2Frp-pppoe%2Fpppoe-discovery.c;fp=pppd%2Fplugins%2Frp-pppoe%2Fpppoe-discovery.c;h=bfb8706b0b1e2e8415a8783ec2d13d58e97cc9dc;hb=4ed9d22c884b6266f30d308c108f214a0815b812;hp=0000000000000000000000000000000000000000;hpb=ff9c589fef9957c502594d23be7f7fc3d8845161;p=ppp.git diff --git a/pppd/plugins/rp-pppoe/pppoe-discovery.c b/pppd/plugins/rp-pppoe/pppoe-discovery.c new file mode 100644 index 0000000..bfb8706 --- /dev/null +++ b/pppd/plugins/rp-pppoe/pppoe-discovery.c @@ -0,0 +1,124 @@ +/* + * Perform PPPoE discovery + * + * Copyright (C) 2000-2001 by Roaring Penguin Software Inc. + * Copyright (C) 2004 Marco d'Itri + * + * 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 +#include +#include +#include +#include + +#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"); +}