]> git.ozlabs.org Git - ppp.git/blob - pppd/plugins/rp-pppoe/pppoe-discovery.c
pppd: Provide error() implementation in pppoe-discovery
[ppp.git] / pppd / plugins / rp-pppoe / pppoe-discovery.c
1 /*
2  * Perform PPPoE discovery
3  *
4  * Copyright (C) 2000-2001 by Roaring Penguin Software Inc.
5  * Copyright (C) 2004 Marco d'Itri <md@linux.it>
6  *
7  * This program may be distributed according to the terms of the GNU
8  * General Public License, version 2 or (at your option) any later version.
9  *
10  */
11
12 #include <stdarg.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <errno.h>
17 #include <string.h>
18
19 #include "pppoe.h"
20
21 #ifdef HAVE_UNISTD_H
22 #include <unistd.h>
23 #endif
24
25 #ifdef HAVE_NETPACKET_PACKET_H
26 #include <netpacket/packet.h>
27 #elif defined(HAVE_LINUX_IF_PACKET_H)
28 #include <linux/if_packet.h>
29 #endif
30
31 #ifdef HAVE_NET_ETHERNET_H
32 #include <net/ethernet.h>
33 #endif
34
35 #ifdef HAVE_ASM_TYPES_H
36 #include <asm/types.h>
37 #endif
38
39 #ifdef HAVE_SYS_IOCTL_H
40 #include <sys/ioctl.h>
41 #endif
42
43 #include <errno.h>
44 #include <stdlib.h>
45 #include <string.h>
46
47 #ifdef HAVE_NET_IF_ARP_H
48 #include <net/if_arp.h>
49 #endif
50
51 char *xstrdup(const char *s);
52 void usage(void);
53
54 void die(int status)
55 {
56         exit(status);
57 }
58
59 void error(char *fmt, ...)
60 {
61     va_list pvar;
62     va_start(pvar, fmt);
63     vfprintf(stderr, fmt, pvar);
64     va_end(pvar);
65 }
66
67 /* Initialize frame types to RFC 2516 values.  Some broken peers apparently
68    use different frame types... sigh... */
69
70 UINT16_t Eth_PPPOE_Discovery = ETH_PPPOE_DISCOVERY;
71 UINT16_t Eth_PPPOE_Session   = ETH_PPPOE_SESSION;
72
73 /**********************************************************************
74 *%FUNCTION: etherType
75 *%ARGUMENTS:
76 * packet -- a received PPPoE packet
77 *%RETURNS:
78 * ethernet packet type (see /usr/include/net/ethertypes.h)
79 *%DESCRIPTION:
80 * Checks the ethernet packet header to determine its type.
81 * We should only be receveing DISCOVERY and SESSION types if the BPF
82 * is set up correctly.  Logs an error if an unexpected type is received.
83 * Note that the ethernet type names come from "pppoe.h" and the packet
84 * packet structure names use the LINUX dialect to maintain consistency
85 * with the rest of this file.  See the BSD section of "pppoe.h" for
86 * translations of the data structure names.
87 ***********************************************************************/
88 UINT16_t
89 etherType(PPPoEPacket *packet)
90 {
91     UINT16_t type = (UINT16_t) ntohs(packet->ethHdr.h_proto);
92     if (type != Eth_PPPOE_Discovery && type != Eth_PPPOE_Session) {
93         fprintf(stderr, "Invalid ether type 0x%x\n", type);
94     }
95     return type;
96 }
97
98 /**********************************************************************
99 *%FUNCTION: openInterface
100 *%ARGUMENTS:
101 * ifname -- name of interface
102 * type -- Ethernet frame type
103 * hwaddr -- if non-NULL, set to the hardware address
104 *%RETURNS:
105 * A raw socket for talking to the Ethernet card.  Exits on error.
106 *%DESCRIPTION:
107 * Opens a raw Ethernet socket
108 ***********************************************************************/
109 int
110 openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
111 {
112     int optval=1;
113     int fd;
114     struct ifreq ifr;
115     int domain, stype;
116
117 #ifdef HAVE_STRUCT_SOCKADDR_LL
118     struct sockaddr_ll sa;
119 #else
120     struct sockaddr sa;
121 #endif
122
123     memset(&sa, 0, sizeof(sa));
124
125 #ifdef HAVE_STRUCT_SOCKADDR_LL
126     domain = PF_PACKET;
127     stype = SOCK_RAW;
128 #else
129     domain = PF_INET;
130     stype = SOCK_PACKET;
131 #endif
132
133     if ((fd = socket(domain, stype, htons(type))) < 0) {
134         /* Give a more helpful message for the common error case */
135         if (errno == EPERM) {
136             rp_fatal("Cannot create raw socket -- pppoe must be run as root.");
137         }
138         fatalSys("socket");
139     }
140
141     if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0) {
142         fatalSys("setsockopt");
143     }
144
145     /* Fill in hardware address */
146     if (hwaddr) {
147         strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
148         if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
149             fatalSys("ioctl(SIOCGIFHWADDR)");
150         }
151         memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
152 #ifdef ARPHRD_ETHER
153         if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
154             char buffer[256];
155             sprintf(buffer, "Interface %.16s is not Ethernet", ifname);
156             rp_fatal(buffer);
157         }
158 #endif
159         if (NOT_UNICAST(hwaddr)) {
160             char buffer[256];
161             sprintf(buffer,
162                     "Interface %.16s has broadcast/multicast MAC address??",
163                     ifname);
164             rp_fatal(buffer);
165         }
166     }
167
168     /* Sanity check on MTU */
169     strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
170     if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) {
171         fatalSys("ioctl(SIOCGIFMTU)");
172     }
173     if (ifr.ifr_mtu < ETH_DATA_LEN) {
174         fprintf(stderr, "Interface %.16s has MTU of %d -- should be %d.\n",
175               ifname, ifr.ifr_mtu, ETH_DATA_LEN);
176         fprintf(stderr, "You may have serious connection problems.\n");
177     }
178
179 #ifdef HAVE_STRUCT_SOCKADDR_LL
180     /* Get interface index */
181     sa.sll_family = AF_PACKET;
182     sa.sll_protocol = htons(type);
183
184     strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
185     if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
186         fatalSys("ioctl(SIOCFIGINDEX): Could not get interface index");
187     }
188     sa.sll_ifindex = ifr.ifr_ifindex;
189
190 #else
191     strcpy(sa.sa_data, ifname);
192 #endif
193
194     /* We're only interested in packets on specified interface */
195     if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
196         fatalSys("bind");
197     }
198
199     return fd;
200 }
201
202
203 /***********************************************************************
204 *%FUNCTION: sendPacket
205 *%ARGUMENTS:
206 * sock -- socket to send to
207 * pkt -- the packet to transmit
208 * size -- size of packet (in bytes)
209 *%RETURNS:
210 * 0 on success; -1 on failure
211 *%DESCRIPTION:
212 * Transmits a packet
213 ***********************************************************************/
214 int
215 sendPacket(PPPoEConnection *conn, int sock, PPPoEPacket *pkt, int size)
216 {
217 #if defined(HAVE_STRUCT_SOCKADDR_LL)
218     if (send(sock, pkt, size, 0) < 0) {
219         sysErr("send (sendPacket)");
220         return -1;
221     }
222 #else
223     struct sockaddr sa;
224
225     if (!conn) {
226         rp_fatal("relay and server not supported on Linux 2.0 kernels");
227     }
228     strcpy(sa.sa_data, conn->ifName);
229     if (sendto(sock, pkt, size, 0, &sa, sizeof(sa)) < 0) {
230         sysErr("sendto (sendPacket)");
231         return -1;
232     }
233 #endif
234     return 0;
235 }
236
237 /***********************************************************************
238 *%FUNCTION: receivePacket
239 *%ARGUMENTS:
240 * sock -- socket to read from
241 * pkt -- place to store the received packet
242 * size -- set to size of packet in bytes
243 *%RETURNS:
244 * >= 0 if all OK; < 0 if error
245 *%DESCRIPTION:
246 * Receives a packet
247 ***********************************************************************/
248 int
249 receivePacket(int sock, PPPoEPacket *pkt, int *size)
250 {
251     if ((*size = recv(sock, pkt, sizeof(PPPoEPacket), 0)) < 0) {
252         sysErr("recv (receivePacket)");
253         return -1;
254     }
255     return 0;
256 }
257
258 /**********************************************************************
259 *%FUNCTION: parsePacket
260 *%ARGUMENTS:
261 * packet -- the PPPoE discovery packet to parse
262 * func -- function called for each tag in the packet
263 * extra -- an opaque data pointer supplied to parsing function
264 *%RETURNS:
265 * 0 if everything went well; -1 if there was an error
266 *%DESCRIPTION:
267 * Parses a PPPoE discovery packet, calling "func" for each tag in the packet.
268 * "func" is passed the additional argument "extra".
269 ***********************************************************************/
270 int
271 parsePacket(PPPoEPacket *packet, ParseFunc *func, void *extra)
272 {
273     UINT16_t len = ntohs(packet->length);
274     unsigned char *curTag;
275     UINT16_t tagType, tagLen;
276
277     if (PPPOE_VER(packet->vertype) != 1) {
278         fprintf(stderr, "Invalid PPPoE version (%d)\n",
279                 PPPOE_VER(packet->vertype));
280         return -1;
281     }
282     if (PPPOE_TYPE(packet->vertype) != 1) {
283         fprintf(stderr, "Invalid PPPoE type (%d)\n",
284                 PPPOE_TYPE(packet->vertype));
285         return -1;
286     }
287
288     /* Do some sanity checks on packet */
289     if (len > ETH_JUMBO_LEN - PPPOE_OVERHEAD) { /* 6-byte overhead for PPPoE header */
290         fprintf(stderr, "Invalid PPPoE packet length (%u)\n", len);
291         return -1;
292     }
293
294     /* Step through the tags */
295     curTag = packet->payload;
296     while(curTag - packet->payload < len) {
297         /* Alignment is not guaranteed, so do this by hand... */
298         tagType = (curTag[0] << 8) + curTag[1];
299         tagLen = (curTag[2] << 8) + curTag[3];
300         if (tagType == TAG_END_OF_LIST) {
301             return 0;
302         }
303         if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
304             fprintf(stderr, "Invalid PPPoE tag length (%u)\n", tagLen);
305             return -1;
306         }
307         func(tagType, tagLen, curTag+TAG_HDR_SIZE, extra);
308         curTag = curTag + TAG_HDR_SIZE + tagLen;
309     }
310     return 0;
311 }
312
313 /**********************************************************************
314 *%FUNCTION: parseForHostUniq
315 *%ARGUMENTS:
316 * type -- tag type
317 * len -- tag length
318 * data -- tag data.
319 * extra -- user-supplied pointer.  This is assumed to be a pointer to int.
320 *%RETURNS:
321 * Nothing
322 *%DESCRIPTION:
323 * If a HostUnique tag is found which matches our PID, sets *extra to 1.
324 ***********************************************************************/
325 void
326 parseForHostUniq(UINT16_t type, UINT16_t len, unsigned char *data,
327                  void *extra)
328 {
329     int *val = (int *) extra;
330     if (type == TAG_HOST_UNIQ && len == sizeof(pid_t)) {
331         pid_t tmp;
332         memcpy(&tmp, data, len);
333         if (tmp == getpid()) {
334             *val = 1;
335         }
336     }
337 }
338
339 /**********************************************************************
340 *%FUNCTION: packetIsForMe
341 *%ARGUMENTS:
342 * conn -- PPPoE connection info
343 * packet -- a received PPPoE packet
344 *%RETURNS:
345 * 1 if packet is for this PPPoE daemon; 0 otherwise.
346 *%DESCRIPTION:
347 * If we are using the Host-Unique tag, verifies that packet contains
348 * our unique identifier.
349 ***********************************************************************/
350 int
351 packetIsForMe(PPPoEConnection *conn, PPPoEPacket *packet)
352 {
353     int forMe = 0;
354
355     /* If packet is not directed to our MAC address, forget it */
356     if (memcmp(packet->ethHdr.h_dest, conn->myEth, ETH_ALEN)) return 0;
357
358     /* If we're not using the Host-Unique tag, then accept the packet */
359     if (!conn->useHostUniq) return 1;
360
361     parsePacket(packet, parseForHostUniq, &forMe);
362     return forMe;
363 }
364
365 /**********************************************************************
366 *%FUNCTION: parsePADOTags
367 *%ARGUMENTS:
368 * type -- tag type
369 * len -- tag length
370 * data -- tag data
371 * extra -- extra user data.  Should point to a PacketCriteria structure
372 *          which gets filled in according to selected AC name and service
373 *          name.
374 *%RETURNS:
375 * Nothing
376 *%DESCRIPTION:
377 * Picks interesting tags out of a PADO packet
378 ***********************************************************************/
379 void
380 parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data,
381               void *extra)
382 {
383     struct PacketCriteria *pc = (struct PacketCriteria *) extra;
384     PPPoEConnection *conn = pc->conn;
385     int i;
386
387     switch(type) {
388     case TAG_AC_NAME:
389         pc->seenACName = 1;
390         printf("Access-Concentrator: %.*s\n", (int) len, data);
391         if (conn->acName && len == strlen(conn->acName) &&
392             !strncmp((char *) data, conn->acName, len)) {
393             pc->acNameOK = 1;
394         }
395         break;
396     case TAG_SERVICE_NAME:
397         pc->seenServiceName = 1;
398         if (len > 0) {
399             printf("       Service-Name: %.*s\n", (int) len, data);
400         }
401         if (conn->serviceName && len == strlen(conn->serviceName) &&
402             !strncmp((char *) data, conn->serviceName, len)) {
403             pc->serviceNameOK = 1;
404         }
405         break;
406     case TAG_AC_COOKIE:
407         printf("Got a cookie:");
408         /* Print first 20 bytes of cookie */
409         for (i=0; i<len && i < 20; i++) {
410             printf(" %02x", (unsigned) data[i]);
411         }
412         if (i < len) printf("...");
413         printf("\n");
414         conn->cookie.type = htons(type);
415         conn->cookie.length = htons(len);
416         memcpy(conn->cookie.payload, data, len);
417         break;
418     case TAG_RELAY_SESSION_ID:
419         printf("Got a Relay-ID:");
420         /* Print first 20 bytes of relay ID */
421         for (i=0; i<len && i < 20; i++) {
422             printf(" %02x", (unsigned) data[i]);
423         }
424         if (i < len) printf("...");
425         printf("\n");
426         conn->relayId.type = htons(type);
427         conn->relayId.length = htons(len);
428         memcpy(conn->relayId.payload, data, len);
429         break;
430     case TAG_SERVICE_NAME_ERROR:
431         printf("Got a Service-Name-Error tag: %.*s\n", (int) len, data);
432         break;
433     case TAG_AC_SYSTEM_ERROR:
434         printf("Got a System-Error tag: %.*s\n", (int) len, data);
435         break;
436     case TAG_GENERIC_ERROR:
437         printf("Got a Generic-Error tag: %.*s\n", (int) len, data);
438         break;
439     }
440 }
441
442 /***********************************************************************
443 *%FUNCTION: sendPADI
444 *%ARGUMENTS:
445 * conn -- PPPoEConnection structure
446 *%RETURNS:
447 * Nothing
448 *%DESCRIPTION:
449 * Sends a PADI packet
450 ***********************************************************************/
451 void
452 sendPADI(PPPoEConnection *conn)
453 {
454     PPPoEPacket packet;
455     unsigned char *cursor = packet.payload;
456     PPPoETag *svc = (PPPoETag *) (&packet.payload);
457     UINT16_t namelen = 0;
458     UINT16_t plen;
459
460     if (conn->serviceName) {
461         namelen = (UINT16_t) strlen(conn->serviceName);
462     }
463     plen = TAG_HDR_SIZE + namelen;
464     CHECK_ROOM(cursor, packet.payload, plen);
465
466     /* Set destination to Ethernet broadcast address */
467     memset(packet.ethHdr.h_dest, 0xFF, ETH_ALEN);
468     memcpy(packet.ethHdr.h_source, conn->myEth, ETH_ALEN);
469
470     packet.ethHdr.h_proto = htons(Eth_PPPOE_Discovery);
471     packet.vertype = PPPOE_VER_TYPE(1, 1);
472     packet.code = CODE_PADI;
473     packet.session = 0;
474
475     svc->type = TAG_SERVICE_NAME;
476     svc->length = htons(namelen);
477     CHECK_ROOM(cursor, packet.payload, namelen+TAG_HDR_SIZE);
478
479     if (conn->serviceName) {
480         memcpy(svc->payload, conn->serviceName, strlen(conn->serviceName));
481     }
482     cursor += namelen + TAG_HDR_SIZE;
483
484     /* If we're using Host-Uniq, copy it over */
485     if (conn->useHostUniq) {
486         PPPoETag hostUniq;
487         pid_t pid = getpid();
488         hostUniq.type = htons(TAG_HOST_UNIQ);
489         hostUniq.length = htons(sizeof(pid));
490         memcpy(hostUniq.payload, &pid, sizeof(pid));
491         CHECK_ROOM(cursor, packet.payload, sizeof(pid) + TAG_HDR_SIZE);
492         memcpy(cursor, &hostUniq, sizeof(pid) + TAG_HDR_SIZE);
493         cursor += sizeof(pid) + TAG_HDR_SIZE;
494         plen += sizeof(pid) + TAG_HDR_SIZE;
495     }
496
497     packet.length = htons(plen);
498
499     sendPacket(conn, conn->discoverySocket, &packet, (int) (plen + HDR_SIZE));
500     if (conn->debugFile) {
501         dumpPacket(conn->debugFile, &packet, "SENT");
502         fprintf(conn->debugFile, "\n");
503         fflush(conn->debugFile);
504     }
505 }
506
507 /**********************************************************************
508 *%FUNCTION: waitForPADO
509 *%ARGUMENTS:
510 * conn -- PPPoEConnection structure
511 * timeout -- how long to wait (in seconds)
512 *%RETURNS:
513 * Nothing
514 *%DESCRIPTION:
515 * Waits for a PADO packet and copies useful information
516 ***********************************************************************/
517 void
518 waitForPADO(PPPoEConnection *conn, int timeout)
519 {
520     fd_set readable;
521     int r;
522     struct timeval tv;
523     PPPoEPacket packet;
524     int len;
525
526     struct PacketCriteria pc;
527     pc.conn          = conn;
528     pc.acNameOK      = (conn->acName)      ? 0 : 1;
529     pc.serviceNameOK = (conn->serviceName) ? 0 : 1;
530     pc.seenACName    = 0;
531     pc.seenServiceName = 0;
532     conn->error = 0;
533         
534     do {
535         if (BPF_BUFFER_IS_EMPTY) {
536             tv.tv_sec = timeout;
537             tv.tv_usec = 0;
538         
539             FD_ZERO(&readable);
540             FD_SET(conn->discoverySocket, &readable);
541
542             while(1) {
543                 r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
544                 if (r >= 0 || errno != EINTR) break;
545             }
546             if (r < 0) {
547                 perror("select (waitForPADO)");
548                 return;
549             }
550             if (r == 0) return;        /* Timed out */
551         }
552         
553         /* Get the packet */
554         receivePacket(conn->discoverySocket, &packet, &len);
555
556         /* Check length */
557         if (ntohs(packet.length) + HDR_SIZE > len) {
558             fprintf(stderr, "Bogus PPPoE length field (%u)\n",
559                    (unsigned int) ntohs(packet.length));
560             continue;
561         }
562
563 #ifdef USE_BPF
564         /* If it's not a Discovery packet, loop again */
565         if (etherType(&packet) != Eth_PPPOE_Discovery) continue;
566 #endif
567
568         if (conn->debugFile) {
569             dumpPacket(conn->debugFile, &packet, "RCVD");
570             fprintf(conn->debugFile, "\n");
571             fflush(conn->debugFile);
572         }
573         /* If it's not for us, loop again */
574         if (!packetIsForMe(conn, &packet)) continue;
575
576         if (packet.code == CODE_PADO) {
577             if (BROADCAST(packet.ethHdr.h_source)) {
578                 fprintf(stderr, "Ignoring PADO packet from broadcast MAC address\n");
579                 continue;
580             }
581             parsePacket(&packet, parsePADOTags, &pc);
582             if (conn->error)
583                 return;
584             if (!pc.seenACName) {
585                 fprintf(stderr, "Ignoring PADO packet with no AC-Name tag\n");
586                 continue;
587             }
588             if (!pc.seenServiceName) {
589                 fprintf(stderr, "Ignoring PADO packet with no Service-Name tag\n");
590                 continue;
591             }
592             conn->numPADOs++;
593             printf("--------------------------------------------------\n");
594             if (pc.acNameOK && pc.serviceNameOK) {
595                 memcpy(conn->peerEth, packet.ethHdr.h_source, ETH_ALEN);
596                 if (conn->printACNames) {
597                     printf("AC-Ethernet-Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
598                            (unsigned) conn->peerEth[0], 
599                            (unsigned) conn->peerEth[1],
600                            (unsigned) conn->peerEth[2],
601                            (unsigned) conn->peerEth[3],
602                            (unsigned) conn->peerEth[4],
603                            (unsigned) conn->peerEth[5]);
604                     continue;
605                 }
606                 conn->discoveryState = STATE_RECEIVED_PADO;
607                 break;
608             }
609         }
610     } while (conn->discoveryState != STATE_RECEIVED_PADO);
611 }
612
613 /**********************************************************************
614 *%FUNCTION: discovery
615 *%ARGUMENTS:
616 * conn -- PPPoE connection info structure
617 *%RETURNS:
618 * Nothing
619 *%DESCRIPTION:
620 * Performs the PPPoE discovery phase
621 ***********************************************************************/
622 void
623 discovery(PPPoEConnection *conn)
624 {
625     int padiAttempts = 0;
626     int timeout = PADI_TIMEOUT;
627
628     conn->discoverySocket =
629         openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth);
630
631     do {
632         padiAttempts++;
633         if (padiAttempts > MAX_PADI_ATTEMPTS) {
634             fprintf(stderr, "Timeout waiting for PADO packets\n");
635             close(conn->discoverySocket);
636             conn->discoverySocket = -1;
637             return;
638         }
639         sendPADI(conn);
640         conn->discoveryState = STATE_SENT_PADI;
641         waitForPADO(conn, timeout);
642     } while (!conn->numPADOs);
643 }
644
645 int main(int argc, char *argv[])
646 {
647     int opt;
648     PPPoEConnection *conn;
649
650     conn = malloc(sizeof(PPPoEConnection));
651     if (!conn)
652         fatalSys("malloc");
653
654     memset(conn, 0, sizeof(PPPoEConnection));
655
656     while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) {
657         switch(opt) {
658         case 'S':
659             conn->serviceName = xstrdup(optarg);
660             break;
661         case 'C':
662             conn->acName = xstrdup(optarg);
663             break;
664         case 'U':
665             conn->useHostUniq = 1;
666             break;
667         case 'D':
668             conn->debugFile = fopen(optarg, "w");
669             if (!conn->debugFile) {
670                 fprintf(stderr, "Could not open %s: %s\n",
671                         optarg, strerror(errno));
672                 exit(1);
673             }
674             fprintf(conn->debugFile, "pppoe-discovery %s\n", RP_VERSION);
675             break;
676         case 'I':
677             conn->ifName = xstrdup(optarg);
678             break;
679         case 'A':
680             /* this is the default */
681             break;
682         case 'V':
683         case 'h':
684             usage();
685             exit(0);
686         default:
687             usage();
688             exit(1);
689         }
690     }
691
692     /* default interface name */
693     if (!conn->ifName)
694         conn->ifName = strdup("eth0");
695
696     conn->discoverySocket = -1;
697     conn->sessionSocket = -1;
698     conn->printACNames = 1;
699
700     discovery(conn);
701     exit(0);
702 }
703
704 void rp_fatal(char const *str)
705 {
706     fprintf(stderr, "%s\n", str);
707     exit(1);
708 }
709
710 void fatalSys(char const *str)
711 {
712     perror(str);
713     exit(1);
714 }
715
716 void sysErr(char const *str)
717 {
718     rp_fatal(str);
719 }
720
721 char *xstrdup(const char *s)
722 {
723     register char *ret = strdup(s);
724     if (!ret)
725         sysErr("strdup");
726     return ret;
727 }
728
729 void usage(void)
730 {
731     fprintf(stderr, "Usage: pppoe-discovery [options]\n");
732     fprintf(stderr, "\nVersion " RP_VERSION "\n");
733 }