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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 #include "to_str-int.h"
39 * If a user _does_ pass in a too-small buffer, this is probably
40 * going to be too long to fit. However, even a partial string
41 * starting with "[Buf" should provide enough of a clue to be
44 #define BUF_TOO_SMALL_ERR "[Buffer too small]"
47 low_nibble_of_octet_to_hex(guint8 oct)
49 /* At least one version of Apple's C compiler/linker is buggy, causing
50 a complaint from the linker about the "literal C string section"
51 not ending with '\0' if we initialize a 16-element "char" array with
52 a 16-character string, the fact that initializing such an array with
53 such a string is perfectly legitimate ANSI C nonwithstanding, the 17th
54 '\0' byte in the string nonwithstanding. */
55 static const gchar hex_digits[16] =
56 { '0', '1', '2', '3', '4', '5', '6', '7',
57 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
59 return hex_digits[oct & 0xF];
63 byte_to_hex(char *out, guint32 dword) {
64 *out++ = low_nibble_of_octet_to_hex(dword >> 4);
65 *out++ = low_nibble_of_octet_to_hex(dword);
70 word_to_hex(char *out, guint16 word) {
71 out = byte_to_hex(out, word >> 8);
72 out = byte_to_hex(out, word);
77 word_to_hex_npad(char *out, guint16 word) {
79 *out++ = low_nibble_of_octet_to_hex((guint8)(word >> 12));
81 *out++ = low_nibble_of_octet_to_hex((guint8)(word >> 8));
83 *out++ = low_nibble_of_octet_to_hex((guint8)(word >> 4));
84 *out++ = low_nibble_of_octet_to_hex((guint8)(word >> 0));
89 dword_to_hex(char *out, guint32 dword) {
90 out = byte_to_hex(out, dword >> 24);
91 out = byte_to_hex(out, dword >> 16);
92 out = byte_to_hex(out, dword >> 8);
93 out = byte_to_hex(out, dword);
98 dword_to_hex_punct(char *out, guint32 dword, char punct) {
99 out = byte_to_hex(out, dword >> 24);
101 out = byte_to_hex(out, dword >> 16);
103 out = byte_to_hex(out, dword >> 8);
105 out = byte_to_hex(out, dword);
110 * This does *not* null-terminate the string. It returns a pointer
111 * to the position in the string following the last character it
112 * puts there, so that the caller can either put the null terminator
113 * in or can append more stuff to the buffer.
115 * There needs to be at least len * 2 bytes left in the buffer.
118 bytes_to_hexstr(char *out, const guint8 *ad, guint32 len) {
122 REPORT_DISSECTOR_BUG("Null pointer passed to bytes_to_hexstr()");
124 for (i = 0; i < len; i++)
125 out = byte_to_hex(out, ad[i]);
130 * This does *not* null-terminate the string. It returns a pointer
131 * to the position in the string following the last character it
132 * puts there, so that the caller can either put the null terminator
133 * in or can append more stuff to the buffer.
135 * There needs to be at least len * 3 - 1 bytes left in the buffer.
138 bytes_to_hexstr_punct(char *out, const guint8 *ad, guint32 len, char punct) {
142 REPORT_DISSECTOR_BUG("Null pointer passed to bytes_to_hexstr_punct()");
144 out = byte_to_hex(out, ad[0]);
145 for (i = 1; i < len; i++) {
147 out = byte_to_hex(out, ad[i]);
152 /* Routine to convert a sequence of bytes to a hex string, one byte/two hex
153 * digits at at a time, with a specified punctuation character between
156 * If punct is '\0', no punctuation is applied (and thus
157 * the resulting string is (len-1) bytes shorter)
160 bytestring_to_ep_str(const guint8 *ad, const guint32 len, const char punct) {
165 REPORT_DISSECTOR_BUG("Null pointer passed to bytestring_to_ep_str()");
167 /* XXX, Old code was using int as iterator... Why len is guint32 anyway?! (darkjames) */
168 if ( ((int) len) < 0)
179 buf=(gchar *)ep_alloc(buflen);
182 bytes_to_hexstr_punct(buf, ad, len, punct);
184 bytes_to_hexstr(buf, ad, len);
186 buf[buflen-1] = '\0';
190 /* Max string length for displaying byte string. */
191 #define MAX_BYTE_STR_LEN 48
194 bytes_to_ep_str(const guint8 *bd, int bd_len) {
200 REPORT_DISSECTOR_BUG("Null pointer passed to bytes_to_ep_str()");
202 cur=(gchar *)ep_alloc(MAX_BYTE_STR_LEN+3+1);
203 if (bd_len <= 0) { cur[0] = '\0'; return cur; }
205 if (bd_len > MAX_BYTE_STR_LEN/2) { /* bd_len > 24 */
207 bd_len = MAX_BYTE_STR_LEN/2;
210 cur_ptr = bytes_to_hexstr(cur, bd, bd_len); /* max MAX_BYTE_STR_LEN bytes */
213 cur_ptr = g_stpcpy(cur_ptr, "..."); /* 3 bytes */
215 *cur_ptr = '\0'; /* 1 byte */
219 /* Turn an array of bytes into a string showing the bytes in hex with
220 * punct as a bytes separator.
223 bytes_to_ep_str_punct(const guint8 *bd, int bd_len, gchar punct) {
229 return bytes_to_ep_str(bd, bd_len);
231 cur=(gchar *)ep_alloc(MAX_BYTE_STR_LEN+3+1);
232 if (bd_len <= 0) { cur[0] = '\0'; return cur; }
234 if (bd_len > MAX_BYTE_STR_LEN/3) { /* bd_len > 16 */
236 bd_len = MAX_BYTE_STR_LEN/3;
239 cur_ptr = bytes_to_hexstr_punct(cur, bd, bd_len, punct); /* max MAX_BYTE_STR_LEN-1 bytes */
242 *cur_ptr++ = punct; /* 1 byte */
243 cur_ptr = g_stpcpy(cur_ptr, "..."); /* 3 bytes */
251 guint32_to_str_buf_len(const guint32 u) {
252 if (u >= 1000000000)return 10;
253 if (u >= 100000000) return 9;
254 if (u >= 10000000) return 8;
255 if (u >= 1000000) return 7;
256 if (u >= 100000) return 6;
257 if (u >= 10000) return 5;
258 if (u >= 1000) return 4;
259 if (u >= 100) return 3;
260 if (u >= 10) return 2;
265 static const char fast_strings[][4] = {
266 "0", "1", "2", "3", "4", "5", "6", "7",
267 "8", "9", "10", "11", "12", "13", "14", "15",
268 "16", "17", "18", "19", "20", "21", "22", "23",
269 "24", "25", "26", "27", "28", "29", "30", "31",
270 "32", "33", "34", "35", "36", "37", "38", "39",
271 "40", "41", "42", "43", "44", "45", "46", "47",
272 "48", "49", "50", "51", "52", "53", "54", "55",
273 "56", "57", "58", "59", "60", "61", "62", "63",
274 "64", "65", "66", "67", "68", "69", "70", "71",
275 "72", "73", "74", "75", "76", "77", "78", "79",
276 "80", "81", "82", "83", "84", "85", "86", "87",
277 "88", "89", "90", "91", "92", "93", "94", "95",
278 "96", "97", "98", "99", "100", "101", "102", "103",
279 "104", "105", "106", "107", "108", "109", "110", "111",
280 "112", "113", "114", "115", "116", "117", "118", "119",
281 "120", "121", "122", "123", "124", "125", "126", "127",
282 "128", "129", "130", "131", "132", "133", "134", "135",
283 "136", "137", "138", "139", "140", "141", "142", "143",
284 "144", "145", "146", "147", "148", "149", "150", "151",
285 "152", "153", "154", "155", "156", "157", "158", "159",
286 "160", "161", "162", "163", "164", "165", "166", "167",
287 "168", "169", "170", "171", "172", "173", "174", "175",
288 "176", "177", "178", "179", "180", "181", "182", "183",
289 "184", "185", "186", "187", "188", "189", "190", "191",
290 "192", "193", "194", "195", "196", "197", "198", "199",
291 "200", "201", "202", "203", "204", "205", "206", "207",
292 "208", "209", "210", "211", "212", "213", "214", "215",
293 "216", "217", "218", "219", "220", "221", "222", "223",
294 "224", "225", "226", "227", "228", "229", "230", "231",
295 "232", "233", "234", "235", "236", "237", "238", "239",
296 "240", "241", "242", "243", "244", "245", "246", "247",
297 "248", "249", "250", "251", "252", "253", "254", "255"
301 guint32_to_str_buf(guint32 u, gchar *buf, int buf_len) {
302 int str_len = guint32_to_str_buf_len(u)+1;
304 gchar *bp = &buf[str_len];
306 if (buf_len < str_len) {
307 g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
313 uint_to_str_back(bp, u);
316 #define PLURALIZE(n) (((n) > 1) ? "s" : "")
317 #define COMMA(do_it) ((do_it) ? ", " : "")
320 * Maximum length of a string showing days/hours/minutes/seconds.
321 * (Does not include the terminating '\0'.)
322 * Includes space for a '-' sign for any negative components.
323 * -12345 days, 12 hours, 12 minutes, 12.123 seconds
325 #define TIME_SECS_LEN (10+1+4+2+2+5+2+2+7+2+2+7+4)
328 * Convert a value in seconds and fractions of a second to a string,
329 * giving time in days, hours, minutes, and seconds, and put the result
331 * "is_nsecs" says that "frac" is microseconds if true and milliseconds
333 * If time is negative, add a '-' to all non-null components.
336 time_secs_to_ep_str_buf(gint32 time_val, const guint32 frac, const gboolean is_nsecs,
339 int hours, mins, secs;
340 const gchar *msign = "";
341 gboolean do_comma = FALSE;
343 if(time_val == G_MININT32) { /* That Which Shall Not Be Negated */
344 ep_strbuf_append_printf(buf, "Unable to cope with time value %d", time_val);
349 time_val = -time_val;
353 secs = time_val % 60;
355 mins = time_val % 60;
357 hours = time_val % 24;
361 ep_strbuf_append_printf(buf, "%s%u day%s", msign, time_val, PLURALIZE(time_val));
366 ep_strbuf_append_printf(buf, "%s%s%u hour%s", COMMA(do_comma), msign, hours, PLURALIZE(hours));
371 ep_strbuf_append_printf(buf, "%s%s%u minute%s", COMMA(do_comma), msign, mins, PLURALIZE(mins));
375 if (secs != 0 || frac != 0) {
378 ep_strbuf_append_printf(buf, "%s%s%u.%09u seconds", COMMA(do_comma), msign, secs, frac);
380 ep_strbuf_append_printf(buf, "%s%s%u.%03u seconds", COMMA(do_comma), msign, secs, frac);
382 ep_strbuf_append_printf(buf, "%s%s%u second%s", COMMA(do_comma), msign, secs, PLURALIZE(secs));
387 time_secs_to_ep_str(const gint32 time_val)
391 buf=ep_strbuf_sized_new(TIME_SECS_LEN+1, TIME_SECS_LEN+1);
394 ep_strbuf_append(buf, "0 seconds");
398 time_secs_to_ep_str_buf(time_val, 0, FALSE, buf);
403 time_secs_to_ep_str_buf_unsigned(guint32 time_val, const guint32 frac, const gboolean is_nsecs,
406 int hours, mins, secs;
407 gboolean do_comma = FALSE;
409 secs = time_val % 60;
411 mins = time_val % 60;
413 hours = time_val % 24;
417 ep_strbuf_append_printf(buf, "%u day%s", time_val, PLURALIZE(time_val));
421 ep_strbuf_append_printf(buf, "%s%u hour%s", COMMA(do_comma), hours, PLURALIZE(hours));
425 ep_strbuf_append_printf(buf, "%s%u minute%s", COMMA(do_comma), mins, PLURALIZE(mins));
428 if (secs != 0 || frac != 0) {
431 ep_strbuf_append_printf(buf, "%s%u.%09u seconds", COMMA(do_comma), secs, frac);
433 ep_strbuf_append_printf(buf, "%s%u.%03u seconds", COMMA(do_comma), secs, frac);
435 ep_strbuf_append_printf(buf, "%s%u second%s", COMMA(do_comma), secs, PLURALIZE(secs));
440 time_secs_to_ep_str_unsigned(const guint32 time_val)
444 buf=ep_strbuf_sized_new(TIME_SECS_LEN+1, TIME_SECS_LEN+1);
447 ep_strbuf_append(buf, "0 seconds");
451 time_secs_to_ep_str_buf_unsigned(time_val, 0, FALSE, buf);
457 time_msecs_to_ep_str(gint32 time_val)
462 buf=ep_strbuf_sized_new(TIME_SECS_LEN+1+3+1, TIME_SECS_LEN+1+3+1);
465 ep_strbuf_append(buf, "0 seconds");
470 /* oops we got passed a negative time */
472 msecs = time_val % 1000;
476 msecs = time_val % 1000;
480 time_secs_to_ep_str_buf(time_val, msecs, FALSE, buf);
484 static const char mon_names[12][4] = {
499 static const gchar *get_zonename(struct tm *tmp) {
500 #if defined(HAVE_TM_ZONE)
503 if ((tmp->tm_isdst != 0) && (tmp->tm_isdst != 1)) {
506 # if defined(HAVE_TZNAME)
507 return tzname[tmp->tm_isdst];
509 # elif defined(_WIN32)
510 /* Windows C Runtime: */
511 /* _tzname is encoded using the "system default ansi code page" */
512 /* ("which is not necessarily the same as the C library locale"). */
513 /* So: _tzname must be converted to UTF8 before use. */
514 /* Alternative: use Windows GetTimeZoneInformation() to get the */
515 /* timezone name in UTF16 and convert same to UTF8. */
516 /* XXX: the result is that the timezone name will be based upon the */
517 /* system code page (iow: the charset of the system). */
518 /* Since Wireshark is not internationalized, it would seem more */
519 /* correct to show the timezone name in English, no matter what */
520 /* the system code page, but I don't how to do that (or if it's */
521 /* really even possible). */
522 /* In any case converting to UTF8 presumably at least keeps GTK */
523 /* happy. (A bug was reported wherein Wireshark crashed in GDK */
524 /* on a "Japanese version of Windows XP" when trying to copy */
525 /* the date/time string (containing a copy of _tz_name) to the */
529 static char *ws_tzname[2] = {NULL, NULL};
531 /* The g_malloc'd value returned from g_locale_to_utf8() is */
532 /* cached for all further use so there's no need to ever */
533 /* g_free() that value. */
534 if (ws_tzname[tmp->tm_isdst] == NULL) {
535 ws_tzname[tmp->tm_isdst] = g_locale_to_utf8(_tzname[tmp->tm_isdst], -1, NULL, NULL, NULL);
536 if (ws_tzname[tmp->tm_isdst] == NULL) {
537 ws_tzname[tmp->tm_isdst] = "???";
540 return ws_tzname[tmp->tm_isdst];
543 return tmp->tm_isdst ? "?DT" : "?ST";
550 abs_time_to_ep_str(const nstime_t *abs_time, const absolute_time_display_e fmt,
553 struct tm *tmp = NULL;
554 const char *zonename = "???";
557 #if (defined _WIN32) && (_MSC_VER < 1500)
558 /* calling localtime() on MSVC 2005 with huge values causes it to crash */
559 /* XXX - find the exact value that still does work */
560 /* XXX - using _USE_32BIT_TIME_T might be another way to circumvent this problem */
561 if(abs_time->secs > 2000000000) {
567 case ABSOLUTE_TIME_UTC:
568 case ABSOLUTE_TIME_DOY_UTC:
569 tmp = gmtime(&abs_time->secs);
573 case ABSOLUTE_TIME_LOCAL:
574 tmp = localtime(&abs_time->secs);
576 zonename = get_zonename(tmp);
583 case ABSOLUTE_TIME_DOY_UTC:
585 buf = ep_strdup_printf("%04d/%03d:%02d:%02d:%02d.%09ld %s",
591 (long)abs_time->nsecs,
594 buf = ep_strdup_printf("%04d/%03d:%02d:%02d:%02d.%09ld",
600 (long)abs_time->nsecs);
604 case ABSOLUTE_TIME_UTC:
605 case ABSOLUTE_TIME_LOCAL:
607 buf = ep_strdup_printf("%s %2d, %d %02d:%02d:%02d.%09ld %s",
608 mon_names[tmp->tm_mon],
614 (long)abs_time->nsecs,
617 buf = ep_strdup_printf("%s %2d, %d %02d:%02d:%02d.%09ld",
618 mon_names[tmp->tm_mon],
624 (long)abs_time->nsecs);
629 buf = ep_strdup("Not representable");
634 abs_time_secs_to_ep_str(const time_t abs_time, const absolute_time_display_e fmt,
637 struct tm *tmp = NULL;
638 const char *zonename = "???";
641 #if (defined _WIN32) && (_MSC_VER < 1500)
642 /* calling localtime() on MSVC 2005 with huge values causes it to crash */
643 /* XXX - find the exact value that still does work */
644 /* XXX - using _USE_32BIT_TIME_T might be another way to circumvent this problem */
645 if(abs_time > 2000000000) {
651 case ABSOLUTE_TIME_UTC:
652 case ABSOLUTE_TIME_DOY_UTC:
653 tmp = gmtime(&abs_time);
657 case ABSOLUTE_TIME_LOCAL:
658 tmp = localtime(&abs_time);
660 zonename = get_zonename(tmp);
667 case ABSOLUTE_TIME_DOY_UTC:
669 buf = ep_strdup_printf("%04d/%03d:%02d:%02d:%02d %s",
677 buf = ep_strdup_printf("%04d/%03d:%02d:%02d:%02d",
686 case ABSOLUTE_TIME_UTC:
687 case ABSOLUTE_TIME_LOCAL:
689 buf = ep_strdup_printf("%s %2d, %d %02d:%02d:%02d %s",
690 mon_names[tmp->tm_mon],
698 buf = ep_strdup_printf("%s %2d, %d %02d:%02d:%02d",
699 mon_names[tmp->tm_mon],
709 buf = ep_strdup("Not representable");
714 display_signed_time(gchar *buf, int buflen, const gint32 sec, gint32 frac,
715 const to_str_time_res_t units)
717 /* If the fractional part of the time stamp is negative,
718 print its absolute value and, if the seconds part isn't
719 (the seconds part should be zero in that case), stick
720 a "-" in front of the entire time stamp. */
734 case TO_STR_TIME_RES_T_SECS:
735 g_snprintf(buf, buflen, "%d", sec);
738 case TO_STR_TIME_RES_T_DSECS:
739 g_snprintf(buf, buflen, "%d.%01d", sec, frac);
742 case TO_STR_TIME_RES_T_CSECS:
743 g_snprintf(buf, buflen, "%d.%02d", sec, frac);
746 case TO_STR_TIME_RES_T_MSECS:
747 g_snprintf(buf, buflen, "%d.%03d", sec, frac);
750 case TO_STR_TIME_RES_T_USECS:
751 g_snprintf(buf, buflen, "%d.%06d", sec, frac);
754 case TO_STR_TIME_RES_T_NSECS:
755 g_snprintf(buf, buflen, "%d.%09d", sec, frac);
762 display_epoch_time(gchar *buf, int buflen, const time_t sec, gint32 frac,
763 const to_str_time_res_t units)
767 elapsed_secs = difftime(sec,(time_t)0);
769 /* This code copied from display_signed_time; keep it in case anyone
770 is looking at captures from before 1970 (???).
771 If the fractional part of the time stamp is negative,
772 print its absolute value and, if the seconds part isn't
773 (the seconds part should be zero in that case), stick
774 a "-" in front of the entire time stamp. */
777 if (elapsed_secs >= 0) {
788 case TO_STR_TIME_RES_T_SECS:
789 g_snprintf(buf, buflen, "%0.0f", elapsed_secs);
792 case TO_STR_TIME_RES_T_DSECS:
793 g_snprintf(buf, buflen, "%0.0f.%01d", elapsed_secs, frac);
796 case TO_STR_TIME_RES_T_CSECS:
797 g_snprintf(buf, buflen, "%0.0f.%02d", elapsed_secs, frac);
800 case TO_STR_TIME_RES_T_MSECS:
801 g_snprintf(buf, buflen, "%0.0f.%03d", elapsed_secs, frac);
804 case TO_STR_TIME_RES_T_USECS:
805 g_snprintf(buf, buflen, "%0.0f.%06d", elapsed_secs, frac);
808 case TO_STR_TIME_RES_T_NSECS:
809 g_snprintf(buf, buflen, "%0.0f.%09d", elapsed_secs, frac);
815 * Display a relative time as days/hours/minutes/seconds.
818 rel_time_to_ep_str(const nstime_t *rel_time)
824 buf=ep_strbuf_sized_new(1+TIME_SECS_LEN+1+6+1, 1+TIME_SECS_LEN+1+6+1);
826 /* If the nanoseconds part of the time stamp is negative,
827 print its absolute value and, if the seconds part isn't
828 (the seconds part should be zero in that case), stick
829 a "-" in front of the entire time stamp. */
830 time_val = (gint) rel_time->secs;
831 nsec = rel_time->nsecs;
832 if (time_val == 0 && nsec == 0) {
833 ep_strbuf_append(buf, "0.000000000 seconds");
838 ep_strbuf_append_c(buf, '-');
841 * We assume here that "rel_time->secs" is negative
842 * or zero; if it's not, the time stamp is bogus,
843 * with a positive seconds and negative microseconds.
845 time_val = (gint) -rel_time->secs;
848 time_secs_to_ep_str_buf(time_val, nsec, TRUE, buf);
852 #define REL_TIME_SECS_LEN (1+10+1+9+1)
855 * Display a relative time as seconds.
858 rel_time_to_secs_ep_str(const nstime_t *rel_time)
862 buf=(gchar *)ep_alloc(REL_TIME_SECS_LEN);
864 display_signed_time(buf, REL_TIME_SECS_LEN, (gint32) rel_time->secs,
865 rel_time->nsecs, TO_STR_TIME_RES_T_NSECS);
870 * Generates a string representing the bits in a bitfield at "bit_offset" from an 8 bit boundary
871 * with the length in bits of no_of_bits based on value.
876 decode_bits_in_field(const guint bit_offset, const gint no_of_bits, const guint64 value)
878 guint64 mask = 0,tmp;
884 mask = mask << (no_of_bits-1);
886 /* Prepare the string, 256 pos for the bits and zero termination, + 64 for the spaces */
887 str=(char *)ep_alloc0(256+64);
888 for(bit=0;bit<((int)(bit_offset&0x07));bit++){
897 /* read the bits for the int */
898 for(i=0;i<no_of_bits;i++){
930 /* Generate, into "buf", a string showing the bits of a bitfield.
931 Return a pointer to the character after that string. */
932 /*XXX this needs a buf_len check */
934 other_decode_bitfield_value(char *buf, const guint32 val, const guint32 mask, const int width)
942 bit = 1 << (width - 1);
945 /* This bit is part of the field. Show its value. */
951 /* This bit is not part of the field. */
966 decode_bitfield_value(char *buf, const guint32 val, const guint32 mask, const int width)
970 p = other_decode_bitfield_value(buf, val, mask, width);
971 p = g_stpcpy(p, " = ");
976 /* Generate a string describing a numeric bitfield (an N-bit field whose
977 value is just a number). */
979 decode_numeric_bitfield(const guint32 val, const guint32 mask, const int width,
986 buf=(char *)ep_alloc(1025); /* isnt this a bit overkill? */
987 /* Compute the number of bits we have to shift the bitfield right
988 to extract its value. */
989 while ((mask & (1<<shift)) == 0)
992 p = decode_bitfield_value(buf, val, mask, width);
993 g_snprintf(p, (gulong) (1025-(p-buf)), fmt, (val & mask) >> shift);
998 This function is very fast and this function is called a lot.
999 XXX update the ep_address_to_str stuff to use this function.
1002 ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len)
1004 register gchar const *p;
1005 register gchar *b=buf;
1007 if (buf_len < MAX_IP_STR_LEN) {
1008 g_snprintf ( buf, buf_len, BUF_TOO_SMALL_ERR ); /* Let the unexpected value alert user */
1012 p=fast_strings[*ad++];
1019 p=fast_strings[*ad++];
1026 p=fast_strings[*ad++];
1033 p=fast_strings[*ad];
1041 gchar* guid_to_ep_str(const e_guid_t *guid) {
1044 buf=(gchar *)ep_alloc(GUID_STR_LEN);
1045 return guid_to_str_buf(guid, buf, GUID_STR_LEN);
1048 gchar* guid_to_str_buf(const e_guid_t *guid, gchar *buf, int buf_len) {
1049 char *tempptr = buf;
1051 if (buf_len < GUID_STR_LEN) {
1052 g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len);/* Let the unexpected value alert user */
1057 tempptr = dword_to_hex(tempptr, guid->data1); /* 8 bytes */
1058 *tempptr++ = '-'; /* 1 byte */
1059 tempptr = word_to_hex(tempptr, guid->data2); /* 4 bytes */
1060 *tempptr++ = '-'; /* 1 byte */
1061 tempptr = word_to_hex(tempptr, guid->data3); /* 4 bytes */
1062 *tempptr++ = '-'; /* 1 byte */
1063 tempptr = bytes_to_hexstr(tempptr, &guid->data4[0], 2); /* 4 bytes */
1064 *tempptr++ = '-'; /* 1 byte */
1065 tempptr = bytes_to_hexstr(tempptr, &guid->data4[2], 6); /* 12 bytes */
1071 const gchar* port_type_to_str (port_type type) {
1073 case PT_NONE: return "NONE";
1074 case PT_SCTP: return "SCTP";
1075 case PT_TCP: return "TCP";
1076 case PT_UDP: return "UDP";
1077 case PT_DCCP: return "DCCP";
1078 case PT_IPX: return "IPX";
1079 case PT_NCP: return "NCP";
1080 case PT_EXCHG: return "FC EXCHG";
1081 case PT_DDP: return "DDP";
1082 case PT_SBCCS: return "FICON SBCCS";
1083 case PT_IDP: return "IDP";
1084 case PT_TIPC: return "TIPC";
1085 case PT_USB: return "USB";
1086 case PT_I2C: return "I2C";
1087 case PT_IBQP: return "IBQP";
1088 case PT_BLUETOOTH: return "BLUETOOTH";
1089 default: return "[Unknown]";
1094 oct_to_str_back(char *ptr, guint32 value)
1097 *(--ptr) = '0' + (value & 0x7);
1106 hex_to_str_back(char *ptr, int pad, guint32 value)
1109 *(--ptr) = low_nibble_of_octet_to_hex(value);
1127 uint_to_str_back(char *ptr, guint32 value)
1135 while (value >= 10) {
1136 p = fast_strings[100 + (value % 100)];
1145 *(--ptr) = (value) | '0';
1151 int_to_str_back(char *ptr, gint32 value)
1154 ptr = uint_to_str_back(ptr, -value);
1157 ptr = uint_to_str_back(ptr, value);
1163 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1168 * indent-tabs-mode: t
1171 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
1172 * :indentSize=8:tabSize=8:noTabs=false: