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