}
if (x < 0)
error("Couldn't create new ppp unit: %m");
+
+ if (x == 0 && req_ifname[0] != '\0') {
+ struct ifreq ifr;
+ char t[MAXIFNAMELEN];
+ memset(&ifr, 0, sizeof(struct ifreq));
+ slprintf(t, sizeof(t), "%s%d", PPP_DRV_NAME, ifunit);
+ strncpy(ifr.ifr_name, t, IF_NAMESIZE);
+ strncpy(ifr.ifr_newname, req_ifname, IF_NAMESIZE);
+ x = ioctl(sock_fd, SIOCSIFNAME, &ifr);
+ if (x < 0)
+ error("Couldn't rename interface %s to %s: %m", t, req_ifname);
+ else
+ info("Renamed interface %s to %s", t, req_ifname);
+ }
+
return x;
}
}
}
- close (s);
if (!ok) {
slprintf(route_buffer, sizeof(route_buffer),
"Sorry - PPP driver version %d.%d.%d is out of date\n",
}
}
}
+ close(s);
return ok;
}
warn("Couldn't unlock pty slave %s: %m", pty_name);
#endif
if ((sfd = open(pty_name, O_RDWR | O_NOCTTY)) < 0)
+ {
warn("Couldn't open pty slave %s: %m", pty_name);
+ close(mfd);
+ }
}
}
#endif /* TIOCGPTN */
return 1;
}
#endif
+
+/********************************************************************
+ *
+ * get_time - Get current time, monotonic if possible.
+ */
+int
+get_time(struct timeval *tv)
+{
+/* Old glibc (< 2.3.4) does define CLOCK_MONOTONIC, but kernel may have it.
+ * Runtime checking makes it safe. */
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC 1
+#endif
+ static int monotonic = -1;
+ struct timespec ts;
+ int ret;
+
+ if (monotonic) {
+ ret = clock_gettime(CLOCK_MONOTONIC, &ts);
+ if (ret == 0) {
+ monotonic = 1;
+ if (tv) {
+ tv->tv_sec = ts.tv_sec;
+ tv->tv_usec = ts.tv_nsec / 1000;
+ }
+ return ret;
+ } else if (monotonic > 0)
+ return ret;
+
+ monotonic = 0;
+ warn("Couldn't use monotonic clock source: %m");
+ }
+
+ return gettimeofday(tv, NULL);
+}