+/*
+ * dump_packet - print out a packet in readable form if it is interesting.
+ * Assumes len >= PPP_HDRLEN.
+ */
+void
+dump_packet(const char *tag, unsigned char *p, int len)
+{
+ int proto;
+
+ if (!debug)
+ return;
+
+ /*
+ * don't print LCP echo request/reply packets if debug <= 1
+ * and the link is up.
+ */
+ proto = (p[2] << 8) + p[3];
+ if (debug <= 1 && unsuccess == 0 && proto == PPP_LCP
+ && len >= PPP_HDRLEN + HEADERLEN) {
+ unsigned char *lcp = p + PPP_HDRLEN;
+ int l = (lcp[2] << 8) + lcp[3];
+
+ if ((lcp[0] == ECHOREQ || lcp[0] == ECHOREP)
+ && l >= HEADERLEN && l <= len - PPP_HDRLEN)
+ return;
+ }
+
+ dbglog("%s %P", tag, p, len);
+}
+
+/*
+ * complete_read - read a full `count' bytes from fd,
+ * unless end-of-file or an error other than EINTR is encountered.
+ */
+ssize_t
+complete_read(int fd, void *buf, size_t count)
+{
+ size_t done;
+ ssize_t nb;
+ char *ptr = buf;
+
+ for (done = 0; done < count; ) {
+ nb = read(fd, ptr, count - done);
+ if (nb < 0) {
+ if (errno == EINTR && !got_sigterm)
+ continue;
+ return -1;
+ }
+ if (nb == 0)
+ break;
+ done += nb;
+ ptr += nb;
+ }
+ return done;
+}
+