From Greg Morris: change the endianness of CCFilehandle to match other
[obnox/wireshark/wip.git] / packet-fclctl.c
1 /* packet-fclctl.c
2  * Routines for FC Link Control Frames 
3  * Copyright 2001, Dinesh G Dutt <ddutt@cisco.com>
4  *
5  * $Id: packet-fclctl.c,v 1.1 2002/12/08 02:32:17 gerald Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from WHATEVER_FILE_YOU_USED (where "WHATEVER_FILE_YOU_USED"
12  * is a dissector file; if you just copied this from README.developer,
13  * don't bother with the "Copied from" - you don't even need to put
14  * in a "Copied from" if you copied an existing dissector, especially
15  * if the bulk of the code in the new dissector is your code)
16  * 
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License
19  * as published by the Free Software Foundation; either version 2
20  * of the License, or (at your option) any later version.
21  * 
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  * 
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30  */
31
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
42 #endif
43
44 #ifdef HAVE_NETINET_IN_H
45 # include <netinet/in.h>
46 #endif
47
48 #include <glib.h>
49
50 #ifdef NEED_SNPRINTF_H
51 # include "snprintf.h"
52 #endif
53
54 #include <epan/packet.h>
55 #include "etypes.h"
56 #include "packet-fc.h"
57 #include "packet-fclctl.h"
58
59 static gchar errstr[64];
60
61 gchar *
62 fclctl_get_typestr (guint8 linkctl_type, guint8 type)
63 {
64     if ((linkctl_type == FC_LCTL_FBSYB) ||
65         (linkctl_type == FC_LCTL_FBSYL)) {
66         return (val_to_str ((type & 0xF0), fc_lctl_fbsy_val, "0x%x")); 
67     }
68     else return ("\0");
69 }
70
71 gchar *
72 fclctl_get_paramstr (guint32 linkctl_type, guint32 param)
73 {
74     int len;
75     
76     errstr[0] = '\0';
77     
78     if (linkctl_type == FC_LCTL_PBSY) {
79         strcpy (errstr, val_to_str (((param & 0xFF000000) >> 24),
80                                     fc_lctl_pbsy_acode_val, "0x%x"));
81         len = strlen (errstr);
82         strcpy (&errstr[len], ", ");
83         len = strlen (errstr);
84         strcpy (&errstr[len],
85                 val_to_str (((param & 0x00FF0000) >> 16),
86                             fc_lctl_pbsy_rjt_val, "0x%x"));
87     }
88     else if ((linkctl_type == FC_LCTL_FRJT) ||
89              (linkctl_type == FC_LCTL_PRJT)) {
90         strcpy (errstr,
91                 val_to_str (((param & 0xFF000000) >> 24),
92                             fc_lctl_rjt_acode_val, "0x%x"));
93         len = strlen (errstr);
94         strcpy (&errstr[len], ", ");
95         len = strlen (errstr);
96         strcpy (&errstr[len],
97                 val_to_str (((param & 0x00FF0000) >> 16), fc_lctl_rjt_val,
98                             "%x"));
99     }
100
101     return (errstr);
102 }