]> git.ozlabs.org Git - ppp.git/commitdiff
remove a couple of ansi-C-isms.
authorPaul Mackerras <paulus@samba.org>
Fri, 19 Mar 1999 04:23:54 +0000 (04:23 +0000)
committerPaul Mackerras <paulus@samba.org>
Fri, 19 Mar 1999 04:23:54 +0000 (04:23 +0000)
loop_frame is needed by some sys-*.c.
print connect time and bytes transferred on close;
added get_ppp_stats to sys-*.c.

13 files changed:
pppd/demand.c
pppd/ipcp.c
pppd/main.c
pppd/options.c
pppd/pppd.h
pppd/sys-NeXT.c
pppd/sys-aix4.c
pppd/sys-bsd.c
pppd/sys-linux.c
pppd/sys-osf.c
pppd/sys-sunos4.c
pppd/sys-svr4.c
pppd/sys-ultrix.c

index 86c176e607f89965f91f889ef9266a4a6405ca61..cfae882f64afd0f279bf14505ade821ea3a7aba4 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: demand.c,v 1.9 1999/03/19 01:21:28 paulus Exp $";
+static char rcsid[] = "$Id: demand.c,v 1.10 1999/03/19 04:23:38 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -62,7 +62,6 @@ struct packet *pend_q;
 struct packet *pend_qtail;
 
 static int active_packet __P((unsigned char *, int));
-static int loop_frame __P((unsigned char *, int));
 
 /*
  * demand_conf - configure the interface for doing dial-on-demand.
@@ -255,7 +254,7 @@ loop_chars(p, n)
  * We apply the active_filter to see if we want this packet to
  * bring up the link.
  */
-static int
+int
 loop_frame(frame, len)
     unsigned char *frame;
     int len;
index 6e0346b77df1a9e919151dd977081b12057dc3db..41eabd2192ed0363394a5bc6e611ec80d43dff2f 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: ipcp.c,v 1.42 1999/03/19 01:19:31 paulus Exp $";
+static char rcsid[] = "$Id: ipcp.c,v 1.43 1999/03/19 04:23:39 paulus Exp $";
 #endif
 
 /*
@@ -1520,6 +1520,8 @@ ipcp_down(f)
     fsm *f;
 {
     IPCPDEBUG(("ipcp: down"));
+    if (get_ppp_stats(f->unit, &link_stats))
+       link_stats_valid = 1;
     if (ipcp_is_up) {
        ipcp_is_up = 0;
        np_down(f->unit, PPP_IP);
index 555ef957f9326c2bc8709cb6b15daf0e3403dc9b..7ad8d3f1d29fd52c683ccdbcd0369bb27ae5976f 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: main.c,v 1.62 1999/03/19 01:26:41 paulus Exp $";
+static char rcsid[] = "$Id: main.c,v 1.63 1999/03/19 04:23:40 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -115,6 +115,11 @@ char *no_ppp_msg = "Sorry - this system lacks PPP kernel support\n";
 GIDSET_TYPE groups[NGROUPS_MAX];/* groups the user is in */
 int ngroups;                   /* How many groups valid in groups */
 
+static struct timeval start_time;      /* Time when link was started. */
+
+struct ppp_stats link_stats;
+int link_stats_valid;
+
 /* Prototypes for procedures local to this file. */
 
 static void create_pidfile __P((void));
@@ -190,6 +195,7 @@ main(argc, argv)
     struct protent *protp;
     struct stat statbuf;
     char numbuf[16];
+    struct timeval now;
 
     phase = PHASE_INITIALIZE;
     p = ttyname(0);
@@ -562,6 +568,7 @@ main(argc, argv)
         * incoming events (reply, timeout, etc.).
         */
        notice("Connect: %s <--> %s", ifname, devnam);
+       gettimeofday(&start_time, NULL);
        lcp_lowerup(0);
        lcp_open(0);            /* Start protocol */
        open_ccp_flag = 0;
@@ -594,6 +601,19 @@ main(argc, argv)
            reap_kids();        /* Don't leave dead kids lying around */
        }
 
