File: ipx.c

package info (click to toggle)
ipgrab 0.8.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 540 kB
  • ctags: 555
  • sloc: ansic: 4,608; sh: 1,507; makefile: 120
file content (165 lines) | stat: -rw-r--r-- 3,504 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**************************************************************************** 
** File: ipx.c
**
** Author: Mike Borella
**
** Comments: Dump IPX header information
**
** $Log: ipx.c,v $
** Revision 1.2  1998/06/12 21:01:08  mborella
** Added log tag
**
*****************************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include "config.h"
#include "ipx.h"

extern struct arg_t *my_args;

/*----------------------------------------------------------------------------
**
** dump_ipx()
**
** Parse IPX header and dump fields
**
**----------------------------------------------------------------------------
*/

void dump_ipx(u_char *bp, int length)
{
  IPXhdr *ipx;
  u_int16_t len;
  u_char *cp;
  void dump_spx(u_char *, u_int16_t);
  void dump_ipxrip(u_char *, u_int16_t);
  static const char *ipxaddr_string(u_char *);
 
  /*
   * Dump header announcement
   */

  printf("-----------------------------------------------------------------\n");
  printf("                        IPX Header\n");
  printf("-----------------------------------------------------------------\n");

  /*
   * View the packet as an IPX header
   */

  ipx = (IPXhdr *) bp;

  /*
   * Check for truncated header and truncated packet
   */
  
  if (length < sizeof(IPXHDR_SIZE))
    {
      printf("Truncated header, length = %d bytes\n", length);
      return;
    }

  len = ntohs(ipx->len);
  if (length < len)
    {
      printf("Truncated packet: length field = %d, actual length = %d\n", 
	     len, length);
      return;
    }

  /*
   * Dump header fields
   */
  
  if (!my_args->n)
    {
      printf("Checksum:               %d\n", ntohs(ipx->csum));
      printf("Packet length:          %d\n", len);
      printf("Transport control:      %d\n", ipx->tc);
      printf("Packet type:            %d ", ipx->pt);

      switch(ipx->pt)
	{
	case 0: 
	  printf("(unknown)\n");
	  break;
	case 1:
	  printf("(RIP)\n");
	  break;
	case 2:
	  printf("(echo)\n");
	  break;
	case 3:
	  printf("(error)\n");
	  break;
	case 4:
	  printf("(PEP)\n");
	  break;
	case 5:
	  printf("(SPX)\n");
	  break;
	case 17:
	  printf("(NCP)\n");
	  break;
	case 20:
	  printf("(NetBIOS)\n");
	  break;
	default:
	  printf("(undefined)\n");
	  break;
	}

      printf("Destination network     %x\n", ntohl(ipx->dstnet));
      printf("Destination node        %s\n", ipxaddr_string(ipx->dstnode));
      printf("Destination port        %d\n", ntohs(ipx->dstport));
      printf("Source network          %x\n", ntohl(ipx->srcnet));
      printf("Source node             %s\n", ipxaddr_string(ipx->srcnode));
      printf("Source port             %d\n", ntohs(ipx->srcport));
    }


  /*
   * Hand it to the next higher level protocol.
   */

  len -= IPXHDR_SIZE;
  cp = (u_char *) bp + IPXHDR_SIZE;
 
  switch (ipx->pt) 
    {
    case 1: 
      dump_ipxrip(cp, len);
      break;

    case 5:
      dump_spx(cp, len);
      break; 
      
    default:
      break;
    }
  
}


/*----------------------------------------------------------------------------
**
** ipxaddr_string()
**
** Convert IPX address to hex format.  Stolen from tcpdump.
**
**----------------------------------------------------------------------------
*/

static const char *ipxaddr_string(u_char *node)
{
    static char line[256];

    sprintf(line, "%02x:%02x:%02x:%02x:%02x:%02x", node[0], node[1], 
	    node[2], node[3], node[4], node[5]);

    return line;
}