打开ppp packet打印

diff --git a/pppd/utils.c b/pppd/utils.c
index 6f668b8..6f1db8f 100644
--- a/pppd/utils.c
+++ b/pppd/utils.c
@@ -670,9 +670,10 @@ log_write(level, buf)
     int level;
     char *buf;
 {
+    dbglog("%s",buf);
     syslog(level, "%s", buf);
 
-    fprintf(stderr, buf);
+    fprintf(stderr,"%s", buf);
     
     if (log_to_fd >= 0 && (level != LOG_DEBUG || debug)) {
        int n = strlen(buf);


@@ -861,8 +862,20 @@ dump_packet(const char *tag, unsigned char *p, int len)
            && l >= HEADERLEN && l <= len - PPP_HDRLEN)
            return;
     }
+    {
+       char bufout[100] = {0};
+       int i = 0;
+       int level;
 
-    dbglog("%s %P", tag, p, len);
+       for(i = 0; i < len; i++)
+           sprintf(&(bufout[2*i]), "%.2x", p[i]);
+        dbglog("%s [%s], len %d", tag, bufout, len);
+
+       level = ANDROID_LOG_DEBUG;
+       init_pr_log(tag, level);
+       format_packet(p, len, pr_log, &level);
+       end_pr_log();
+    }
 }


修改后的函数如下
static void
log_write(level, buf)
    int level;
    char *buf;
{
    dbglog("%s",buf);
    syslog(level, "%s", buf);

    fprintf(stderr,"%s", buf);
    
    if (log_to_fd >= 0 && (level != LOG_DEBUG || debug)) {
	int n = strlen(buf);

	if (n > 0 && buf[n-1] == '\n')
	    --n;
	if (write(log_to_fd, buf, n) != n
	    || write(log_to_fd, "\n", 1) != 1)
	    log_to_fd = -1;
    }
}

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;
    }
    {
	char bufout[100] = {0};
	int i = 0;
	int level;

	for(i = 0; i < len; i++)
	    sprintf(&(bufout[2*i]), "%.2x", p[i]);
        dbglog("%s [%s], len %d", tag, bufout, len);

	level = ANDROID_LOG_DEBUG;
	init_pr_log(tag, level);
	format_packet(p, len, pr_log, &level);
	end_pr_log();
    }
}



你可能感兴趣的:(打开ppp packet打印)