]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/pppoe/pppoe-discovery.c
pppoe: Rename variable printACNames to pppoe_verbose to match cmdline option
[ppp.git] / pppd / plugins / pppoe / pppoe-discovery.c
index 34b77e8c27217af9924d7f8cbb7c78966c688065..6f01790f1bc11d24ca891fb6f43761561bb88b29 100644 (file)
@@ -45,6 +45,8 @@
 #include <net/if_arp.h>
 #endif
 
+int pppoe_verbose;
+
 char *xstrdup(const char *s);
 void usage(void);
 
@@ -130,7 +132,7 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
     if ((fd = socket(domain, stype, htons(type))) < 0) {
        /* Give a more helpful message for the common error case */
        if (errno == EPERM) {
-           rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
+           fatal("Cannot create raw socket -- pppoe must be run as root.");
        }
        fatalSys("socket");
     }
@@ -148,17 +150,11 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
        memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
 #ifdef ARPHRD_ETHER
        if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
-           char buffer[256];
-           sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
-           rp_fatal(buffer);
+           fatal("Interface %.16s is not Ethernet", ifname);
        }
 #endif
        if (NOT_UNICAST(hwaddr)) {
-           char buffer[256];
-           sprintf(buffer,
-                   "Interface %.16s has broadcast/multicast MAC address??",
-                   ifname);
-           rp_fatal(buffer);
+           fatal("Interface %.16s has broadcast/multicast MAC address??", ifname);
        }
     }
 
@@ -214,18 +210,18 @@ sendPacket(PPPoEConnection *conn, int sock, PPPoEPacket *pkt, int size)
 {
 #if defined(HAVE_STRUCT_SOCKADDR_LL)
     if (send(sock, pkt, size, 0) < 0) {
-       sysErr("send (sendPacket)");
+       fatalSys("send (sendPacket)");
        return -1;
     }
 #else
     struct sockaddr sa;
 
     if (!conn) {
-       rp_fatal("relay and server not supported on Linux 2.0 kernels");
+       fatal("relay and server not supported on Linux 2.0 kernels");
     }
     strcpy(sa.sa_data, conn->ifName);
     if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
-       sysErr("sendto (sendPacket)");
+       fatalSys("sendto (sendPacket)");
        return -1;
     }
 #endif
@@ -247,7 +243,7 @@ int
 receivePacket(int sock, PPPoEPacket *pkt, int *size)
 {
     if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
-       sysErr("recv (receivePacket)");
+       fatalSys("recv (receivePacket)");
        return -1;
     }
     return 0;
@@ -381,7 +377,7 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data,
     switch(type) {
     case TAG_AC_NAME:
        pc->seenACName = 1;
-       if (conn->printACNames) {
+       if (pppoe_verbose >= 1) {
            printf("Access-Concentrator: %.*s\n", (int) len, data);
        }
        if (conn->acName && len == strlen(conn->acName) &&
@@ -391,7 +387,7 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data,
        break;
     case TAG_SERVICE_NAME:
        pc->seenServiceName = 1;
-       if (conn->printACNames && len > 0) {
+       if (pppoe_verbose >= 1 && len > 0) {
            printf("       Service-Name: %.*s\n", (int) len, data);
        }
        if (conn->serviceName && len == strlen(conn->serviceName) &&
@@ -400,7 +396,7 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data,
        }
        break;
     case TAG_AC_COOKIE:
-       if (conn->printACNames) {
+       if (pppoe_verbose >= 1) {
            printf("Got a cookie:");
            /* Print first 20 bytes of cookie */
            for (i=0; i<len && i < 20; i++) {
@@ -414,7 +410,7 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data,
        memcpy(conn->cookie.payload, data, len);
        break;
     case TAG_RELAY_SESSION_ID:
-       if (conn->printACNames) {
+       if (pppoe_verbose >= 1) {
            printf("Got a Relay-ID:");
            /* Print first 20 bytes of relay ID */
            for (i=0; i<len && i < 20; i++) {
@@ -428,17 +424,17 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data,
        memcpy(conn->relayId.payload, data, len);
        break;
     case TAG_SERVICE_NAME_ERROR:
-       if (conn->printACNames) {
+       if (pppoe_verbose >= 1) {
            printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data);
        }
        break;
     case TAG_AC_SYSTEM_ERROR:
-       if (conn->printACNames) {
+       if (pppoe_verbose >= 1) {
            printf("Got a System-Error tag: %.*s\n", (int) len, data);
        }
        break;
     case TAG_GENERIC_ERROR:
-       if (conn->printACNames) {
+       if (pppoe_verbose >= 1) {
            printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
        }
        break;
@@ -594,7 +590,7 @@ waitForPADO(PPPoEConnection *conn, int timeout)
            conn->numPADOs++;
            if (pc.acNameOK && pc.serviceNameOK) {
                memcpy(conn->peerEth, packet.ethHdr.h_source, ETH_ALEN);
-               if (conn->printACNames) {
+               if (pppoe_verbose >= 1) {
                    printf("AC-Ethernet-Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
                           (unsigned) conn->peerEth[0], 
                           (unsigned) conn->peerEth[1],
@@ -655,7 +651,7 @@ int main(int argc, char *argv[])
 
     memset(conn, 0, sizeof(PPPoEConnection));
 
-    conn->printACNames = 1;
+    pppoe_verbose = 1;
     conn->discoveryTimeout = PADI_TIMEOUT;
     conn->discoveryAttempts = MAX_PADI_ATTEMPTS;
 
@@ -719,7 +715,7 @@ int main(int argc, char *argv[])
            conn->ifName = xstrdup(optarg);
            break;
        case 'Q':
-           conn->printACNames = 0;
+           pppoe_verbose = 0;
            break;
        case 'V':
        case 'h':
@@ -746,9 +742,13 @@ int main(int argc, char *argv[])
        exit(0);
 }
 
-void rp_fatal(char const *str)
+void fatal(char * fmt, ...)
 {
-    fprintf(stderr, "%s\n", str);
+    va_list ap;
+    va_start(ap, fmt);
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
+    fputc('\n', stderr);
     exit(1);
 }
 
@@ -758,16 +758,11 @@ void fatalSys(char const *str)
     exit(1);
 }
 
-void sysErr(char const *str)
-{
-    rp_fatal(str);
-}
-
 char *xstrdup(const char *s)
 {
     register char *ret = strdup(s);
     if (!ret)
-       sysErr("strdup");
+       fatalSys("strdup");
     return ret;
 }