资源简介
tcp/ip网络协议是当前网络应用的基础。通过源代码可了解其内部的运作方式。能更好的进行网络的开发于应用。
代码片段和文件信息
/* Asynchronous HDLC routines */
#include “global.h“
#include “ahdlc.h“
#include “crc.h“
#include “trace.h“ /******/
static uint8 *putbyte(uint8 *uint8);
void
init_hdlc(hpmaxsize)
struct ahdlc *hp;
int maxsize;
{
hp->escaped = 0;
hp->hunt = 0;
hp->inframe = NULL;
hp->maxsize = maxsize;
hp->fcs = FCS_START;
hp->rxframes = 0;
hp->aborts = 0;
hp->toobigs = 0;
hp->crcerrs = 0;
}
/* Process incoming data. Return completed packets NULL otherwise */
struct mbuf *
ahdlcrx(apc)
struct ahdlc *ap; /* HDLC Receiver control block */
uint8 c;
{
struct mbuf *bp;
if(c == HDLC_ESC_ASYNC){
ap->escaped = 1;
return NULL;
}
if(c != HDLC_FLAG){
if(ap->hunt)
return NULL; /* Ignore until next packet */
/* Normal character within packet */
if(ap->escaped){
c ^= HDLC_ESC_COMPL;
ap->escaped = 0;
}
if(ap->inframe == NULL)
ap->inframe = ambufw(ap->maxsize);
if(ap->inframe->cnt == ap->maxsize){
/* frame too large */
ap->toobigs++;
#ifdef debug
printf(“frame TOO LARGE (>%u bytes)\n“ap->maxsize);
#endif
free_p(&ap->inframe);
ap->inframe = NULL;
ap->escaped = 0;
ap->fcs = FCS_START;
ap->hunt = 1;
return NULL;
}
/* Store character update FCS */
ap->inframe->data[ap->inframe->cnt++] = c;
ap->fcs = FCS(ap->fcsc);
return NULL;
}
/* We get here only if the character is a flag */
if(ap->escaped){
/* ESC FLAG is frame abort */
ap->aborts++;
#ifdef debug
printf(“AHDLC ABORT cnt = %u\n“ap->inframe->cnt);
#endif
ap->hunt = 1;
ap->escaped = 0;
free_p(&ap->inframe);
ap->inframe = NULL;
ap->fcs = FCS_START;
return NULL;
}
if(ap->hunt){
/* Found flag in hunt mode. Reset for new frame */
ap->hunt = 0;
return NULL;
}
if(ap->inframe == NULL){
/* Padding flags ignore */
return NULL;
}
if(ap->fcs != FCS_FINAL){
/* CRC error */
ap->crcerrs++;
#ifdef debug
printf(“AHDLC CRC ERROR cnt = %u\n“ap->inframe->cnt);
hex_dump(stdout&ap->inframe);
#endif
free_p(&ap->inframe);
ap->inframe = NULL;
ap->fcs = FCS_START;
return NULL;
}
if(ap->inframe->cnt < 2){
/* Runt frame */
ap->runts++;
#ifdef debug
printf(“AHDLC RUNT cnt = %u\n“ap->inframe->cnt);
#endif
free_p(&ap->inframe);
ap->inframe = NULL;
ap->fcs = FCS_START;
return NULL;
}
/* Normal end-of-frame */
ap->rxframes++;
bp = ap->inframe;
ap->inframe = NULL;
ap->fcs = FCS_START;
bp->cnt -= 2;
#ifdef debug
printf(“Normal AHDLC receive len %u\n“bp->cnt);
#endif
return bp;
}
/* Encode a packet in asynchronous HDLC for transmission */
struct mbuf *
ahdlctx(bp)
struct mbuf *bp;
{
struct mbuf *obp;
uint8 *cp;
int c;
uint16 fcs;
fcs = FCS_START;
obp = ambufw(5+2*len_p(bp)); /* Allocate worst-case */
cp = obp->data;
while((c = PULLCHAR(&bp)) != -1){
fcs = FCS(fcsc);
cp = putbyte(cpc);
}
free_p(&bp); /* Shouldn‘t be necessary */
fcs ^= 0x
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 24616 2001-08-01 15:31 TCP_IP\config.c
文件 3352 1995-11-17 08:59 TCP_IP\ahdlc.c
文件 13028 2001-08-01 15:34 TCP_IP\alloc.c
文件 738 2001-08-01 15:34 TCP_IP\arcdump.c
文件 2337 2001-08-01 15:34 TCP_IP\arcnet.c
文件 4907 2001-08-01 15:34 TCP_IP\arpcmd.c
文件 1770 2001-08-01 15:34 TCP_IP\arpdump.c
文件 3958 2001-08-01 15:34 TCP_IP\asy.c
文件 492 1995-11-17 08:59 TCP_IP\aud.c
文件 12286 2001-08-01 15:33 TCP_IP\ax25cmd.c
文件 3964 2001-08-01 15:33 TCP_IP\ax25dump.c
文件 2293 2001-08-01 15:33 TCP_IP\ax25mail.c
文件 5345 2001-08-01 15:33 TCP_IP\ax25subr.c
文件 17030 2001-08-01 15:24 TCP_IP\lapb.c
文件 4658 2001-08-01 15:33 TCP_IP\axheard.c
文件 22075 2001-08-01 15:33 TCP_IP\bmutil.c
文件 10636 2001-08-01 15:26 TCP_IP\hop.c
文件 15767 2001-08-01 15:32 TCP_IP\bootpcmd.c
文件 6665 2001-08-01 15:20 TCP_IP\ping.c
文件 29335 2001-08-01 15:31 TCP_IP\bootpdip.c
文件 7004 2001-08-01 15:31 TCP_IP\cmdparse.c
文件 6376 2001-08-01 15:11 TCP_IP\udp.c
文件 2913 1995-11-17 09:00 TCP_IP\crc.c
文件 1272 1995-11-17 09:00 TCP_IP\devparam.c
文件 8348 2001-08-01 15:31 TCP_IP\dirutil.c
文件 20390 2001-08-01 15:30 TCP_IP\display.c
文件 9743 2001-08-01 15:30 TCP_IP\dma.c
文件 41251 2001-08-01 15:30 TCP_IP\domain.c
文件 6541 2001-08-01 15:30 TCP_IP\domhdr.c
文件 7838 2001-08-01 15:30 TCP_IP\dos.c
文件 11011 1995-11-18 08:07 TCP_IP\axsock.c
............此处省略237个文件信息
- 上一篇:C++实现朴素贝叶斯分类器
- 下一篇:C语言模拟实现 try catch
评论
共有 条评论