As pointed by Evan: don't leak memory when the string pointer is NULL.
[metze/wireshark/wip.git] / epan / frequency-utils.h
1 /* frequency-utils.h
2  * Frequency conversion utility definitions
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 2007 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #ifndef __FREQUENCY_UTILS_H__
26 #define __FREQUENCY_UTILS_H__
27
28 #include "ws_symbol_export.h"
29
30 /** @file
31  * Frequency and channel conversion utilities.
32  */
33
34 /**
35  * Given a center frequency in MHz, return a channel number.
36  * @param freq Frequency in MHz.
37  * @return The equivalent channel or -1 if no match is found.
38  */
39 WS_DLL_PUBLIC
40 gint
41 ieee80211_mhz_to_chan(guint freq);
42
43 /**
44  * Given a channel number and a band type, return a center frequency.
45  * @param chan Channel number
46  * @param is_bg TRUE if the channel is a b/g channel, FALSE otherwise.
47  * @return The equivalent frequency or 0 if no match is found.
48  */
49 WS_DLL_PUBLIC
50 guint
51 ieee80211_chan_to_mhz(gint chan, gboolean is_bg);
52
53 /**
54  * Given a frequency in MHz, return a string representation.
55  * @param freq Frequench in MHz.
56  * @return A string showing the frequency, channel number, and type.  The string must be freed with g_free() after use.
57  */
58 WS_DLL_PUBLIC
59 gchar*
60 ieee80211_mhz_to_str(guint freq);
61
62 /* Should this be "(freq < 4920)", or something else? */
63 #define FREQ_IS_BG(freq) (freq <= 2484)
64
65 /*
66  * Editor modelines
67  *
68  * Local Variables:
69  * c-basic-offset: 4
70  * tab-width: 8
71  * indent-tabs-mode: nil
72  * End:
73  *
74  * ex: set shiftwidth=4 tabstop=8 expandtab:
75  * :indentSize=4:tabSize=8:noTabs=true:
76  */
77
78 #endif /* __FREQUENCY_UTILS_H__ */
79