nrdump.c
上传用户:hepax88
上传日期:2007-01-03
资源大小:1101k
文件大小:3k
源码类别:

TCP/IP协议栈

开发平台:

Visual C++

  1. /* NET/ROM header tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "netrom.h"
  8. #include "nr4.h"
  9. #include "trace.h"
  10. /* Display NET/ROM network and transport headers */
  11. void
  12. netrom_dump(fp,bpp,check)
  13. FILE *fp;
  14. struct mbuf **bpp;
  15. int check;
  16. {
  17. uint8 src[AXALEN],dest[AXALEN];
  18. char tmp[AXBUF];
  19. uint8 thdr[NR4MINHDR];
  20. register i;
  21. if(bpp == NULL || *bpp == NULL)
  22. return;
  23. /* See if it is a routing broadcast */
  24. if((*(*bpp)->data) == NR3NODESIG) {
  25. (void)PULLCHAR(bpp); /* Signature */
  26. pullup(bpp,tmp,ALEN);
  27. tmp[ALEN] = '';
  28. fprintf(fp,"NET/ROM Routing: %sn",tmp);
  29. for(i = 0;i < NRDESTPERPACK;i++) {
  30. if (pullup(bpp,src,AXALEN) < AXALEN)
  31. break;
  32. fprintf(fp,"        %12s",pax25(tmp,src));
  33. pullup(bpp,tmp,ALEN);
  34. tmp[ALEN] = '';
  35. fprintf(fp,"%8s",tmp);
  36. pullup(bpp,src,AXALEN);
  37. fprintf(fp,"    %12s",pax25(tmp,src));
  38. tmp[0] = PULLCHAR(bpp);
  39. fprintf(fp,"    %3un",(tmp[0]));
  40. }
  41. return;
  42. }
  43. /* Decode network layer */
  44. pullup(bpp,src,AXALEN);
  45. fprintf(fp,"NET/ROM: %s",pax25(tmp,src));
  46. pullup(bpp,dest,AXALEN);
  47. fprintf(fp,"->%s",pax25(tmp,dest));
  48. i = PULLCHAR(bpp);
  49. fprintf(fp," ttl %dn",i);
  50. /* Read first five bytes of "transport" header */
  51. pullup(bpp,thdr,NR4MINHDR);
  52. switch(thdr[4] & NR4OPCODE){
  53.   case NR4OPPID: /* network PID extension */
  54. if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  55.   ip_dump(fp,bpp,check) ;
  56. return;
  57. }
  58.   else
  59.   fprintf(fp,"         protocol family %x, proto %x",
  60.  thdr[0], thdr[1]) ;
  61.   break ;
  62. case NR4OPCONRQ: /* Connect request */
  63. fprintf(fp,"         conn rqst: ckt %d/%d",(thdr[0]),(thdr[1]));
  64. i = PULLCHAR(bpp);
  65. fprintf(fp," wnd %d",i);
  66. pullup(bpp,src,AXALEN);
  67. fprintf(fp," %s",pax25(tmp,src));
  68. pullup(bpp,dest,AXALEN);
  69. fprintf(fp,"@%s",pax25(tmp,dest));
  70. break;
  71. case NR4OPCONAK: /* Connect acknowledgement */
  72. fprintf(fp,"         conn ack: ur ckt %d/%d my ckt %d/%d",
  73.  thdr[0], thdr[1], thdr[2],thdr[3]);
  74. i = PULLCHAR(bpp);
  75. fprintf(fp," wnd %d",i);
  76. break;
  77. case NR4OPDISRQ: /* Disconnect request */
  78. fprintf(fp,"         disc: ckt %d/%d",
  79.  thdr[0],thdr[1]);
  80. break;
  81. case NR4OPDISAK: /* Disconnect acknowledgement */
  82. fprintf(fp,"         disc ack: ckt %d/%d",
  83.  thdr[0],thdr[1]);
  84. break;
  85. case NR4OPINFO: /* Information (data) */
  86. fprintf(fp,"         info: ckt %d/%d",
  87.  thdr[0],thdr[1]);
  88. fprintf(fp," txseq %d rxseq %d",
  89.  thdr[2],thdr[3]);
  90. break;
  91. case NR4OPACK: /* Information acknowledgement */
  92. fprintf(fp,"         info ack: ckt %d/%d",
  93.  thdr[0],thdr[1]);
  94. fprintf(fp," txseq %d rxseq %d",thdr[2],thdr[3]);
  95. break;
  96. default:
  97.   fprintf(fp,"         unknown transport type %d",
  98.  thdr[4] & 0x0f) ;
  99. break;
  100. }
  101. if(thdr[4] & NR4CHOKE)
  102. fprintf(fp," CHOKE");
  103. if(thdr[4] & NR4NAK)
  104. fprintf(fp," NAK");
  105. if(thdr[4] & NR4MORE)
  106. fprintf(fp," MORE");
  107. putc('n',fp);
  108. }