⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 target.c

📁 ppp协议的lwip源代码
💻 C
字号:

#include "pppconf.h"
#include "ppp.h"

#if PPP_DEBUG > 0
#include "pppdebug.h"

void ppp_trace(int level, const char *format, ...)
{
	va_list args;

	(void)level;
	va_start(args, format);
	vprintf(format, args);
	va_end(args);
}
#endif

void ppp_panic(char * msg)
{
	printf("PPP panic: %s\n", msg);
	exit(1);
}

void
ppp_msleep(unsigned long ms)
{
	sys_sem_t delaysem = sys_sem_new(0);

	sys_sem_wait_timeout(delaysem, ms);

	sys_sem_free(delaysem);
}

/*
 * Make a string representation of a network IP address.
 * WARNING: NOT RE-ENTRANT!
 */
char *ip_ntoa(u32_t ipaddr)
{
    static char b[20];
    
    ipaddr = ntohl(ipaddr);
    
    sprintf(b, "%d.%d.%d.%d",
            (u_char)(ipaddr >> 24),
            (u_char)(ipaddr >> 16),
            (u_char)(ipaddr >> 8),
            (u_char)(ipaddr));
    return b;
}



/* Convert byte to two ascii-hex characters */
static void
ctohex(char *buf, short c)
{
	static char hex[] = "0123456789abcdef";

	*buf++ = hex[(c&0xf0)>>4];
	*buf = hex[c&0x0f];
}

/* Print a buffer up to 16 bytes long in formatted hex with ascii
 * translation, e.g.,
 * 0000: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f  0123456789:;<=>?
 */
static void
fmtline(short addr, const u_char *buf, short len)
{
	char line[80];
	char *aptr,*cptr;
	u_char c;
	int i;

	for(i=0; i< sizeof(line); i++)
		line[i] = ' ';
	ctohex(line,(short)((addr&0xff00) >> 8));
	ctohex(line+2,(short)(addr&0xff));
	aptr = &line[6];
	cptr = &line[55];
	while(len-- != 0){
		c = *buf++;
		ctohex(aptr,(short)(c));
		aptr += 3;
		c &= 0x7f;
#ifndef isprint
#define isprint(c) (((c) >= 0x20) && ((c) < 0x7f))
#endif
		*cptr++ = isprint((c)) ? c : '.';
	}
	*cptr++ = '\0';
	printf("%s\n",  line);
}

//#define MAX_HEX_DUMP 512

void
ppp_hex_dump(const u_char *bp, u_int length)
{
	unsigned short address = 0;
#ifdef MAX_HEX_DUMP
	u_int remain=0;

	if(length > MAX_HEX_DUMP) {
		remain = length - MAX_HEX_DUMP;
		length = MAX_HEX_DUMP;
	}
#endif

	while(length > 0) {
		int n;

		n = (length > 16) ? 16 : length;
		fmtline(address,bp,n);
		length -= n;
		address += n;
		bp += n;
	}

#ifdef MAX_HEX_DUMP
	if(remain) {
		printf("hex_dump: skipping %d remaining bytes\n", remain);
	}
#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -