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