+       /*
+        * Print connect time and statistics.
+        */
+       if (gettimeofday(&now, NULL) >= 0) {
+           int t = now.tv_sec - start_time.tv_sec;
+           t = (t + 5) / 6;    /* now in 1/10ths of minutes */
+           info("Connect time %d.%d minutes", t/10, t%10);
+       }
+       if (link_stats_valid) {
+           info("Send %d bytes, received %d bytes",
+                link_stats.p.ppp_obytes, link_stats.p.ppp_ibytes);
+       }
+
        /*
         * If we may want to bring the link up again, transfer
         * the ppp unit back to the loopback.  Set the
@@ -1883,7 +1903,10 @@ script_unsetenv(var)
  * always leaves destination null-terminated (for len > 0).
  */
 size_t
-strlcpy(char *dest, const char *src, size_t len)
+strlcpy(dest, src, len)
+    char *dest;
+    const char *src;
+    size_t len;
 {
     size_t ret = strlen(src);
 
@@ -1903,7 +1926,10 @@ strlcpy(char *dest, const char *src, size_t len)
  * always leaves destination null-terminated (for len > 0).
  */
 size_t
-strlcat(char *dest, const char *src, size_t len)
+strlcat(dest, src, len)
+    char *dest;
+    const char *src;
+    size_t len;
 {
     size_t dlen = strlen(dest);
 
index c502f5b9984a53c4ec6da4fc3d07f63e71b76dcb..53456cc8d13ead6754a11e37b39c12724777d465 100644 (file)
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: options.c,v 1.52 1999/03/19 01:27:43 paulus Exp $";
+static char rcsid[] = "$Id: options.c,v 1.53 1999/03/19 04:23:44 paulus Exp $";
 #endif
 
 #include <ctype.h>
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
-#include <limits.h>
 #include <stdlib.h>
 #include <termios.h>
 #include <syslog.h>
index a01a52b935909a514f6d0bc64fb7c0ab461dd660..60ef281681957cf7810cc188c438027b0de4a67d 100644 (file)
@@ -16,7 +16,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: pppd.h,v 1.32 1999/03/19 01:28:27 paulus Exp $
+ * $Id: pppd.h,v 1.33 1999/03/19 04:23:45 paulus Exp $
  */
 
 /*
@@ -27,6 +27,7 @@
 #define __PPPD_H__
 
 #include <stdio.h>             /* for FILE */
+#include <limits.h>            /* for NGROUPS_MAX */
 #include <sys/param.h>         /* for MAXPATHLEN and BSD4_4, if defined */
 #include <sys/types.h>         /* for u_int32_t, if defined */
 #include <sys/time.h>          /* for struct timeval */
@@ -130,6 +131,8 @@ extern char **script_env;   /* Environment variables for scripts */
 extern int     detached;       /* Have detached from controlling tty */
 extern GIDSET_TYPE groups[NGROUPS_MAX];        /* groups the user is in */
 extern int     ngroups;        /* How many groups valid in groups */
+extern struct ppp_stats link_stats; /* byte/packet counts etc. for link */
+extern int     link_stats_valid; /* set if link_stats is valid */
 
 /*
  * Variables set by command-line options.
@@ -302,6 +305,7 @@ void demand_unblock __P((void)); /* set all NPs to pass packets */
 void demand_discard __P((void)); /* set all NPs to discard packets */
 void demand_rexmit __P((int)); /* retransmit saved frames for an NP */
 int  loop_chars __P((unsigned char *, int)); /* process chars from loopback */
+int  loop_frame __P((unsigned char *, int)); /* should we bring link up? */
 
 /* Procedures exported from sys-*.c */
 void sys_init __P((void));     /* Do system-dependent initialization */
@@ -337,6 +341,8 @@ void ccp_flags_set __P((int, int, int));
 int  ccp_fatal_error __P((int)); /* Test for fatal decomp error in kernel */
 int  get_idle_time __P((int, struct ppp_idle *));
                                /* Find out how long link has been idle */
+int  get_ppp_stats __P((int, struct ppp_stats *));
+                               /* Return link statistics */
 int  sifvjcomp __P((int, int, int, int));
                                /* Configure VJ TCP header compression */
 int  sifup __P((int));         /* Configure i/f up (for IP) */
index 0a6645e4d75186b7e3d997b796acb3f0bca1a5e4..7db81d4a43038954cccde98426018319232680b6 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-NeXT.c,v 1.15 1999/03/19 01:29:40 paulus Exp $";
+static char rcsid[] = "$Id: sys-NeXT.c,v 1.16 1999/03/19 04:23:46 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -541,7 +541,8 @@ wait_input(timo)
 /*
  * add_fd - add an fd to the set that wait_input waits for.
  */
-void add_fd(int fd)
+void add_fd(fd)
+    int fd;
 {
     FD_SET(fd, &in_fds);
     if (fd > max_in_fd)
@@ -551,7 +552,8 @@ void add_fd(int fd)
 /*
  * remove_fd - remove an fd from the set that wait_input waits for.
  */
-void remove_fd(int fd)
+void remove_fd(fd)
+    int fd;
 {
     FD_CLR(fd, &in_fds);
 }
@@ -1447,6 +1449,26 @@ get_idle_time(u, ip)
   return (ioctl(ttyfd, PPPIOCGIDLE, ip) >= 0); 
 }
 
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+    int u;
+    struct ppp_stats *stats;
+{
+    struct ifpppstatsreq req;
+
+    memset (&req, 0, sizeof (req));
+    strlcpy(req.ifr_name, interface, sizeof(req.ifr_name));
+    if (ioctl(sockfd, SIOCGPPPSTATS, &req) < 0) {
+       error("Couldn't get PPP statistics: %m");
+       return 0;
+    }
+    *stats = req.stats;
+    return 1;
+}
+
 
 /*
  * get_loop_output - read characters from the loopback, form them
index fbe9bccf870f9c9374e04fa3b8c45f9ac75acb82..e797c54e5f5ed1e63dbb3ead91ddb63e6839df27 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-aix4.c,v 1.18 1999/03/19 01:29:40 paulus Exp $";
+static char rcsid[] = "$Id: sys-aix4.c,v 1.19 1999/03/19 04:23:46 paulus Exp $";
 #endif
 
 /*
@@ -581,7 +581,8 @@ wait_input(timo)
 /*
  * add_fd - add an fd to the set that wait_input waits for.
  */
-void add_fd(int fd)
+void add_fd(fd)
+    int fd;
 {
     int n;
 
@@ -599,7 +600,8 @@ void add_fd(int fd)
 /*
  * remove_fd - remove an fd from the set that wait_input waits for.
  */
-void remove_fd(int fd)
+void remove_fd(fd)
+    int fd;
 {
     int n;
 
index 717bcfed7f9b1564c127484444ff8fbef36dfeef..d59f073ca8e64c34dc8ffe5a3535d3eafb30507f 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-bsd.c,v 1.39 1999/03/19 01:29:44 paulus Exp $";
+static char rcsid[] = "$Id: sys-bsd.c,v 1.40 1999/03/19 04:23:47 paulus Exp $";
 /*     $NetBSD: sys-bsd.c,v 1.1.1.3 1997/09/26 18:53:04 christos Exp $ */
 #endif
 
@@ -559,7 +559,8 @@ wait_input(timo)
 /*
  * add_fd - add an fd to the set that wait_input waits for.
  */
-void add_fd(int fd)
+void add_fd(fd)
+    int fd;
 {
     FD_SET(fd, &in_fds);
     if (fd > max_in_fd)
@@ -569,7 +570,8 @@ void add_fd(int fd)
 /*
  * remove_fd - remove an fd from the set that wait_input waits for.
  */
-void remove_fd(int fd)
+void remove_fd(fd)
+    int fd;
 {
     FD_CLR(fd, &in_fds);
 }
@@ -790,6 +792,26 @@ get_idle_time(u, ip)
     return ioctl(ppp_fd, PPPIOCGIDLE, ip) >= 0;
 }
 
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+    int u;
+    struct ppp_stats *stats;
+{
+    struct ifpppstatsreq req;
+
+    memset (&req, 0, sizeof (req));
+    strlcpy(req.ifr_name, interface, sizeof(req.ifr_name));
+    if (ioctl(sockfd, SIOCGPPPSTATS, &req) < 0) {
+       error("Couldn't get PPP statistics: %m");
+       return 0;
+    }
+    *stats = req.stats;
+    return 1;
+}
+
 
 #ifdef PPP_FILTER
 /*
index 3a5890aac284d4c18aab89d18ffb51edfa541f1a..a7fd168b0e8e06ec1b05e831cde69cb769e8d5bf 100644 (file)
@@ -964,6 +964,29 @@ get_idle_time(u, ip)
     return ioctl(ppp_fd, PPPIOCGIDLE, ip) >= 0;
 } 
 
+/********************************************************************
+ *
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+    int u;
+    struct ppp_stats *stats;
+{
+    struct ifpppstatsreq req;
+
+    memset (&req, 0, sizeof (req));
+
+    req.stats_ptr = (caddr_t) &req.stats;
+    strlcpy(req.ifr__name, ifname, sizeof(req.ifr__name));
+    if (ioctl(sock_fd, SIOCGPPPSTATS, &req) < 0) {
+       error("Couldn't get PPP statistics: %m");
+       return 0;
+    }
+    *stats = req.stats;
+    return 1;
+} 
+
 /********************************************************************
  *
  * ccp_fatal_error - returns 1 if decompression was disabled as a
index 30930b25743cccf6d7c78efe366dc5aac111a751..c25e33921afdc3eb4b1139d11748c02b9e837304 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-osf.c,v 1.21 1999/03/19 01:29:46 paulus Exp $";
+static char rcsid[] = "$Id: sys-osf.c,v 1.22 1999/03/19 04:23:49 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -754,7 +754,8 @@ wait_input(timo)
 /*
  * add_fd - add an fd to the set that wait_input waits for.
  */
-void add_fd(int fd)
+void add_fd(fd)
+    int fd;
 {
     int n;
 
@@ -772,7 +773,8 @@ void add_fd(int fd)
 /*
  * remove_fd - remove an fd from the set that wait_input waits for.
  */
-void remove_fd(int fd)
+void remove_fd(fd)
+    int fd;
 {
     int n;
 
@@ -1009,6 +1011,21 @@ get_idle_time(u, ip)
     return strioctl(pppfd, PPPIO_GIDLE, ip, 0, sizeof(struct ppp_idle)) >= 0;
 }
 
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+    int u;
+    struct ppp_stats *stats;
+{
+    if (strioctl(pppfd, PPPIO_GETSTAT, stats, 0, sizeof(*stats)) < 0) {
+       error("Couldn't get link statistics: %m");
+       return 0;
+    }
+    return 1;
+}
+
 
 /*
  * ccp_fatal_error - returns 1 if decompression was disabled as a
index ba2cc3c7953cd1e57071567464221018575863f1..8a1847faed8d67048b4798faa49a06c4d1ee5350 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-sunos4.c,v 1.16 1999/03/19 01:29:47 paulus Exp $";
+static char rcsid[] = "$Id: sys-sunos4.c,v 1.17 1999/03/19 04:23:50 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -617,6 +617,44 @@ wait_input(timo)
        fatal("poll: %m");
 }
 
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(fd)
+    int fd;
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n)
+       if (pollfds[n].fd == fd)
+           return;
+    if (n_pollfds < MAX_POLLFDS) {
+       pollfds[n_pollfds].fd = fd;
+       pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP;
+       ++n_pollfds;
+    } else
+       error("Too many inputs!");
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(fd)
+    int fd;
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n) {
+       if (pollfds[n].fd == fd) {
+           while (++n < n_pollfds)
+               pollfds[n-1] = pollfds[n];
+           --n_pollfds;
+           break;
+       }
+    }
+}
+
+#if 0
 /*
  * wait_loop_output - wait until there is data available on the
  * loopback, for the length of time specified by *timo (indefinite
@@ -643,7 +681,7 @@ wait_time(timo)
     if (n < 0 && errno != EINTR)
        fatal("select: %m");
 }
-
+#endif
 
 /*
  * read_packet - get a PPP packet from the serial device.
@@ -821,6 +859,21 @@ get_idle_time(u, ip)
     return strioctl(pppfd, PPPIO_GIDLE, ip, 0, sizeof(struct ppp_idle)) >= 0;
 }
 
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+    int u;
+    struct ppp_stats *stats;
+{
+    if (strioctl(pppfd, PPPIO_GETSTAT, stats, 0, sizeof(*stats)) < 0) {
+       error("Couldn't get link statistics: %m");
+       return 0;
+    }
+    return 1;
+}
+
 
 /*
  * ccp_fatal_error - returns 1 if decompression was disabled as a
index c87c9d060e763cde474fd94b3a4f38b90713077b..461e53640979373dbe328928a5c591fec4da4784 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-svr4.c,v 1.27 1999/03/19 01:29:50 paulus Exp $";
+static char rcsid[] = "$Id: sys-svr4.c,v 1.28 1999/03/19 04:23:52 paulus Exp $";
 #endif
 
 #include <limits.h>
@@ -683,7 +683,8 @@ wait_input(timo)
 /*
  * add_fd - add an fd to the set that wait_input waits for.
  */
-void add_fd(int fd)
+void add_fd(fd)
+    int fd;
 {
     int n;
 
@@ -701,7 +702,8 @@ void add_fd(int fd)
 /*
  * remove_fd - remove an fd from the set that wait_input waits for.
  */
-void remove_fd(int fd)
+void remove_fd(fd)
+    int fd;
 {
     int n;
 
@@ -930,6 +932,21 @@ get_idle_time(u, ip)
     return strioctl(pppfd, PPPIO_GIDLE, ip, 0, sizeof(struct ppp_idle)) >= 0;
 }
 
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+    int u;
+    struct ppp_stats *stats;
+{
+    if (strioctl(pppfd, PPPIO_GETSTAT, stats, 0, sizeof(*stats)) < 0) {
+       error("Couldn't get link statistics: %m");
+       return 0;
+    }
+    return 1;
+}
+
 #if 0
 /*
  * set_filters - transfer the pass and active filters to the kernel.
index e4ed3e7f0ab0b85d0e9bd68267cc80d69e72cc05..82783be2095474dc89337f33e078bcd093d183dc 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-ultrix.c,v 1.28 1999/03/19 01:29:51 paulus Exp $";
+static char rcsid[] = "$Id: sys-ultrix.c,v 1.29 1999/03/19 04:23:54 paulus Exp $";
 #endif
 
 /*
@@ -586,7 +586,8 @@ wait_input(timo)
 /*
  * add_fd - add an fd to the set that wait_input waits for.
  */
-void add_fd(int fd)
+void add_fd(fd)
+    int fd;
 {
     FD_SET(fd, &in_fds);
     if (fd > max_in_fd)
@@ -596,7 +597,8 @@ void add_fd(int fd)
 /*
  * remove_fd - remove an fd from the set that wait_input waits for.
  */
-void remove_fd(int fd)
+void remove_fd(fd)
+    int fd;
 {
     FD_CLR(fd, &in_fds);
 }
@@ -793,6 +795,26 @@ get_idle_time(u, ip)
     return ioctl(ppp_fd, PPPIOCGIDLE, ip) >= 0;
 }
 
+/*
+ * get_ppp_stats - return statistics for the link.
+ */
+int
+get_ppp_stats(u, stats)
+    int u;
+    struct ppp_stats *stats;
+{
+    struct ifpppstatsreq req;
+
+    memset (&req, 0, sizeof (req));
+    strlcpy(req.ifr_name, interface, sizeof(req.ifr_name));
+    if (ioctl(sockfd, SIOCGPPPSTATS, &req) < 0) {
+       error("Couldn't get PPP statistics: %m");
+       return 0;
+    }
+    *stats = req.stats;
+    return 1;
+}
+
 
 /*
  * sifvjcomp - config tcp header compression