keywords and eol-style
[obnox/wireshark/wip.git] / wiretap / iptrace.c
1 /* iptrace.c
2  *
3  * $Id$
4  *
5  * Wiretap Library
6  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 #include <stdlib.h>
27 #include <errno.h>
28 #include <string.h>
29 #include "wtap-int.h"
30 #include "file_wrappers.h"
31 #include "buffer.h"
32 #include "atm.h"
33 #include "iptrace.h"
34
35 static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
36     long *data_offset);
37 static gboolean iptrace_seek_read_1_0(wtap *wth, long seek_off,
38     union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
39     int *err, gchar **err_info);
40
41 static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
42     long *data_offset);
43 static gboolean iptrace_seek_read_2_0(wtap *wth, long seek_off,
44     union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
45     int *err, gchar **err_info);
46
47 static int iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len,
48     int *err);
49 static gboolean iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr,
50     int packet_size, int *err);
51 static void fill_in_pseudo_header(int encap, const guint8 *pd, guint32 len,
52     union wtap_pseudo_header *pseudo_header, guint8 *header);
53 static int wtap_encap_ift(unsigned int  ift);
54
55 int iptrace_open(wtap *wth, int *err, gchar **err_info _U_)
56 {
57         int bytes_read;
58         char name[12];
59
60         errno = WTAP_ERR_CANT_READ;
61         bytes_read = file_read(name, 1, 11, wth->fh);
62         if (bytes_read != 11) {
63                 *err = file_error(wth->fh);
64                 if (*err != 0)
65                         return -1;
66                 return 0;
67         }
68         wth->data_offset += 11;
69         name[11] = 0;
70
71         if (strcmp(name, "iptrace 1.0") == 0) {
72                 wth->file_type = WTAP_FILE_IPTRACE_1_0;
73                 wth->subtype_read = iptrace_read_1_0;
74                 wth->subtype_seek_read = iptrace_seek_read_1_0;
75         }
76         else if (strcmp(name, "iptrace 2.0") == 0) {
77                 wth->file_type = WTAP_FILE_IPTRACE_2_0;
78                 wth->subtype_read = iptrace_read_2_0;
79                 wth->subtype_seek_read = iptrace_seek_read_2_0;
80         }
81         else {
82                 return 0;
83         }
84
85         return 1;
86 }
87
88 /***********************************************************
89  * iptrace 1.0                                             *
90  ***********************************************************/
91
92 /*
93  * iptrace 1.0, discovered through inspection
94  *
95  * Packet record contains:
96  *
97  *      an initial header, with a length field and a time stamp, in
98  *      seconds since the Epoch;
99  *
100  *      data, with the specified length.
101  *
102  * The data contains:
103  *
104  *      a bunch of information about the packet;
105  *
106  *      padding, at least for FDDI;
107  *
108  *      the raw packet data.
109  */
110 typedef struct {
111 /* 0-3 */       guint32         pkt_length;     /* packet length + 0x16 */
112 /* 4-7 */       guint32         tv_sec;         /* time stamp, seconds since the Epoch */
113 /* 8-11 */      guint32         junk1;          /* ???, not time */
114 /* 12-15 */     char            if_name[4];     /* null-terminated */
115 /* 16-27 */     char            junk2[12];      /* ??? */
116 /* 28 */        guint8          if_type;        /* BSD net/if_types.h */
117 /* 29 */        guint8          tx_flag;        /* 0=receive, 1=transmit */
118 } iptrace_1_0_phdr;
119
120 #define IPTRACE_1_0_PHDR_SIZE   30      /* initial header plus packet data */
121 #define IPTRACE_1_0_PDATA_SIZE  22      /* packet data */
122
123 /* Read the next packet */
124 static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info _U_,
125     long *data_offset)
126 {
127         int                     ret;
128         guint32                 packet_size;
129         guint8                  header[IPTRACE_1_0_PHDR_SIZE];
130         guint8                  *data_ptr;
131         iptrace_1_0_phdr        pkt_hdr;
132         guchar                  fddi_padding[3];
133
134         /* Read the descriptor data */
135         *data_offset = wth->data_offset;
136         ret = iptrace_read_rec_header(wth->fh, header, IPTRACE_1_0_PHDR_SIZE,
137             err);
138         if (ret <= 0) {
139                 /* Read error or EOF */
140                 return FALSE;
141         }
142         wth->data_offset += IPTRACE_1_0_PHDR_SIZE;
143
144         /*
145          * Byte 28 of the frame header appears to be a BSD-style IFT_xxx
146          * value giving the type of the interface.  Check out the
147          * <net/if_types.h> header file.
148          */
149         pkt_hdr.if_type = header[28];
150         wth->phdr.pkt_encap = wtap_encap_ift(pkt_hdr.if_type);
151
152         /* Read the packet data */
153         packet_size = pntohl(&header[0]) - IPTRACE_1_0_PDATA_SIZE;
154
155         /*
156          * AIX appears to put 3 bytes of padding in front of FDDI
157          * frames; strip that crap off.
158          */
159         if (wth->phdr.pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
160                 /*
161                  * The packet size is really a record size and includes
162                  * the padding.
163                  */
164                 packet_size -= 3;
165                 wth->data_offset += 3;
166
167                 /*
168                  * Read the padding.
169                  */
170                 if (!iptrace_read_rec_data(wth->fh, fddi_padding, 3, err))
171                         return FALSE;   /* Read error */
172         }
173
174         buffer_assure_space( wth->frame_buffer, packet_size );
175         data_ptr = buffer_start_ptr( wth->frame_buffer );
176         if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err))
177                 return FALSE;   /* Read error */
178         wth->data_offset += packet_size;
179
180         wth->phdr.len = packet_size;
181         wth->phdr.caplen = packet_size;
182         wth->phdr.ts.tv_sec = pntohl(&header[4]);
183         wth->phdr.ts.tv_usec = 0;
184
185         if (wth->phdr.pkt_encap == WTAP_ENCAP_UNKNOWN) {
186                 *err = WTAP_ERR_UNSUPPORTED_ENCAP;
187                 *err_info = g_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported",
188                     pkt_hdr.if_type);
189                 return FALSE;
190         }
191
192         /* Fill in the pseudo-header. */
193         fill_in_pseudo_header(wth->phdr.pkt_encap, data_ptr, wth->phdr.caplen,
194             &wth->pseudo_header, header);
195
196         /* If the per-file encapsulation isn't known, set it to this
197            packet's encapsulation.
198
199            If it *is* known, and it isn't this packet's encapsulation,
200            set it to WTAP_ENCAP_PER_PACKET, as this file doesn't
201            have a single encapsulation for all packets in the file. */
202         if (wth->file_encap == WTAP_ENCAP_UNKNOWN)
203                 wth->file_encap = wth->phdr.pkt_encap;
204         else {
205                 if (wth->file_encap != wth->phdr.pkt_encap)
206                         wth->file_encap = WTAP_ENCAP_PER_PACKET;
207         }
208
209         return TRUE;
210 }
211
212 static gboolean iptrace_seek_read_1_0(wtap *wth, long seek_off,
213     union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
214     int *err, gchar **err_info _U_)
215 {
216         int                     ret;
217         guint8                  header[IPTRACE_1_0_PHDR_SIZE];
218         int                     pkt_encap;
219         guchar                  fddi_padding[3];
220
221         if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
222                 return FALSE;
223
224         /* Read the descriptor data */
225         ret = iptrace_read_rec_header(wth->random_fh, header,
226             IPTRACE_1_0_PHDR_SIZE, err);
227         if (ret <= 0) {
228                 /* Read error or EOF */
229                 if (ret == 0) {
230                         /* EOF means "short read" in random-access mode */
231                         *err = WTAP_ERR_SHORT_READ;
232                 }
233                 return FALSE;
234         }
235
236         /*
237          * Get the interface type.
238          */
239         pkt_encap = wtap_encap_ift(header[28]);
240
241         /*
242          * AIX appears to put 3 bytes of padding in front of FDDI
243          * frames; strip that crap off.
244          */
245         if (pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
246                 /*
247                  * Read the padding.
248                  */
249                 if (!iptrace_read_rec_data(wth->random_fh, fddi_padding, 3, err))
250                         return FALSE;   /* Read error */
251         }
252
253         /* Get the packet data */
254         if (!iptrace_read_rec_data(wth->random_fh, pd, packet_size, err))
255                 return FALSE;
256
257         /* Fill in the pseudo_header. */
258         fill_in_pseudo_header(pkt_encap, pd, packet_size, pseudo_header,
259             header);
260
261         return TRUE;
262 }
263
264 /***********************************************************
265  * iptrace 2.0                                             *
266  ***********************************************************/
267
268 /*
269  * iptrace 2.0, discovered through inspection
270  *
271  * Packet record contains:
272  *
273  *      an initial header, with a length field and a time stamp, in
274  *      seconds since the Epoch;
275  *
276  *      data, with the specified length.
277  *
278  * The data contains:
279  *
280  *      a bunch of information about the packet;
281  *
282  *      padding, at least for FDDI;
283  *
284  *      the raw packet data.
285  */
286 typedef struct {
287 /* 0-3 */       guint32         pkt_length;     /* packet length + 32 */
288 /* 4-7 */       guint32         tv_sec0;        /* time stamp, seconds since the Epoch */
289 /* 8-11 */      guint32         junk1;          /* ?? */
290 /* 12-15 */     char            if_name[4];     /* null-terminated */
291 /* 16-27 */     char            if_desc[12];    /* interface description. */
292 /* 28 */        guint8          if_type;        /* BSD net/if_types.h */
293 /* 29 */        guint8          tx_flag;        /* 0=receive, 1=transmit */
294 /* 30-31 */     guint16         junk3;
295 /* 32-35 */     guint32         tv_sec;         /* time stamp, seconds since the Epoch */
296 /* 36-39 */     guint32         tv_nsec;        /* nanoseconds since that second */
297 } iptrace_2_0_phdr;
298
299 #define IPTRACE_2_0_PHDR_SIZE   40      /* initial header plus packet data */
300 #define IPTRACE_2_0_PDATA_SIZE  32      /* packet data */
301
302 /* Read the next packet */
303 static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info _U_,
304     long *data_offset)
305 {
306         int                     ret;
307         guint32                 packet_size;
308         guint8                  header[IPTRACE_2_0_PHDR_SIZE];
309         guint8                  *data_ptr;
310         iptrace_2_0_phdr        pkt_hdr;
311         guchar                  fddi_padding[3];
312
313         /* Read the descriptor data */
314         *data_offset = wth->data_offset;
315         ret = iptrace_read_rec_header(wth->fh, header, IPTRACE_2_0_PHDR_SIZE,
316             err);
317         if (ret <= 0) {
318                 /* Read error or EOF */
319                 return FALSE;
320         }
321         wth->data_offset += IPTRACE_2_0_PHDR_SIZE;
322
323         /*
324          * Byte 28 of the frame header appears to be a BSD-style IFT_xxx
325          * value giving the type of the interface.  Check out the
326          * <net/if_types.h> header file.
327          */
328         pkt_hdr.if_type = header[28];
329         wth->phdr.pkt_encap = wtap_encap_ift(pkt_hdr.if_type);
330
331         /* Read the packet data */
332         packet_size = pntohl(&header[0]) - IPTRACE_2_0_PDATA_SIZE;
333
334         /*
335          * AIX appears to put 3 bytes of padding in front of FDDI
336          * frames; strip that crap off.
337          */
338         if (wth->phdr.pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
339                 /*
340                  * The packet size is really a record size and includes
341                  * the padding.
342                  */
343                 packet_size -= 3;
344                 wth->data_offset += 3;
345
346                 /*
347                  * Read the padding.
348                  */
349                 if (!iptrace_read_rec_data(wth->fh, fddi_padding, 3, err))
350                         return FALSE;   /* Read error */
351         }
352
353         buffer_assure_space( wth->frame_buffer, packet_size );
354         data_ptr = buffer_start_ptr( wth->frame_buffer );
355         if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err))
356                 return FALSE;   /* Read error */
357         wth->data_offset += packet_size;
358
359         /* AIX saves time in nsec, not usec. It's easier to make iptrace
360          * files more Unix-compliant here than try to get the calling
361          * program to know when to use nsec or usec */
362
363         wth->phdr.len = packet_size;
364         wth->phdr.caplen = packet_size;
365         wth->phdr.ts.tv_sec = pntohl(&header[32]);
366         wth->phdr.ts.tv_usec = pntohl(&header[36]) / 1000;
367
368         if (wth->phdr.pkt_encap == WTAP_ENCAP_UNKNOWN) {
369                 *err = WTAP_ERR_UNSUPPORTED_ENCAP;
370                 *err_info = g_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported",
371                     pkt_hdr.if_type);
372                 return FALSE;
373         }
374
375         /* Fill in the pseudo-header. */
376         fill_in_pseudo_header(wth->phdr.pkt_encap, data_ptr, wth->phdr.caplen,
377             &wth->pseudo_header, header);
378
379         /* If the per-file encapsulation isn't known, set it to this
380            packet's encapsulation.
381
382            If it *is* known, and it isn't this packet's encapsulation,
383            set it to WTAP_ENCAP_PER_PACKET, as this file doesn't
384            have a single encapsulation for all packets in the file. */
385         if (wth->file_encap == WTAP_ENCAP_UNKNOWN)
386                 wth->file_encap = wth->phdr.pkt_encap;
387         else {
388                 if (wth->file_encap != wth->phdr.pkt_encap)
389                         wth->file_encap = WTAP_ENCAP_PER_PACKET;
390         }
391
392         return TRUE;
393 }
394
395 static gboolean iptrace_seek_read_2_0(wtap *wth, long seek_off,
396     union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
397     int *err, gchar **err_info _U_)
398 {
399         int                     ret;
400         guint8                  header[IPTRACE_2_0_PHDR_SIZE];
401         int                     pkt_encap;
402         guchar                  fddi_padding[3];
403
404         if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
405                 return FALSE;
406
407         /* Read the descriptor data */
408         ret = iptrace_read_rec_header(wth->random_fh, header,
409             IPTRACE_2_0_PHDR_SIZE, err);
410         if (ret <= 0) {
411                 /* Read error or EOF */
412                 if (ret == 0) {
413                         /* EOF means "short read" in random-access mode */
414                         *err = WTAP_ERR_SHORT_READ;
415                 }
416                 return FALSE;
417         }
418
419         /*
420          * Get the interface type.
421          */
422         pkt_encap = wtap_encap_ift(header[28]);
423
424         /*
425          * AIX appears to put 3 bytes of padding in front of FDDI
426          * frames; strip that crap off.
427          */
428         if (pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
429                 /*
430                  * Read the padding.
431                  */
432                 if (!iptrace_read_rec_data(wth->random_fh, fddi_padding, 3, err))
433                         return FALSE;   /* Read error */
434         }
435
436         /* Get the packet data */
437         if (!iptrace_read_rec_data(wth->random_fh, pd, packet_size, err))
438                 return FALSE;
439
440         /* Fill in the pseudo-header. */
441         fill_in_pseudo_header(pkt_encap, pd, packet_size, pseudo_header,
442             header);
443
444         return TRUE;
445 }
446
447 static int
448 iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len, int *err)
449 {
450         int     bytes_read;
451
452         errno = WTAP_ERR_CANT_READ;
453         bytes_read = file_read(header, 1, header_len, fh);
454         if (bytes_read != header_len) {
455                 *err = file_error(fh);
456                 if (*err != 0)
457                         return -1;
458                 if (bytes_read != 0) {
459                         *err = WTAP_ERR_SHORT_READ;
460                         return -1;
461                 }
462                 return 0;
463         }
464         return 1;
465 }
466
467 static gboolean
468 iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr, int packet_size, int *err)
469 {
470         int     bytes_read;
471
472         errno = WTAP_ERR_CANT_READ;
473         bytes_read = file_read( data_ptr, 1, packet_size, fh );
474
475         if (bytes_read != packet_size) {
476                 *err = file_error(fh);
477                 if (*err == 0)
478                         *err = WTAP_ERR_SHORT_READ;
479                 return FALSE;
480         }
481         return TRUE;
482 }
483
484 /*
485  * Fill in the pseudo-header information we can.
486  *
487  * For ATM traffic, "iptrace", alas, doesn't tell us what type of traffic
488  * is in the packet - it was presumably run on a machine that was one of
489  * the endpoints of the connection, so in theory it could presumably have
490  * told us, but, for whatever reason, it failed to do so - perhaps the
491  * low-level mechanism that feeds the presumably-AAL5 frames to us doesn't
492  * have access to that information (e.g., because it's in the ATM driver,
493  * and the ATM driver merely knows that stuff on VPI/VCI X.Y should be
494  * handed up to some particular client, it doesn't know what that client is).
495  *
496  * We let our caller try to figure out what kind of traffic it is, either
497  * by guessing based on the VPI/VCI, guessing based on the header of the
498  * packet, seeing earlier traffic that set up the circuit and specified
499  * in some fashion what sort of traffic it is, or being told by the user.
500  */
501 static void
502 fill_in_pseudo_header(int encap, const guint8 *pd, guint32 len,
503     union wtap_pseudo_header *pseudo_header, guint8 *header)
504 {
505         char    if_text[9];
506         char    *decimal;
507         int     Vpi = 0;
508         int     Vci = 0;
509
510         switch (encap) {
511
512         case WTAP_ENCAP_ATM_PDUS:
513                 /* Rip apart the "x.y" text into Vpi/Vci numbers */
514                 memcpy(if_text, &header[20], 8);
515                 if_text[8] = '\0';
516                 decimal = strchr(if_text, '.');
517                 if (decimal) {
518                         *decimal = '\0';
519                         Vpi = strtoul(if_text, NULL, 10);
520                         decimal++;
521                         Vci = strtoul(decimal, NULL, 10);
522                 }
523
524                 /*
525                  * OK, which value means "DTE->DCE" and which value means
526                  * "DCE->DTE"?
527                  */
528                 pseudo_header->atm.channel = header[29];
529
530                 pseudo_header->atm.vpi = Vpi;
531                 pseudo_header->atm.vci = Vci;
532
533                 /*
534                  * Attempt to guess from the packet data, the VPI,
535                  * and the VCI information about the type of traffic.
536                  */
537                 atm_guess_traffic_type(pd, len, pseudo_header);
538
539                 /* We don't have this information */
540                 pseudo_header->atm.flags = 0;
541                 pseudo_header->atm.cells = 0;
542                 pseudo_header->atm.aal5t_u2u = 0;
543                 pseudo_header->atm.aal5t_len = 0;
544                 pseudo_header->atm.aal5t_chksum = 0;
545                 break;
546
547         case WTAP_ENCAP_ETHERNET:
548                 /* We assume there's no FCS in this frame. */
549                 pseudo_header->eth.fcs_len = 0;
550                 break;
551         }
552 }
553
554 /* Given an RFC1573 (SNMP ifType) interface type,
555  * return the appropriate Wiretap Encapsulation Type.
556  */
557 static int
558 wtap_encap_ift(unsigned int  ift)
559 {
560
561         static const int ift_encap[] = {
562 /* 0x0 */       WTAP_ENCAP_UNKNOWN,     /* nothing */
563 /* 0x1 */       WTAP_ENCAP_UNKNOWN,     /* IFT_OTHER */
564 /* 0x2 */       WTAP_ENCAP_UNKNOWN,     /* IFT_1822 */
565 /* 0x3 */       WTAP_ENCAP_UNKNOWN,     /* IFT_HDH1822 */
566 /* 0x4 */       WTAP_ENCAP_RAW_IP,      /* IFT_X25DDN */
567 /* 0x5 */       WTAP_ENCAP_UNKNOWN,     /* IFT_X25 */
568 /* 0x6 */       WTAP_ENCAP_ETHERNET,    /* IFT_ETHER */
569 /* 0x7 */       WTAP_ENCAP_ETHERNET,    /* IFT_ISO88023 */
570 /* 0x8 */       WTAP_ENCAP_UNKNOWN,     /* IFT_ISO88024 */
571 /* 0x9 */       WTAP_ENCAP_TOKEN_RING,  /* IFT_ISO88025 */
572 /* 0xa */       WTAP_ENCAP_UNKNOWN,     /* IFT_ISO88026 */
573 /* 0xb */       WTAP_ENCAP_UNKNOWN,     /* IFT_STARLAN */
574 /* 0xc */       WTAP_ENCAP_RAW_IP,      /* IFT_P10, IBM SP switch */
575 /* 0xd */       WTAP_ENCAP_UNKNOWN,     /* IFT_P80 */
576 /* 0xe */       WTAP_ENCAP_UNKNOWN,     /* IFT_HY */
577 /* 0xf */       WTAP_ENCAP_FDDI_BITSWAPPED,     /* IFT_FDDI */
578 /* 0x10 */      WTAP_ENCAP_LAPB,        /* IFT_LAPB */  /* no data to back this up */
579 /* 0x11 */      WTAP_ENCAP_UNKNOWN,     /* IFT_SDLC */
580 /* 0x12 */      WTAP_ENCAP_UNKNOWN,     /* IFT_T1 */
581 /* 0x13 */      WTAP_ENCAP_UNKNOWN,     /* IFT_CEPT */
582 /* 0x14 */      WTAP_ENCAP_UNKNOWN,     /* IFT_ISDNBASIC */
583 /* 0x15 */      WTAP_ENCAP_UNKNOWN,     /* IFT_ISDNPRIMARY */
584 /* 0x16 */      WTAP_ENCAP_UNKNOWN,     /* IFT_PTPSERIAL */
585 /* 0x17 */      WTAP_ENCAP_UNKNOWN,     /* IFT_PPP */
586 /* 0x18 */      WTAP_ENCAP_RAW_IP,      /* IFT_LOOP */
587 /* 0x19 */      WTAP_ENCAP_UNKNOWN,     /* IFT_EON */
588 /* 0x1a */      WTAP_ENCAP_UNKNOWN,     /* IFT_XETHER */
589 /* 0x1b */      WTAP_ENCAP_UNKNOWN,     /* IFT_NSIP */
590 /* 0x1c */      WTAP_ENCAP_UNKNOWN,     /* IFT_SLIP */
591 /* 0x1d */      WTAP_ENCAP_UNKNOWN,     /* IFT_ULTRA */
592 /* 0x1e */      WTAP_ENCAP_UNKNOWN,     /* IFT_DS3 */
593 /* 0x1f */      WTAP_ENCAP_UNKNOWN,     /* IFT_SIP */
594 /* 0x20 */      WTAP_ENCAP_UNKNOWN,     /* IFT_FRELAY */
595 /* 0x21 */      WTAP_ENCAP_UNKNOWN,     /* IFT_RS232 */
596 /* 0x22 */      WTAP_ENCAP_UNKNOWN,     /* IFT_PARA */
597 /* 0x23 */      WTAP_ENCAP_UNKNOWN,     /* IFT_ARCNET */
598 /* 0x24 */      WTAP_ENCAP_UNKNOWN,     /* IFT_ARCNETPLUS */
599 /* 0x25 */      WTAP_ENCAP_ATM_PDUS,    /* IFT_ATM */
600         };
601         #define NUM_IFT_ENCAPS (sizeof ift_encap / sizeof ift_encap[0])
602
603         if (ift < NUM_IFT_ENCAPS) {
604                 return ift_encap[ift];
605         }
606         else {
607                 return WTAP_ENCAP_UNKNOWN;
608         }
609 }