2 * Routines for utilities to convert various other types to strings.
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h> /* needed for <netinet/in.h> */
36 #ifdef HAVE_NETINET_IN_H
37 # include <netinet/in.h> /* needed for <arpa/inet.h> on some platforms */
40 #ifdef HAVE_ARPA_INET_H
41 #include <arpa/inet.h>
44 #ifdef HAVE_SYS_SOCKET_H
45 #include <sys/socket.h> /* needed to define AF_ values on UNIX */
48 #ifdef HAVE_WINSOCK2_H
49 #include <winsock2.h> /* needed to define AF_ values on Windows */
52 #ifdef NEED_INET_V6DEFS_H
53 # include "inet_v6defs.h"
57 #include "value_string.h"
58 #include "addr_resolv.h"
60 #include "atalk-utils.h"
61 #include "sna-utils.h"
62 #include "osi-utils.h"
63 #include <epan/dissectors/packet-mtp3.h>
69 * If a user _does_ pass in a too-small buffer, this is probably
70 * going to be too long to fit. However, even a partial string
71 * starting with "[Buf" should provide enough of a clue to be
74 #define BUF_TOO_SMALL_ERR "[Buffer too small]"
76 /* Routine to convert a sequence of bytes to a hex string, one byte/two hex
77 * digits at at a time, with a specified punctuation character between
80 * If punct is '\0', no punctuation is applied (and thus
81 * the resulting string is (len-1) bytes shorter)
84 bytestring_to_str(const guint8 *ad, guint32 len, char punct) {
87 int i = (int) len - 1;
90 /* At least one version of Apple's C compiler/linker is buggy, causing
91 a complaint from the linker about the "literal C string section"
92 not ending with '\0' if we initialize a 16-element "char" array with
93 a 16-character string, the fact that initializing such an array with
94 such a string is perfectly legitimate ANSI C nonwithstanding, the 17th
95 '\0' byte in the string nonwithstanding. */
96 static const gchar hex_digits[16] =
97 { '0', '1', '2', '3', '4', '5', '6', '7',
98 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
105 if (buflen < 3 || i < 0) {
109 buf=ep_alloc(buflen);
110 p = &buf[buflen - 1];
114 *--p = hex_digits[octet&0xF];
116 *--p = hex_digits[octet&0xF];
126 /* Wrapper for the most common case of asking
127 * for a string using a colon as the hex-digit separator.
130 remove this one later when every call has been converted to address_to_str()
133 ether_to_str(const guint8 *ad)
135 return bytestring_to_str(ad, 6, ':');
139 This function is very fast and this function is called a lot.
140 XXX update the address_to_str stuff to use this function.
143 ip_to_str(const guint8 *ad) {
146 buf=ep_alloc(MAX_IP_STR_LEN);
147 ip_to_str_buf(ad, buf, MAX_IP_STR_LEN);
152 This function is very fast and this function is called a lot.
153 XXX update the address_to_str stuff to use this function.
155 static const char * const fast_strings[] = {
156 "0", "1", "2", "3", "4", "5", "6", "7",
157 "8", "9", "10", "11", "12", "13", "14", "15",
158 "16", "17", "18", "19", "20", "21", "22", "23",
159 "24", "25", "26", "27", "28", "29", "30", "31",
160 "32", "33", "34", "35", "36", "37", "38", "39",
161 "40", "41", "42", "43", "44", "45", "46", "47",
162 "48", "49", "50", "51", "52", "53", "54", "55",
163 "56", "57", "58", "59", "60", "61", "62", "63",
164 "64", "65", "66", "67", "68", "69", "70", "71",
165 "72", "73", "74", "75", "76", "77", "78", "79",
166 "80", "81", "82", "83", "84", "85", "86", "87",
167 "88", "89", "90", "91", "92", "93", "94", "95",
168 "96", "97", "98", "99", "100", "101", "102", "103",
169 "104", "105", "106", "107", "108", "109", "110", "111",
170 "112", "113", "114", "115", "116", "117", "118", "119",
171 "120", "121", "122", "123", "124", "125", "126", "127",
172 "128", "129", "130", "131", "132", "133", "134", "135",
173 "136", "137", "138", "139", "140", "141", "142", "143",
174 "144", "145", "146", "147", "148", "149", "150", "151",
175 "152", "153", "154", "155", "156", "157", "158", "159",
176 "160", "161", "162", "163", "164", "165", "166", "167",
177 "168", "169", "170", "171", "172", "173", "174", "175",
178 "176", "177", "178", "179", "180", "181", "182", "183",
179 "184", "185", "186", "187", "188", "189", "190", "191",
180 "192", "193", "194", "195", "196", "197", "198", "199",
181 "200", "201", "202", "203", "204", "205", "206", "207",
182 "208", "209", "210", "211", "212", "213", "214", "215",
183 "216", "217", "218", "219", "220", "221", "222", "223",
184 "224", "225", "226", "227", "228", "229", "230", "231",
185 "232", "233", "234", "235", "236", "237", "238", "239",
186 "240", "241", "242", "243", "244", "245", "246", "247",
187 "248", "249", "250", "251", "252", "253", "254", "255"
190 ip_to_str_buf(const guint8 *ad, gchar *buf, int buf_len)
192 register gchar const *p;
193 register gchar *b=buf;
195 if (buf_len < MAX_IP_STR_LEN) {
196 g_snprintf ( buf, buf_len, BUF_TOO_SMALL_ERR ); /* Let the unexpected value alert user */
200 p=fast_strings[*ad++];
207 p=fast_strings[*ad++];
214 p=fast_strings[*ad++];
231 remove this one later when every call has been converted to address_to_str()
234 ip6_to_str(const struct e_in6_addr *ad) {
235 #ifndef INET6_ADDRSTRLEN
236 #define INET6_ADDRSTRLEN 46
240 str=ep_alloc(INET6_ADDRSTRLEN+1);
242 ip6_to_str_buf(ad, str);
247 ip6_to_str_buf(const struct e_in6_addr *ad, gchar *buf)
249 inet_ntop(AF_INET6, (const guchar*)ad, buf, INET6_ADDRSTRLEN);
253 ipx_addr_to_str(guint32 net, const guint8 *ad)
258 buf=ep_alloc(8+1+MAXNAMELEN+1); /* 8 digits, 1 period, NAME, 1 null */
259 name = get_ether_name_if_known(ad);
262 g_snprintf(buf, 8+1+MAXNAMELEN+1, "%s.%s", get_ipxnet_name(net), name);
265 g_snprintf(buf, 8+1+MAXNAMELEN+1, "%s.%s", get_ipxnet_name(net),
266 bytestring_to_str(ad, 6, '\0'));
272 ipxnet_to_string(const guint8 *ad)
274 guint32 addr = pntohl(ad);
275 return ipxnet_to_str_punct(addr, ' ');
279 ipxnet_to_str_punct(const guint32 ad, char punct)
285 /* At least one version of Apple's C compiler/linker is buggy, causing
286 a complaint from the linker about the "literal C string section"
287 not ending with '\0' if we initialize a 16-element "char" array with
288 a 16-character string, the fact that initializing such an array with
289 such a string is perfectly legitimate ANSI C nonwithstanding, the 17th
290 '\0' byte in the string nonwithstanding. */
291 static const gchar hex_digits[16] =
292 { '0', '1', '2', '3', '4', '5', '6', '7',
293 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
294 static const guint32 octet_mask[4] =
295 { 0xff000000 , 0x00ff0000, 0x0000ff00, 0x000000ff };
302 octet = (ad & octet_mask[i]) >> ((3 - i) * 8);
303 *--p = hex_digits[octet&0xF];
305 *--p = hex_digits[octet&0xF];
316 vines_addr_to_str(const guint8 *addrp)
322 vines_addr_to_str_buf(addrp, buf, 214);
327 vines_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
329 g_snprintf(buf, buf_len, "%08x.%04x", pntohl(&addrp[0]), pntohs(&addrp[4]));
334 usb_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
336 if(pletohl(&addrp[0])==0xffffffff){
337 g_snprintf(buf, buf_len, "host");
339 g_snprintf(buf, buf_len, "%d.%d", pletohl(&addrp[0]), pletohl(&addrp[4]));
343 #define PLURALIZE(n) (((n) > 1) ? "s" : "")
344 #define COMMA(do_it) ((do_it) ? ", " : "")
347 * Maximum length of a string showing days/hours/minutes/seconds.
348 * (Does not include the terminating '\0'.)
349 * Includes space for a '-' sign for any negative components.
350 * -12345 days, 12 hours, 12 minutes, 12.123 seconds
352 #define TIME_SECS_LEN (10+1+4+2+2+5+2+2+7+2+2+7+4)
355 * Convert a value in seconds and fractions of a second to a string,
356 * giving time in days, hours, minutes, and seconds, and put the result
358 * "is_nsecs" says that "frac" is microseconds if true and milliseconds
360 * If time is negative, add a '-' to all non-null components.
363 time_secs_to_str_buf(gint32 time, guint32 frac, gboolean is_nsecs,
366 int hours, mins, secs;
367 const gchar *msign = "";
368 gboolean do_comma = FALSE;
370 if(time == G_MININT32) { /* That Which Shall Not Be Negated */
371 ep_strbuf_append_printf(buf, "Unable to cope with time value %d", time);
388 ep_strbuf_append_printf(buf, "%s%u day%s", msign, time, PLURALIZE(time));
393 ep_strbuf_append_printf(buf, "%s%s%u hour%s", COMMA(do_comma), msign, hours, PLURALIZE(hours));
398 ep_strbuf_append_printf(buf, "%s%s%u minute%s", COMMA(do_comma), msign, mins, PLURALIZE(mins));
402 if (secs != 0 || frac != 0) {
405 ep_strbuf_append_printf(buf, "%s%s%u.%09u seconds", COMMA(do_comma), msign, secs, frac);
407 ep_strbuf_append_printf(buf, "%s%s%u.%03u seconds", COMMA(do_comma), msign, secs, frac);
409 ep_strbuf_append_printf(buf, "%s%s%u second%s", COMMA(do_comma), msign, secs, PLURALIZE(secs));
414 time_secs_to_str(gint32 time)
418 buf=ep_strbuf_sized_new(TIME_SECS_LEN+1, TIME_SECS_LEN+1);
421 ep_strbuf_append(buf, "0 time");
425 time_secs_to_str_buf(time, 0, FALSE, buf);
430 time_secs_to_str_buf_unsigned(guint32 time, guint32 frac, gboolean is_nsecs,
433 int hours, mins, secs;
434 gboolean do_comma = FALSE;
444 ep_strbuf_append_printf(buf, "%u day%s", time, PLURALIZE(time));
448 ep_strbuf_append_printf(buf, "%s%u hour%s", COMMA(do_comma), hours, PLURALIZE(hours));
452 ep_strbuf_append_printf(buf, "%s%u minute%s", COMMA(do_comma), mins, PLURALIZE(mins));
455 if (secs != 0 || frac != 0) {
458 ep_strbuf_append_printf(buf, "%s%u.%09u seconds", COMMA(do_comma), secs, frac);
460 ep_strbuf_append_printf(buf, "%s%u.%03u seconds", COMMA(do_comma), secs, frac);
462 ep_strbuf_append_printf(buf, "%s%u second%s", COMMA(do_comma), secs, PLURALIZE(secs));
467 time_secs_to_str_unsigned(guint32 time)
471 buf=ep_strbuf_sized_new(TIME_SECS_LEN+1, TIME_SECS_LEN+1);
474 ep_strbuf_append(buf, "0 time");
478 time_secs_to_str_buf_unsigned(time, 0, FALSE, buf);
484 time_msecs_to_str(gint32 time)
489 buf=ep_strbuf_sized_new(TIME_SECS_LEN+1+3+1, TIME_SECS_LEN+1+3+1);
492 ep_strbuf_append(buf, "0 time");
497 /* oops we got passed a negative time */
507 time_secs_to_str_buf(time, msecs, FALSE, buf);
511 static const char *mon_names[12] = {
527 abs_time_to_str(nstime_t *abs_time)
532 buf=ep_alloc(3+1+2+2+4+1+2+1+2+1+2+1+9+1);
536 /* calling localtime() on MSVC 2005 with huge values causes it to crash */
537 /* XXX - find the exact value that still does work */
538 /* XXX - using _USE_32BIT_TIME_T might be another way to circumvent this problem */
539 if(abs_time->secs > 2000000000) {
543 tmp = localtime(&abs_time->secs);
545 g_snprintf(buf, 3+1+2+2+4+1+2+1+2+1+2+1+9+1,
546 "%s %2d, %d %02d:%02d:%02d.%09ld",
547 mon_names[tmp->tm_mon],
553 (long)abs_time->nsecs);
555 strncpy(buf, "Not representable", 3+1+2+2+4+1+2+1+2+1+2+1+9+1);
560 abs_time_secs_to_str(time_t abs_time)
565 buf=ep_alloc(3+1+2+2+4+1+2+1+2+1+2+1);
567 tmp = localtime(&abs_time);
569 g_snprintf(buf, 3+1+2+2+4+1+2+1+2+1+2+1,
570 "%s %2d, %d %02d:%02d:%02d",
571 mon_names[tmp->tm_mon],
578 strncpy(buf, "Not representable", 3+1+2+2+4+1+2+1+2+1+2+1);
583 display_signed_time(gchar *buf, int buflen, gint32 sec, gint32 frac,
588 /* If the fractional part of the time stamp is negative,
589 print its absolute value and, if the seconds part isn't
590 (the seconds part should be zero in that case), stick
591 a "-" in front of the entire time stamp. */
601 g_snprintf(buf, buflen, "%s%d", sign, sec);
605 g_snprintf(buf, buflen, "%s%d.%01d", sign, sec, frac);
609 g_snprintf(buf, buflen, "%s%d.%02d", sign, sec, frac);
613 g_snprintf(buf, buflen, "%s%d.%03d", sign, sec, frac);
617 g_snprintf(buf, buflen, "%s%d.%06d", sign, sec, frac);
621 g_snprintf(buf, buflen, "%s%d.%09d", sign, sec, frac);
628 display_epoch_time(gchar *buf, int buflen, time_t sec, gint32 frac,
634 elapsed_secs = difftime(sec,(time_t)0);
636 /* This code copied from display_signed_time; keep it in case anyone
637 is looking at captures from before 1970 (???).
638 If the fractional part of the time stamp is negative,
639 print its absolute value and, if the seconds part isn't
640 (the seconds part should be zero in that case), stick
641 a "-" in front of the entire time stamp. */
645 if (elapsed_secs >= 0)
651 g_snprintf(buf, buflen, "%s%0.0f", sign, elapsed_secs);
655 g_snprintf(buf, buflen, "%s%0.0f.%01d", sign, elapsed_secs, frac);
659 g_snprintf(buf, buflen, "%s%0.0f.%02d", sign, elapsed_secs, frac);
663 g_snprintf(buf, buflen, "%s%0.0f.%03d", sign, elapsed_secs, frac);
667 g_snprintf(buf, buflen, "%s%0.0f.%06d", sign, elapsed_secs, frac);
671 g_snprintf(buf, buflen, "%s%0.0f.%09d", sign, elapsed_secs, frac);
677 * Display a relative time as days/hours/minutes/seconds.
680 rel_time_to_str(nstime_t *rel_time)
687 buf=ep_strbuf_sized_new(1+TIME_SECS_LEN+1+6+1, 1+TIME_SECS_LEN+1+6+1);
689 /* If the nanoseconds part of the time stamp is negative,
690 print its absolute value and, if the seconds part isn't
691 (the seconds part should be zero in that case), stick
692 a "-" in front of the entire time stamp. */
694 time = (gint) rel_time->secs;
695 nsec = rel_time->nsecs;
696 if (time == 0 && nsec == 0) {
697 ep_strbuf_append(buf, "0.000000000 seconds");
702 ep_strbuf_append_c(buf, '-');
705 * We assume here that "rel_time->secs" is negative
706 * or zero; if it's not, the time stamp is bogus,
707 * with a positive seconds and negative microseconds.
709 time = (gint) -rel_time->secs;
712 time_secs_to_str_buf(time, nsec, TRUE, buf);
716 #define REL_TIME_SECS_LEN (1+10+1+9+1)
719 * Display a relative time as seconds.
722 rel_time_to_secs_str(nstime_t *rel_time)
726 buf=ep_alloc(REL_TIME_SECS_LEN);
728 display_signed_time(buf, REL_TIME_SECS_LEN, (gint32) rel_time->secs,
729 rel_time->nsecs, NSECS);
735 remove this one later when every call has been converted to address_to_str()
738 fc_to_str(const guint8 *ad)
740 return bytestring_to_str (ad, 3, '.');
743 /* FC Network Header Network Address Authority Identifiers */
745 #define FC_NH_NAA_IEEE 1 /* IEEE 802.1a */
746 #define FC_NH_NAA_IEEE_E 2 /* IEEE Exteneded */
747 #define FC_NH_NAA_LOCAL 3
748 #define FC_NH_NAA_IP 4 /* 32-bit IP address */
749 #define FC_NH_NAA_IEEE_R 5 /* IEEE Registered */
750 #define FC_NH_NAA_IEEE_R_E 6 /* IEEE Registered Exteneded */
751 /* according to FC-PH 3 draft these are now reclaimed and reserved */
752 #define FC_NH_NAA_CCITT_INDV 12 /* CCITT 60 bit individual address */
753 #define FC_NH_NAA_CCITT_GRP 14 /* CCITT 60 bit group address */
756 fcwwn_to_str (const guint8 *ad)
762 if (ad == NULL) return NULL;
764 ethstr=ep_alloc(512);
766 fmt = (ad[0] & 0xF0) >> 4;
771 case FC_NH_NAA_IEEE_E:
772 memcpy (oui, &ad[2], 6);
773 g_snprintf (ethstr, 512, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)", ad[0],
774 ad[1], ad[2], ad[3], ad[4], ad[5], ad[6], ad[7],
775 get_manuf_name (oui));
778 case FC_NH_NAA_IEEE_R:
779 oui[0] = ((ad[0] & 0x0F) << 4) | ((ad[1] & 0xF0) >> 4);
780 oui[1] = ((ad[1] & 0x0F) << 4) | ((ad[2] & 0xF0) >> 4);
781 oui[2] = ((ad[2] & 0x0F) << 4) | ((ad[3] & 0xF0) >> 4);
782 oui[3] = ((ad[3] & 0x0F) << 4) | ((ad[4] & 0xF0) >> 4);
783 oui[4] = ((ad[4] & 0x0F) << 4) | ((ad[5] & 0xF0) >> 4);
784 oui[5] = ((ad[5] & 0x0F) << 4) | ((ad[6] & 0xF0) >> 4);
786 g_snprintf (ethstr, 512, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)", ad[0],
787 ad[1], ad[2], ad[3], ad[4], ad[5], ad[6], ad[7],
788 get_manuf_name (oui));
792 g_snprintf (ethstr, 512, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", ad[0],
793 ad[1], ad[2], ad[3], ad[4], ad[5], ad[6], ad[7]);
799 * Generates a string representing the bits in a bitfield at "bit_offset" from an 8 bit boundary
800 * with the length in bits of no_of_bits based on value.
805 decode_bits_in_field(gint bit_offset, gint no_of_bits, guint64 value)
807 guint64 mask = 0,tmp;
813 mask = mask << (no_of_bits-1);
815 /* prepare the string */
818 for(bit=0;bit<((int)(bit_offset&0x07));bit++){
825 /* read the bits for the int */
826 for(i=0;i<no_of_bits;i++){
852 /* Generate, into "buf", a string showing the bits of a bitfield.
853 Return a pointer to the character after that string. */
854 /*XXX this needs a buf_len check */
856 other_decode_bitfield_value(char *buf, guint32 val, guint32 mask, int width)
864 bit = 1 << (width - 1);
867 /* This bit is part of the field. Show its value. */
873 /* This bit is not part of the field. */
888 decode_bitfield_value(char *buf, guint32 val, guint32 mask, int width)
892 p = other_decode_bitfield_value(buf, val, mask, width);
898 /* Generate a string describing a Boolean bitfield (a one-bit field that
899 says something is either true of false). */
901 decode_boolean_bitfield(guint32 val, guint32 mask, int width,
902 const char *truedesc, const char *falsedesc)
907 buf=ep_alloc(1025); /* is this a bit overkill? */
908 p = decode_bitfield_value(buf, val, mask, width);
912 strcpy(p, falsedesc);
916 /* Generate a string describing a numeric bitfield (an N-bit field whose
917 value is just a number). */
919 decode_numeric_bitfield(guint32 val, guint32 mask, int width,
926 buf=ep_alloc(1025); /* isnt this a bit overkill? */
927 /* Compute the number of bits we have to shift the bitfield right
928 to extract its value. */
929 while ((mask & (1<<shift)) == 0)
932 p = decode_bitfield_value(buf, val, mask, width);
933 g_snprintf(p, (gulong) (1025-(p-buf)), fmt, (val & mask) >> shift);
938 /*XXX FIXME the code below may be called very very frequently in the future.
939 optimize it for speed and get rid of the slow sprintfs */
940 /* XXX - perhaps we should have individual address types register
941 a table of routines to do operations such as address-to-name translation,
942 address-to-string translation, and the like, and have this call them,
943 and also have an address-to-string-with-a-name routine */
944 /* XXX - use this, and that future address-to-string-with-a-name routine,
945 in "col_set_addr()"; it might also be useful to have address types
946 export the names of the source and destination address fields, so
947 that "col_set_addr()" need know nothing whatsoever about particular
949 /* convert an address struct into a printable string */
952 address_to_str(const address *addr)
956 str=ep_alloc(MAX_ADDR_STR_LEN);
957 address_to_str_buf(addr, str, MAX_ADDR_STR_LEN);
961 /* The called routines use ep_alloc:ed memory */
963 se_address_to_str(const address *addr)
967 str = address_to_str(addr);
968 return se_strdup(str);
972 address_to_str_buf(const address *addr, gchar *buf, int buf_len)
974 const guint8 *addrdata;
976 struct atalk_ddp_addr ddp_addr;
983 g_snprintf(buf, buf_len, "%s", "");
986 addrdata = addr->data;
987 g_snprintf(buf, buf_len, "%02x:%02x:%02x:%02x:%02x:%02x", addrdata[0], addrdata[1], addrdata[2], addrdata[3], addrdata[4], addrdata[5]);
990 ip_to_str_buf(addr->data, buf, buf_len);
993 if ( inet_ntop(AF_INET6, addr->data, buf, buf_len) == NULL ) /* Returns NULL if no space and does not touch buf */
994 g_snprintf ( buf, buf_len, BUF_TOO_SMALL_ERR ); /* Let the unexpected value alert user */
997 addrdata = addr->data;
998 g_snprintf(buf, buf_len, "%02x%02x%02x%02x.%02x%02x%02x%02x%02x%02x", addrdata[0], addrdata[1], addrdata[2], addrdata[3], addrdata[4], addrdata[5], addrdata[6], addrdata[7], addrdata[8], addrdata[9]);
1001 sna_fid_to_str_buf(addr, buf, buf_len);
1004 memcpy(&ddp_addr, addr->data, sizeof ddp_addr);
1005 atalk_addr_to_str_buf(&ddp_addr, buf, buf_len);
1008 vines_addr_to_str_buf(addr->data, buf, buf_len);
1011 usb_addr_to_str_buf(addr->data, buf, buf_len);
1014 print_nsap_net_buf(addr->data, addr->len, buf, buf_len);
1017 addrdata = addr->data;
1018 g_snprintf(buf, buf_len, "0x%02X", addrdata[0]);
1021 addrdata = addr->data;
1022 g_snprintf(buf, buf_len, "%02x.%02x.%02x", addrdata[0], addrdata[1], addrdata[2]);
1025 mtp3_addr_to_str_buf((const mtp3_addr_pc_t *)addr->data, buf, buf_len);
1028 addrstr = addr->data;
1029 g_snprintf(buf, buf_len, "%s", addrstr);
1032 addrdata = addr->data;
1033 g_snprintf(buf, buf_len, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1034 addrdata[0], addrdata[1], addrdata[2], addrdata[3],
1035 addrdata[4], addrdata[5], addrdata[6], addrdata[7]);
1038 int copy_len = addr->len < (buf_len - 1) ? addr->len : (buf_len - 1);
1039 memcpy(buf, addr->data, copy_len );
1040 buf[copy_len] = '\0';
1044 tipc_addr_to_str_buf(addr->data, buf, buf_len);
1047 g_assert_not_reached();
1051 gchar* guid_to_str(const e_guid_t *guid) {
1054 buf=ep_alloc(GUID_STR_LEN);
1055 return guid_to_str_buf(guid, buf, GUID_STR_LEN);
1058 gchar* guid_to_str_buf(const e_guid_t *guid, gchar *buf, int buf_len) {
1059 g_snprintf(buf, buf_len, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1060 guid->data1, guid->data2, guid->data3,
1061 guid->data4[0], guid->data4[1], guid->data4[2], guid->data4[3], guid->data4[4], guid->data4[5], guid->data4[6], guid->data4[7]);
1066 tipc_addr_to_str_buf( const guint8 *data, gchar *buf, int buf_len){
1070 guint32 tipc_address;
1072 tipc_address = data[0];
1073 tipc_address = (tipc_address << 8) ^ data[1];
1074 tipc_address = (tipc_address << 8) ^ data[2];
1075 tipc_address = (tipc_address << 8) ^ data[3];
1077 processor = tipc_address & 0x0fff;
1079 tipc_address = tipc_address >> 12;
1080 subnetwork = tipc_address & 0x0fff;
1082 tipc_address = tipc_address >> 12;
1083 zone = tipc_address & 0xff;
1085 g_snprintf(buf,buf_len,"%u.%u.%u",zone,subnetwork,processor);