2010-02-27 21:41:12 +00:00
|
|
|
/* address_to_str.c
|
|
|
|
* Routines for utilities to convert addresses to strings.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2010-02-27 21:41:12 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 01:48:30 +00:00
|
|
|
#include "config.h"
|
2010-02-27 21:41:12 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2013-08-27 21:12:52 +00:00
|
|
|
# include <sys/types.h> /* needed for <netinet/in.h> */
|
2010-02-27 21:41:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2013-08-27 21:12:52 +00:00
|
|
|
# include <netinet/in.h> /* needed for <arpa/inet.h> on some platforms */
|
2010-02-27 21:41:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2013-08-27 21:12:52 +00:00
|
|
|
#include <sys/socket.h> /* needed to define AF_ values on UNIX */
|
2010-02-27 21:41:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_WINSOCK2_H
|
2013-08-27 21:12:52 +00:00
|
|
|
#include <winsock2.h> /* needed to define AF_ values on Windows */
|
2010-02-27 21:41:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NEED_INET_V6DEFS_H
|
2010-05-28 20:19:55 +00:00
|
|
|
# include "wsutil/inet_v6defs.h"
|
2010-02-27 21:41:12 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-09 11:26:41 +00:00
|
|
|
#include "to_str-int.h"
|
2010-02-27 21:41:12 +00:00
|
|
|
#include "to_str.h"
|
|
|
|
#include "value_string.h"
|
|
|
|
#include "addr_resolv.h"
|
2013-08-01 23:34:47 +00:00
|
|
|
#include "wsutil/pint.h"
|
2010-02-27 21:41:12 +00:00
|
|
|
#include "atalk-utils.h"
|
|
|
|
#include "sna-utils.h"
|
|
|
|
#include "osi-utils.h"
|
|
|
|
#include <epan/dissectors/packet-mtp3.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "emem.h"
|
2013-11-23 22:17:27 +00:00
|
|
|
#include "wmem/wmem.h"
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2014-01-30 17:43:52 +00:00
|
|
|
static void
|
|
|
|
ip6_to_str_buf_len(const guchar* src, char *buf, size_t buf_len);
|
|
|
|
|
2010-02-27 21:41:12 +00:00
|
|
|
/*
|
|
|
|
* If a user _does_ pass in a too-small buffer, this is probably
|
|
|
|
* going to be too long to fit. However, even a partial string
|
|
|
|
* starting with "[Buf" should provide enough of a clue to be
|
|
|
|
* useful.
|
|
|
|
*/
|
|
|
|
#define BUF_TOO_SMALL_ERR "[Buffer too small]"
|
|
|
|
|
|
|
|
/* Wrapper for the most common case of asking
|
|
|
|
* for a string using a colon as the hex-digit separator.
|
|
|
|
*/
|
|
|
|
/* XXX FIXME
|
|
|
|
remove this one later when every call has been converted to ep_address_to_str()
|
|
|
|
*/
|
2012-12-26 05:57:06 +00:00
|
|
|
const gchar *
|
2010-02-27 21:41:12 +00:00
|
|
|
ether_to_str(const guint8 *ad)
|
|
|
|
{
|
2013-12-19 15:49:09 +00:00
|
|
|
return bytestring_to_ep_str(ad, 6, ':');
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 05:57:06 +00:00
|
|
|
const gchar *
|
2011-01-21 02:48:55 +00:00
|
|
|
tvb_ether_to_str(tvbuff_t *tvb, const gint offset)
|
|
|
|
{
|
2013-12-19 15:49:09 +00:00
|
|
|
return bytestring_to_ep_str(tvb_get_ptr(tvb, offset, 6), 6, ':');
|
2011-01-21 02:48:55 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 21:41:12 +00:00
|
|
|
/*
|
|
|
|
This function is very fast and this function is called a lot.
|
|
|
|
XXX update the ep_address_to_str stuff to use this function.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
ip_to_str(const guint8 *ad) {
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *buf;
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
buf=(gchar *)ep_alloc(MAX_IP_STR_LEN);
|
|
|
|
ip_to_str_buf(ad, buf, MAX_IP_STR_LEN);
|
|
|
|
return buf;
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 15:53:30 +00:00
|
|
|
#define IPV4_LENGTH 4
|
|
|
|
const gchar *
|
|
|
|
tvb_ip_to_str(tvbuff_t *tvb, const gint offset)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *buf;
|
2011-01-13 15:53:30 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
buf=(gchar *)ep_alloc(MAX_IP_STR_LEN);
|
|
|
|
ip_to_str_buf(tvb_get_ptr(tvb, offset, IPV4_LENGTH), buf, MAX_IP_STR_LEN);
|
|
|
|
return buf;
|
2011-01-13 15:53:30 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 21:41:12 +00:00
|
|
|
/* XXX FIXME
|
|
|
|
remove this one later when every call has been converted to ep_address_to_str()
|
|
|
|
*/
|
2014-01-14 05:39:57 +00:00
|
|
|
const gchar *
|
2010-02-27 21:41:12 +00:00
|
|
|
ip6_to_str(const struct e_in6_addr *ad) {
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *str;
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
str=(gchar *)ep_alloc(MAX_IP6_STR_LEN);
|
|
|
|
ip6_to_str_buf(ad, str);
|
|
|
|
return str;
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
2014-01-30 17:43:52 +00:00
|
|
|
/* XXX FIXME
|
|
|
|
This exists solely for a single call from ui/iface_lists.c,
|
|
|
|
scan_local_interfaces(), and gcc's -fstrict-aliasing. The iface_lists.c
|
|
|
|
code should be change to used a different type for its ip6 address,
|
|
|
|
so that this function is no longer needed.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
ip6_guint8_to_str(const guint8 *ad) {
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str=(gchar *)ep_alloc(MAX_IP6_STR_LEN);
|
|
|
|
ip6_to_str_buf_len((const guchar*)ad, str, MAX_IP6_STR_LEN);
|
|
|
|
return str;
|
|
|
|
}
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2011-01-13 15:53:30 +00:00
|
|
|
#define IPV6_LENGTH 16
|
2014-01-14 05:39:57 +00:00
|
|
|
const gchar *
|
2011-01-13 15:53:30 +00:00
|
|
|
tvb_ip6_to_str(tvbuff_t *tvb, const gint offset)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *buf;
|
2011-01-13 15:53:30 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
buf=(gchar *)ep_alloc(MAX_IP6_STR_LEN);
|
|
|
|
ip6_to_str_buf((const struct e_in6_addr *)tvb_get_ptr(tvb, offset, IPV6_LENGTH), buf);
|
|
|
|
return buf;
|
2011-01-13 15:53:30 +00:00
|
|
|
}
|
|
|
|
|
2011-05-05 20:48:21 +00:00
|
|
|
/* const char *
|
|
|
|
* inet_ntop6(src, dst, size)
|
2013-08-27 21:12:52 +00:00
|
|
|
* convert IPv6 binary address into presentation (printable) format
|
2011-05-05 20:48:21 +00:00
|
|
|
* author:
|
2013-08-27 21:12:52 +00:00
|
|
|
* Paul Vixie, 1996.
|
2011-05-05 20:48:21 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ip6_to_str_buf_len(const guchar* src, char *buf, size_t buf_len)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
struct { int base, len; } best, cur;
|
|
|
|
guint words[8];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (buf_len < MAX_IP6_STR_LEN) { /* buf_len < 40 */
|
|
|
|
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Preprocess:
|
|
|
|
* Copy the input (bytewise) array into a wordwise array.
|
|
|
|
* Find the longest run of 0x00's in src[] for :: shorthanding.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 16; i += 2) {
|
|
|
|
words[i / 2] = (src[i+1] << 0);
|
|
|
|
words[i / 2] |= (src[i] << 8);
|
|
|
|
}
|
|
|
|
best.base = -1; best.len = 0;
|
|
|
|
cur.base = -1; cur.len = 0;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (words[i] == 0) {
|
|
|
|
if (cur.base == -1) {
|
|
|
|
cur.base = i;
|
|
|
|
cur.len = 1;
|
|
|
|
} else
|
|
|
|
cur.len++;
|
|
|
|
} else {
|
|
|
|
if (cur.base != -1) {
|
|
|
|
if (best.base == -1 || cur.len > best.len)
|
|
|
|
best = cur;
|
|
|
|
cur.base = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cur.base != -1) {
|
|
|
|
if (best.base == -1 || cur.len > best.len)
|
|
|
|
best = cur;
|
|
|
|
}
|
|
|
|
if (best.base != -1 && best.len < 2)
|
|
|
|
best.base = -1;
|
|
|
|
|
|
|
|
/* Is this address an encapsulated IPv4? */
|
|
|
|
/* XXX,
|
|
|
|
* Orginal code dated 1996 uses ::/96 as a valid IPv4-compatible addresses
|
|
|
|
* but since Feb 2006 ::/96 is deprecated one.
|
|
|
|
* Quoting wikipedia [0]:
|
|
|
|
* > The 96-bit zero-value prefix ::/96, originally known as IPv4-compatible
|
|
|
|
* > addresses, was mentioned in 1995[35] but first described in 1998.[41]
|
|
|
|
* > This class of addresses was used to represent IPv4 addresses within
|
|
|
|
* > an IPv6 transition technology. Such an IPv6 address has its first
|
|
|
|
* > (most significant) 96 bits set to zero, while its last 32 bits are the
|
|
|
|
* > IPv4 address that is represented.
|
|
|
|
* > In February 2006 the Internet Engineering Task Force (IETF) has deprecated
|
|
|
|
* > the use of IPv4-compatible addresses.[1] The only remaining use of this address
|
|
|
|
* > format is to represent an IPv4 address in a table or database with fixed size
|
|
|
|
* > members that must also be able to store an IPv6 address.
|
|
|
|
*
|
|
|
|
* If needed it can be fixed by changing next line:
|
|
|
|
* if (best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
|
|
|
|
* to:
|
|
|
|
* if (best.base == 0 && best.len == 5 && words[5] == 0xffff)
|
|
|
|
*
|
|
|
|
* [0] http://en.wikipedia.org/wiki/IPv6_address#Historical_notes
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
|
|
|
|
{
|
|
|
|
/* best.len == 6 -> ::IPv4; 5 -> ::ffff:IPv4 */
|
|
|
|
buf = g_stpcpy(buf, "::");
|
|
|
|
if (best.len == 5)
|
|
|
|
buf = g_stpcpy(buf, "ffff:");
|
|
|
|
ip_to_str_buf(src + 12, buf, MAX_IP_STR_LEN);
|
|
|
|
/* max: 2 + 5 + 16 == 23 bytes */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format the result.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
/* Are we inside the best run of 0x00's? */
|
|
|
|
if (i == best.base) {
|
|
|
|
*buf++ = ':';
|
|
|
|
i += best.len;
|
|
|
|
|
|
|
|
/* Was it a trailing run of 0x00's? */
|
|
|
|
if (i == 8) {
|
|
|
|
*buf++ = ':';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Are we following an initial run of 0x00s or any real hex? */
|
|
|
|
if (i != 0)
|
|
|
|
*buf++ = ':';
|
|
|
|
|
|
|
|
buf = word_to_hex_npad(buf, words[i]); /* max: 4B */
|
|
|
|
/* max: 8 * 4 + 7 == 39 bytes */
|
|
|
|
}
|
|
|
|
*buf = '\0'; /* 40 byte */
|
2011-05-05 20:48:21 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 21:41:12 +00:00
|
|
|
void
|
|
|
|
ip6_to_str_buf(const struct e_in6_addr *ad, gchar *buf)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
ip6_to_str_buf_len((const guchar*)ad, buf, MAX_IP6_STR_LEN);
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar*
|
2010-04-03 18:18:50 +00:00
|
|
|
ipx_addr_to_str(const guint32 net, const guint8 *ad)
|
2010-02-27 21:41:12 +00:00
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *buf;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
name = get_ether_name_if_known(ad);
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
buf = ep_strdup_printf("%s.%s", get_ipxnet_name(net), name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buf = ep_strdup_printf("%s.%s", get_ipxnet_name(net),
|
2013-12-19 15:49:09 +00:00
|
|
|
bytestring_to_ep_str(ad, 6, '\0'));
|
2013-08-27 21:12:52 +00:00
|
|
|
}
|
|
|
|
return buf;
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar*
|
|
|
|
ipxnet_to_string(const guint8 *ad)
|
|
|
|
{
|
2013-11-29 18:59:06 +00:00
|
|
|
guint32 addr = pntoh32(ad);
|
2013-08-27 21:12:52 +00:00
|
|
|
return ipxnet_to_str_punct(addr, ' ');
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
2010-04-03 18:18:50 +00:00
|
|
|
ipxnet_to_str_punct(const guint32 ad, const char punct)
|
2010-02-27 21:41:12 +00:00
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *buf = (gchar *)ep_alloc(12);
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
*dword_to_hex_punct(buf, ad, punct) = '\0';
|
|
|
|
return buf;
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vines_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
if (buf_len < 14) {
|
|
|
|
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-29 18:59:06 +00:00
|
|
|
buf = dword_to_hex(buf, pntoh32(&addrp[0])); /* 8 bytes */
|
2013-08-27 21:12:52 +00:00
|
|
|
*buf++ = '.'; /* 1 byte */
|
2013-11-29 18:59:06 +00:00
|
|
|
buf = word_to_hex(buf, pntoh16(&addrp[4])); /* 4 bytes */
|
2013-08-27 21:12:52 +00:00
|
|
|
*buf = '\0'; /* 1 byte */
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
2011-02-11 03:13:24 +00:00
|
|
|
tvb_vines_addr_to_str(tvbuff_t *tvb, const gint offset)
|
2010-02-27 21:41:12 +00:00
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *buf;
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
buf=(gchar *)ep_alloc(214); /* XXX, 14 here? */
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
vines_addr_to_str_buf(tvb_get_ptr(tvb, offset, VINES_ADDR_LEN), buf, 214);
|
|
|
|
return buf;
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
2011-05-08 10:23:53 +00:00
|
|
|
/*
|
|
|
|
This function is very fast and this function is called a lot.
|
|
|
|
XXX update the ep_address_to_str stuff to use this function.
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
eui64_to_str(const guint64 ad) {
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *buf;
|
|
|
|
guint8 *p_eui64;
|
2011-05-08 10:23:53 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
p_eui64 = (guint8 *)ep_alloc(8);
|
|
|
|
buf=(gchar *)ep_alloc(EUI64_STR_LEN);
|
2011-05-08 10:23:53 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
/* Copy and convert the address to network byte order. */
|
|
|
|
*(guint64 *)(void *)(p_eui64) = pntoh64(&(ad));
|
2011-05-08 10:23:53 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
g_snprintf(buf, EUI64_STR_LEN, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
|
|
|
|
p_eui64[0], p_eui64[1], p_eui64[2], p_eui64[3],
|
|
|
|
p_eui64[4], p_eui64[5], p_eui64[6], p_eui64[7] );
|
|
|
|
return buf;
|
2011-05-08 10:23:53 +00:00
|
|
|
}
|
|
|
|
gchar *
|
|
|
|
tvb_eui64_to_str(tvbuff_t *tvb, const gint offset, const guint encoding)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
if(encoding)
|
|
|
|
{
|
|
|
|
return eui64_to_str(tvb_get_letoh64(tvb, offset));
|
|
|
|
}else {
|
|
|
|
return eui64_to_str(tvb_get_ntoh64(tvb, offset));
|
|
|
|
}
|
2011-05-08 10:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 21:41:12 +00:00
|
|
|
static void
|
|
|
|
usb_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
|
|
|
|
{
|
2013-11-29 18:59:06 +00:00
|
|
|
if(pletoh32(&addrp[0])==0xffffffff){
|
2013-08-27 21:12:52 +00:00
|
|
|
g_snprintf(buf, buf_len, "host");
|
|
|
|
} else {
|
2013-11-29 18:59:06 +00:00
|
|
|
g_snprintf(buf, buf_len, "%d.%d", pletoh32(&addrp[0]), pletoh32(&addrp[4]));
|
2013-08-27 21:12:52 +00:00
|
|
|
}
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tipc_addr_to_str_buf( const guint8 *data, gchar *buf, int buf_len){
|
2013-08-27 21:12:52 +00:00
|
|
|
guint8 zone;
|
|
|
|
guint16 subnetwork;
|
|
|
|
guint16 processor;
|
|
|
|
guint32 tipc_address;
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
tipc_address = data[0];
|
|
|
|
tipc_address = (tipc_address << 8) ^ data[1];
|
|
|
|
tipc_address = (tipc_address << 8) ^ data[2];
|
|
|
|
tipc_address = (tipc_address << 8) ^ data[3];
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
processor = tipc_address & 0x0fff;
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
tipc_address = tipc_address >> 12;
|
|
|
|
subnetwork = tipc_address & 0x0fff;
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
tipc_address = tipc_address >> 12;
|
|
|
|
zone = tipc_address & 0xff;
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
g_snprintf(buf,buf_len,"%u.%u.%u",zone,subnetwork,processor);
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 02:57:22 +00:00
|
|
|
static void
|
|
|
|
ib_addr_to_str_buf( const address *addr, gchar *buf, int buf_len){
|
2013-08-27 21:12:52 +00:00
|
|
|
if (addr->len >= 16) { /* GID is 128bits */
|
|
|
|
#define PREAMBLE_STR_LEN ((int)(sizeof("GID: ") - 1))
|
|
|
|
g_snprintf(buf,buf_len,"GID: ");
|
|
|
|
if (buf_len < PREAMBLE_STR_LEN ||
|
|
|
|
inet_ntop(AF_INET6, addr->data, buf + PREAMBLE_STR_LEN,
|
|
|
|
buf_len - PREAMBLE_STR_LEN) == NULL ) /* Returns NULL if no space and does not touch buf */
|
|
|
|
g_snprintf ( buf, buf_len, BUF_TOO_SMALL_ERR ); /* Let the unexpected value alert user */
|
|
|
|
} else { /* this is a LID (16 bits) */
|
|
|
|
guint16 lid_number;
|
|
|
|
|
|
|
|
memcpy((void *)&lid_number, addr->data, sizeof lid_number);
|
|
|
|
g_snprintf(buf,buf_len,"LID: %u",lid_number);
|
|
|
|
}
|
2010-11-17 02:57:22 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 21:41:12 +00:00
|
|
|
/* XXX FIXME
|
|
|
|
remove this one later when every call has been converted to ep_address_to_str()
|
|
|
|
*/
|
2012-12-26 05:57:06 +00:00
|
|
|
const gchar *
|
2010-02-27 21:41:12 +00:00
|
|
|
fc_to_str(const guint8 *ad)
|
|
|
|
{
|
2013-12-19 15:49:09 +00:00
|
|
|
return bytestring_to_ep_str (ad, 3, '.');
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 05:57:06 +00:00
|
|
|
const gchar *
|
2011-01-16 04:33:42 +00:00
|
|
|
tvb_fc_to_str(tvbuff_t *tvb, const gint offset)
|
|
|
|
{
|
2013-12-19 15:49:09 +00:00
|
|
|
return bytestring_to_ep_str (tvb_get_ptr(tvb, offset, 3), 3, '.');
|
2011-01-16 04:33:42 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 21:41:12 +00:00
|
|
|
/* FC Network Header Network Address Authority Identifiers */
|
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
#define FC_NH_NAA_IEEE 1 /* IEEE 802.1a */
|
|
|
|
#define FC_NH_NAA_IEEE_E 2 /* IEEE Exteneded */
|
|
|
|
#define FC_NH_NAA_LOCAL 3
|
|
|
|
#define FC_NH_NAA_IP 4 /* 32-bit IP address */
|
|
|
|
#define FC_NH_NAA_IEEE_R 5 /* IEEE Registered */
|
|
|
|
#define FC_NH_NAA_IEEE_R_E 6 /* IEEE Registered Exteneded */
|
2010-02-27 21:41:12 +00:00
|
|
|
/* according to FC-PH 3 draft these are now reclaimed and reserved */
|
2013-08-27 21:12:52 +00:00
|
|
|
#define FC_NH_NAA_CCITT_INDV 12 /* CCITT 60 bit individual address */
|
|
|
|
#define FC_NH_NAA_CCITT_GRP 14 /* CCITT 60 bit group address */
|
2010-02-27 21:41:12 +00:00
|
|
|
|
|
|
|
gchar *
|
|
|
|
fcwwn_to_str (const guint8 *ad)
|
|
|
|
{
|
|
|
|
int fmt;
|
|
|
|
guint8 oui[6];
|
|
|
|
gchar *ethstr;
|
|
|
|
gchar *ethptr;
|
|
|
|
|
|
|
|
if (ad == NULL) return NULL;
|
|
|
|
|
2013-03-15 05:42:50 +00:00
|
|
|
ethstr=(gchar *)ep_alloc(512);
|
2013-08-27 21:12:52 +00:00
|
|
|
ethptr = bytes_to_hexstr_punct(ethstr, ad, 8, ':'); /* 23 bytes */
|
2010-02-27 21:41:12 +00:00
|
|
|
|
|
|
|
fmt = (ad[0] & 0xF0) >> 4;
|
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
|
|
|
|
case FC_NH_NAA_IEEE:
|
|
|
|
case FC_NH_NAA_IEEE_E:
|
|
|
|
memcpy (oui, &ad[2], 6);
|
|
|
|
|
|
|
|
g_snprintf (ethptr, 512-23, " (%s)", get_manuf_name (oui));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FC_NH_NAA_IEEE_R:
|
|
|
|
oui[0] = ((ad[0] & 0x0F) << 4) | ((ad[1] & 0xF0) >> 4);
|
|
|
|
oui[1] = ((ad[1] & 0x0F) << 4) | ((ad[2] & 0xF0) >> 4);
|
|
|
|
oui[2] = ((ad[2] & 0x0F) << 4) | ((ad[3] & 0xF0) >> 4);
|
|
|
|
oui[3] = ((ad[3] & 0x0F) << 4) | ((ad[4] & 0xF0) >> 4);
|
|
|
|
oui[4] = ((ad[4] & 0x0F) << 4) | ((ad[5] & 0xF0) >> 4);
|
|
|
|
oui[5] = ((ad[5] & 0x0F) << 4) | ((ad[6] & 0xF0) >> 4);
|
|
|
|
|
|
|
|
g_snprintf (ethptr, 512-23, " (%s)", get_manuf_name (oui));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*ethptr = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (ethstr);
|
|
|
|
}
|
|
|
|
|
2011-01-16 04:33:42 +00:00
|
|
|
gchar *
|
|
|
|
tvb_fcwwn_to_str(tvbuff_t *tvb, const gint offset)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
return fcwwn_to_str (tvb_get_ptr(tvb, offset, 8));
|
2011-01-16 04:33:42 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 18:51:40 +00:00
|
|
|
/* XXX FIXME
|
|
|
|
remove this one later when every call has been converted to address_to_str()
|
|
|
|
*/
|
2012-12-26 05:57:06 +00:00
|
|
|
const gchar *
|
2012-08-02 18:51:40 +00:00
|
|
|
ax25_to_str(const guint8 *ad)
|
|
|
|
{
|
2013-12-19 15:49:09 +00:00
|
|
|
return bytestring_to_ep_str(ad, 7, ':');
|
2012-08-02 18:51:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX FIXME
|
|
|
|
remove this one later when every call has been converted to address_to_str()
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
get_ax25_name(const guint8 *ad)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
address addr;
|
2012-08-02 18:51:40 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
addr.type = AT_AX25;
|
|
|
|
addr.len = 7;
|
|
|
|
addr.data = ad;
|
2012-08-02 18:51:40 +00:00
|
|
|
|
2013-11-23 22:03:48 +00:00
|
|
|
return ep_address_to_str( &addr );
|
2012-08-02 18:51:40 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 21:41:12 +00:00
|
|
|
/*XXX FIXME the code below may be called very very frequently in the future.
|
|
|
|
optimize it for speed and get rid of the slow sprintfs */
|
|
|
|
/* XXX - perhaps we should have individual address types register
|
|
|
|
a table of routines to do operations such as address-to-name translation,
|
|
|
|
address-to-string translation, and the like, and have this call them,
|
|
|
|
and also have an address-to-string-with-a-name routine */
|
|
|
|
/* XXX - use this, and that future address-to-string-with-a-name routine,
|
|
|
|
in "col_set_addr()"; it might also be useful to have address types
|
|
|
|
export the names of the source and destination address fields, so
|
|
|
|
that "col_set_addr()" need know nothing whatsoever about particular
|
|
|
|
address types */
|
|
|
|
/* convert an address struct into a printable string */
|
|
|
|
|
2013-11-23 22:17:27 +00:00
|
|
|
gchar*
|
|
|
|
address_to_str(wmem_allocator_t *scope, const address *addr)
|
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str=(gchar *)wmem_alloc(scope, MAX_ADDR_STR_LEN);
|
|
|
|
address_to_str_buf(addr, str, MAX_ADDR_STR_LEN);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2010-02-27 21:41:12 +00:00
|
|
|
gchar*
|
|
|
|
ep_address_to_str(const address *addr)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *str;
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
str=(gchar *)ep_alloc(MAX_ADDR_STR_LEN);
|
|
|
|
address_to_str_buf(addr, str, MAX_ADDR_STR_LEN);
|
|
|
|
return str;
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The called routines use se_alloc'ed memory */
|
|
|
|
gchar*
|
|
|
|
se_address_to_str(const address *addr)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
gchar *str;
|
2010-02-27 21:41:12 +00:00
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
str=(gchar *)se_alloc(MAX_ADDR_STR_LEN);
|
|
|
|
address_to_str_buf(addr, str, MAX_ADDR_STR_LEN);
|
|
|
|
return str;
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
address_to_str_buf(const address *addr, gchar *buf, int buf_len)
|
|
|
|
{
|
2013-08-27 21:12:52 +00:00
|
|
|
const guint8 *addrdata;
|
|
|
|
struct atalk_ddp_addr ddp_addr;
|
|
|
|
guint16 ieee_802_15_4_short_addr;
|
|
|
|
|
|
|
|
char temp[32];
|
|
|
|
char *tempptr = temp;
|
|
|
|
|
|
|
|
if (!buf || !buf_len)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(addr->type){
|
|
|
|
case AT_NONE:
|
|
|
|
buf[0] = '\0';
|
|
|
|
break;
|
|
|
|
case AT_ETHER: /* 18 bytes */
|
|
|
|
tempptr = bytes_to_hexstr_punct(tempptr, (const guint8 *)addr->data, 6, ':'); /* 17 bytes */
|
|
|
|
break;
|
|
|
|
case AT_IPv4:
|
|
|
|
ip_to_str_buf((const guint8 *)addr->data, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_IPv6:
|
|
|
|
ip6_to_str_buf_len((const guchar *)addr->data, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_IPX: /* 22 bytes */
|
|
|
|
addrdata = (const guint8 *)addr->data;
|
|
|
|
tempptr = bytes_to_hexstr(tempptr, &addrdata[0], 4); /* 8 bytes */
|
|
|
|
*tempptr++ = '.'; /*1 byte */
|
|
|
|
tempptr = bytes_to_hexstr(tempptr, &addrdata[4], 6); /* 12 bytes */
|
|
|
|
break;
|
|
|
|
case AT_SNA:
|
|
|
|
sna_fid_to_str_buf(addr, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_ATALK:
|
|
|
|
memcpy(&ddp_addr, addr->data, sizeof ddp_addr);
|
|
|
|
atalk_addr_to_str_buf(&ddp_addr, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_VINES:
|
|
|
|
vines_addr_to_str_buf((const guint8 *)addr->data, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_USB:
|
|
|
|
usb_addr_to_str_buf((const guint8 *)addr->data, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_OSI:
|
|
|
|
print_nsap_net_buf((const guint8 *)addr->data, addr->len, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_ARCNET: /* 5 bytes */
|
|
|
|
tempptr = g_stpcpy(tempptr, "0x"); /* 2 bytes */
|
|
|
|
tempptr = bytes_to_hexstr(tempptr, (const guint8 *)addr->data, 1); /* 2 bytes */
|
|
|
|
break;
|
|
|
|
case AT_FC: /* 9 bytes */
|
|
|
|
tempptr = bytes_to_hexstr_punct(tempptr, (const guint8 *)addr->data, 3, '.'); /* 8 bytes */
|
|
|
|
break;
|
|
|
|
case AT_SS7PC:
|
|
|
|
mtp3_addr_to_str_buf((const mtp3_addr_pc_t *)addr->data, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_STRINGZ:
|
|
|
|
g_strlcpy(buf, (const gchar *)addr->data, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_EUI64: /* 24 bytes */
|
|
|
|
tempptr = bytes_to_hexstr_punct(tempptr, (const guint8 *)addr->data, 8, ':'); /* 23 bytes */
|
|
|
|
break;
|
|
|
|
case AT_URI: {
|
|
|
|
int copy_len = addr->len < (buf_len - 1) ? addr->len : (buf_len - 1);
|
|
|
|
memcpy(buf, addr->data, copy_len );
|
|
|
|
buf[copy_len] = '\0';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AT_TIPC:
|
|
|
|
tipc_addr_to_str_buf((const guint8 *)addr->data, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_IB:
|
|
|
|
ib_addr_to_str_buf(addr, buf, buf_len);
|
|
|
|
break;
|
|
|
|
case AT_AX25:
|
|
|
|
addrdata = (const guint8 *)addr->data;
|
|
|
|
g_snprintf(buf, buf_len, "%c%c%c%c%c%c-%02d",
|
|
|
|
(addrdata[0] >> 1) & 0x7f, (addrdata[1] >> 1) & 0x7f, (addrdata[2] >> 1) & 0x7f,
|
|
|
|
(addrdata[3] >> 1) & 0x7f, (addrdata[4] >> 1) & 0x7f, (addrdata[5] >> 1) & 0x7f,
|
|
|
|
(addrdata[6] >> 1) & 0x0f );
|
|
|
|
break;
|
|
|
|
case AT_IEEE_802_15_4_SHORT:
|
2013-11-29 18:59:06 +00:00
|
|
|
ieee_802_15_4_short_addr = pletoh16(addr->data);
|
2013-08-27 21:12:52 +00:00
|
|
|
if (ieee_802_15_4_short_addr == 0xffff)
|
|
|
|
g_snprintf(buf, buf_len, "Broadcast");
|
|
|
|
else
|
|
|
|
g_snprintf(buf, buf_len, "0x%04x", ieee_802_15_4_short_addr);
|
|
|
|
break;
|
2013-12-06 04:33:58 +00:00
|
|
|
case AT_J1939:
|
|
|
|
addrdata = (const guint8 *)addr->data;
|
|
|
|
g_snprintf(buf, buf_len, "%d", addrdata[0]);
|
|
|
|
break;
|
|
|
|
case AT_DEVICENET:
|
|
|
|
addrdata = (const guint8 *)addr->data;
|
|
|
|
g_snprintf(buf, buf_len, "%d", addrdata[0] & 0x3f);
|
|
|
|
break;
|
2013-08-27 21:12:52 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy to output buffer */
|
|
|
|
if (tempptr != temp) {
|
|
|
|
size_t temp_len = (size_t) (tempptr - temp);
|
|
|
|
|
|
|
|
if (temp_len < (size_t) buf_len) {
|
|
|
|
memcpy(buf, temp, temp_len);
|
|
|
|
buf[temp_len] = '\0';
|
|
|
|
} else
|
2013-12-20 10:30:57 +00:00
|
|
|
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len);/* Let the unexpected value alert user */
|
2010-02-27 21:41:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-27 21:12:52 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|