From Jakub Zawadzki:
Optimizations. https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4303 svn path=/trunk/; revision=31967
This commit is contained in:
parent
1d5c24d068
commit
4e66c899d1
|
@ -637,7 +637,7 @@ static gchar *serv_name_lookup(guint port, port_type proto)
|
|||
if (!(g_resolv_flags & RESOLV_TRANSPORT) ||
|
||||
(servp = getservbyport(g_htons(port), serv_proto)) == NULL) {
|
||||
/* unknown port */
|
||||
g_snprintf(tp->name, MAXNAMELEN, "%d", port);
|
||||
guint32_to_str_buf(port, tp->name, MAXNAMELEN);
|
||||
} else {
|
||||
g_strlcpy(tp->name, servp->s_name, MAXNAMELEN);
|
||||
}
|
||||
|
@ -2615,12 +2615,8 @@ static gchar *ep_utoa(guint port)
|
|||
{
|
||||
gchar *bp = ep_alloc(MAXNAMELEN);
|
||||
|
||||
bp = &bp[MAXNAMELEN -1];
|
||||
|
||||
*bp = 0;
|
||||
do {
|
||||
*--bp = (port % 10) +'0';
|
||||
} while ((port /= 10) != 0);
|
||||
/* XXX, guint32_to_str() ? */
|
||||
guint32_to_str_buf(port, bp, MAXNAMELEN);
|
||||
return bp;
|
||||
}
|
||||
|
||||
|
|
|
@ -1157,8 +1157,6 @@ col_set_time(column_info *cinfo, gint el, nstime_t *ts, char *fieldname)
|
|||
static void
|
||||
col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_src, gboolean fill_col_exprs)
|
||||
{
|
||||
struct e_in6_addr ipv6_addr;
|
||||
|
||||
if (addr->type == AT_NONE) {
|
||||
pinfo->cinfo->col_data[col] = "";
|
||||
/* No address, nothing to do */
|
||||
|
@ -1182,7 +1180,7 @@ col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_src, gboole
|
|||
pinfo->cinfo->col_expr.col_expr[col] = "eth.src";
|
||||
else
|
||||
pinfo->cinfo->col_expr.col_expr[col] = "eth.dst";
|
||||
g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], ether_to_str(addr->data), COL_MAX_LEN);
|
||||
address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
|
||||
break;
|
||||
|
||||
case AT_IPv4:
|
||||
|
@ -1190,7 +1188,7 @@ col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_src, gboole
|
|||
pinfo->cinfo->col_expr.col_expr[col] = "ip.src";
|
||||
else
|
||||
pinfo->cinfo->col_expr.col_expr[col] = "ip.dst";
|
||||
g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], ip_to_str(addr->data), COL_MAX_LEN);
|
||||
ip_to_str_buf(addr->data, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
|
||||
break;
|
||||
|
||||
case AT_IPv6:
|
||||
|
@ -1198,8 +1196,7 @@ col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_src, gboole
|
|||
pinfo->cinfo->col_expr.col_expr[col] = "ipv6.src";
|
||||
else
|
||||
pinfo->cinfo->col_expr.col_expr[col] = "ipv6.dst";
|
||||
memcpy(&ipv6_addr.bytes, addr->data, sizeof ipv6_addr.bytes);
|
||||
g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], ip6_to_str(&ipv6_addr), COL_MAX_LEN);
|
||||
address_to_str_buf(addr, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
|
||||
break;
|
||||
|
||||
case AT_ATALK:
|
||||
|
@ -1249,11 +1246,11 @@ col_set_port(packet_info *pinfo, int col, gboolean is_res, gboolean is_src, gboo
|
|||
if (is_res)
|
||||
g_strlcpy(pinfo->cinfo->col_buf[col], get_sctp_port(port), COL_MAX_LEN);
|
||||
else
|
||||
g_snprintf(pinfo->cinfo->col_buf[col], COL_MAX_LEN, "%u", port);
|
||||
guint32_to_str_buf(port, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
|
||||
break;
|
||||
|
||||
case PT_TCP:
|
||||
g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "%u", port);
|
||||
guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
|
||||
if (is_res)
|
||||
g_strlcpy(pinfo->cinfo->col_buf[col], get_tcp_port(port), COL_MAX_LEN);
|
||||
else
|
||||
|
@ -1265,7 +1262,7 @@ col_set_port(packet_info *pinfo, int col, gboolean is_res, gboolean is_src, gboo
|
|||
break;
|
||||
|
||||
case PT_UDP:
|
||||
g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "%u", port);
|
||||
guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
|
||||
if (is_res)
|
||||
g_strlcpy(pinfo->cinfo->col_buf[col], get_udp_port(port), COL_MAX_LEN);
|
||||
else
|
||||
|
@ -1281,7 +1278,7 @@ col_set_port(packet_info *pinfo, int col, gboolean is_res, gboolean is_src, gboo
|
|||
pinfo->cinfo->col_expr.col_expr[col] = "ddp.src_socket";
|
||||
else
|
||||
pinfo->cinfo->col_expr.col_expr[col] = "ddp.dst_socket";
|
||||
g_snprintf(pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN, "%u", port);
|
||||
guint32_to_str_buf(port, pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
|
||||
g_strlcpy(pinfo->cinfo->col_buf[col], pinfo->cinfo->col_expr.col_expr_val[col], COL_MAX_LEN);
|
||||
break;
|
||||
|
||||
|
@ -1351,7 +1348,7 @@ col_fill_in_frame_data(frame_data *fd, column_info *cinfo, gint col, gboolean fi
|
|||
switch (cinfo->col_fmt[col]) {
|
||||
|
||||
case COL_NUMBER:
|
||||
g_snprintf(cinfo->col_buf[col], COL_MAX_LEN, "%u", fd->num);
|
||||
guint32_to_str_buf(fd->num, cinfo->col_buf[col], COL_MAX_LEN);
|
||||
cinfo->col_data[col] = cinfo->col_buf[col];
|
||||
break;
|
||||
|
||||
|
@ -1366,12 +1363,12 @@ col_fill_in_frame_data(frame_data *fd, column_info *cinfo, gint col, gboolean fi
|
|||
break;
|
||||
|
||||
case COL_PACKET_LENGTH:
|
||||
g_snprintf(cinfo->col_buf[col], COL_MAX_LEN, "%u", fd->pkt_len);
|
||||
guint32_to_str_buf(fd->pkt_len, cinfo->col_buf[col], COL_MAX_LEN);
|
||||
cinfo->col_data[col] = cinfo->col_buf[col];
|
||||
break;
|
||||
|
||||
case COL_CUMULATIVE_BYTES:
|
||||
g_snprintf(cinfo->col_buf[col], COL_MAX_LEN, "%u", fd->cum_bytes);
|
||||
guint32_to_str_buf(fd->cum_bytes, cinfo->col_buf[col], COL_MAX_LEN);
|
||||
cinfo->col_data[col] = cinfo->col_buf[col];
|
||||
break;
|
||||
|
||||
|
@ -1508,7 +1505,7 @@ col_fill_in(packet_info *pinfo, gboolean fill_col_exprs, gboolean fill_fd_colums
|
|||
break;
|
||||
|
||||
case COL_VSAN:
|
||||
g_snprintf(pinfo->cinfo->col_buf[i], COL_MAX_LEN, "%u", pinfo->vsan);
|
||||
guint32_to_str_buf(pinfo->vsan, pinfo->cinfo->col_buf[i], COL_MAX_LEN);
|
||||
pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
|
||||
break;
|
||||
|
||||
|
@ -1715,7 +1712,7 @@ gchar *ptr;
|
|||
|
||||
switch (cinfo->col_fmt[col]) {
|
||||
case COL_NUMBER: /* frame number */
|
||||
g_snprintf(buf, COL_MAX_LEN, "%u", fd->num);
|
||||
guint32_to_str_buf(fd->num, buf, COL_MAX_LEN);
|
||||
break;
|
||||
|
||||
case COL_CLS_TIME:
|
||||
|
@ -1738,11 +1735,11 @@ gchar *ptr;
|
|||
break;
|
||||
|
||||
case COL_PACKET_LENGTH: /* fd->pkt_len */
|
||||
g_snprintf(buf, COL_MAX_LEN, "%u", fd->pkt_len);
|
||||
guint32_to_str_buf(fd->pkt_len, buf, COL_MAX_LEN);
|
||||
break;
|
||||
|
||||
case COL_CUMULATIVE_BYTES: /* fd->cum_bytes */
|
||||
g_snprintf(buf, COL_MAX_LEN, "%u", fd->cum_bytes);
|
||||
guint32_to_str_buf(fd->cum_bytes, buf, COL_MAX_LEN);
|
||||
break;
|
||||
|
||||
case COL_DEF_SRC:
|
||||
|
@ -1790,7 +1787,7 @@ gchar *ptr;
|
|||
case COL_UNRES_DST_PORT:
|
||||
/* hack */
|
||||
if (GPOINTER_TO_UINT(fd->col_text[col]) <= 65536)
|
||||
g_snprintf(buf, COL_MAX_LEN, "%u", GPOINTER_TO_UINT(fd->col_text[col]));
|
||||
guint32_to_str_buf(GPOINTER_TO_UINT(fd->col_text[col], buf, COL_MAX_LEN));
|
||||
else
|
||||
ptr = fd->col_text[col];
|
||||
break;
|
||||
|
@ -1803,7 +1800,7 @@ gchar *ptr;
|
|||
break;
|
||||
|
||||
case COL_VSAN:
|
||||
g_snprintf(buf, COL_MAX_LEN, "%u", GPOINTER_TO_UINT(fd->col_text[col]));
|
||||
guint32_to_str_buf(GPOINTER_TO_UINT(fd->col_text[col]), buf, COL_MAX_LEN);
|
||||
break;
|
||||
|
||||
case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
|
||||
|
|
|
@ -115,7 +115,15 @@ integer_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
|
|||
static void
|
||||
integer_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
|
||||
{
|
||||
sprintf(buf, "%d", fv->value.sinteger);
|
||||
guint32 val;
|
||||
|
||||
if (fv->value.sinteger < 0) {
|
||||
*buf++ = '-';
|
||||
val = -fv->value.sinteger;
|
||||
} else
|
||||
val = fv->value.sinteger;
|
||||
|
||||
guint32_to_str_buf(val, buf, 11);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -127,7 +135,7 @@ uinteger_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
|
|||
static void
|
||||
uinteger_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
|
||||
{
|
||||
sprintf(buf, "%u", fv->value.uinteger);
|
||||
guint32_to_str_buf(fv->value.uinteger, buf, 11);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -403,7 +411,8 @@ boolean_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
|
|||
static void
|
||||
boolean_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
|
||||
{
|
||||
sprintf(buf, "%s", fv->value.uinteger ? "1" : "0");
|
||||
*buf++ = (fv->value.uinteger) ? '1' : '0';
|
||||
*buf = '\0';
|
||||
}
|
||||
|
||||
/* Checks for equality with zero or non-zero */
|
||||
|
|
|
@ -370,49 +370,6 @@ format_text_wsp(const guchar *string, size_t len)
|
|||
return fmtbuf[idx];
|
||||
}
|
||||
|
||||
/* Max string length for displaying byte string. */
|
||||
#define MAX_BYTE_STR_LEN 48
|
||||
|
||||
/* Turn an array of bytes into a string showing the bytes in hex. */
|
||||
#define N_BYTES_TO_STR_STRINGS 6
|
||||
gchar *
|
||||
bytes_to_str(const guint8 *bd, int bd_len) {
|
||||
return bytes_to_str_punct(bd,bd_len,'\0');
|
||||
}
|
||||
|
||||
/* Turn an array of bytes into a string showing the bytes in hex with
|
||||
* punct as a bytes separator.
|
||||
*/
|
||||
gchar *
|
||||
bytes_to_str_punct(const guint8 *bd, int bd_len, gchar punct) {
|
||||
gchar *cur;
|
||||
gchar *p;
|
||||
int len;
|
||||
|
||||
cur=ep_alloc(MAX_BYTE_STR_LEN+3+1);
|
||||
p = cur;
|
||||
len = MAX_BYTE_STR_LEN;
|
||||
while (bd_len > 0 && len > 0) {
|
||||
*p++ = hex[(*bd) >> 4];
|
||||
*p++ = hex[(*bd) & 0xF];
|
||||
len -= 2;
|
||||
bd++;
|
||||
bd_len--;
|
||||
if(punct && bd_len > 0){
|
||||
*p++ = punct;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
if (bd_len != 0) {
|
||||
/* Note that we're not showing the full string. */
|
||||
*p++ = '.';
|
||||
*p++ = '.';
|
||||
*p++ = '.';
|
||||
}
|
||||
*p = '\0';
|
||||
return cur;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_byte_sep(guint8 c)
|
||||
{
|
||||
|
|
429
epan/to_str.c
429
epan/to_str.c
|
@ -73,20 +73,8 @@
|
|||
*/
|
||||
#define BUF_TOO_SMALL_ERR "[Buffer too small]"
|
||||
|
||||
/* Routine to convert a sequence of bytes to a hex string, one byte/two hex
|
||||
* digits at at a time, with a specified punctuation character between
|
||||
* the bytes.
|
||||
*
|
||||
* If punct is '\0', no punctuation is applied (and thus
|
||||
* the resulting string is (len-1) bytes shorter)
|
||||
*/
|
||||
gchar *
|
||||
bytestring_to_str(const guint8 *ad, guint32 len, char punct) {
|
||||
gchar *buf;
|
||||
gchar *p;
|
||||
int i = (int) len - 1;
|
||||
guint32 octet;
|
||||
size_t buflen;
|
||||
static inline char *
|
||||
byte_to_hex(char *out, guint32 dword) {
|
||||
/* At least one version of Apple's C compiler/linker is buggy, causing
|
||||
a complaint from the linker about the "literal C string section"
|
||||
not ending with '\0' if we initialize a 16-element "char" array with
|
||||
|
@ -97,30 +85,237 @@ bytestring_to_str(const guint8 *ad, guint32 len, char punct) {
|
|||
{ '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
|
||||
*out++ = hex_digits[(dword >> 4) & 0xF];
|
||||
*out++ = hex_digits[dword & 0xF];
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
word_to_hex(char *out, guint16 word) {
|
||||
out = byte_to_hex(out, word >> 8);
|
||||
out = byte_to_hex(out, word);
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
dword_to_hex(char *out, guint32 dword) {
|
||||
out = byte_to_hex(out, dword >> 24);
|
||||
out = byte_to_hex(out, dword >> 16);
|
||||
out = byte_to_hex(out, dword >> 8);
|
||||
out = byte_to_hex(out, dword);
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
dword_to_hex_punct(char *out, guint32 dword, char punct) {
|
||||
out = byte_to_hex(out, dword >> 24);
|
||||
*out++ = punct;
|
||||
out = byte_to_hex(out, dword >> 16);
|
||||
*out++ = punct;
|
||||
out = byte_to_hex(out, dword >> 8);
|
||||
*out++ = punct;
|
||||
out = byte_to_hex(out, dword);
|
||||
return out;
|
||||
}
|
||||
|
||||
/* buffer need to be at least len * 2 size */
|
||||
static inline char *
|
||||
bytes_to_hexstr(char *out, const guint8 *ad, guint32 len) {
|
||||
guint32 i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
out = byte_to_hex(out, ad[i]);
|
||||
return out;
|
||||
}
|
||||
|
||||
/* buffer need to be at least len * 3 - 1 size */
|
||||
static inline char *
|
||||
bytes_to_hexstr_punct(char *out, const guint8 *ad, guint32 len, char punct) {
|
||||
guint32 i;
|
||||
|
||||
out = byte_to_hex(out, ad[0]);
|
||||
for (i = 1; i < len; i++) {
|
||||
*out++ = punct;
|
||||
out = byte_to_hex(out, ad[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Routine to convert a sequence of bytes to a hex string, one byte/two hex
|
||||
* digits at at a time, with a specified punctuation character between
|
||||
* the bytes.
|
||||
*
|
||||
* If punct is '\0', no punctuation is applied (and thus
|
||||
* the resulting string is (len-1) bytes shorter)
|
||||
*/
|
||||
gchar *
|
||||
bytestring_to_str(const guint8 *ad, guint32 len, char punct) {
|
||||
gchar *buf;
|
||||
size_t buflen;
|
||||
|
||||
/* XXX, Old code was using int as iterator... Why len is guint32 anyway?! (darkjames) */
|
||||
if ( ((int) len) < 0)
|
||||
return "";
|
||||
|
||||
if (!len)
|
||||
return "";
|
||||
|
||||
if (punct)
|
||||
buflen=len*3;
|
||||
else
|
||||
buflen=len*2 + 1;
|
||||
|
||||
if (buflen < 3 || i < 0) {
|
||||
return "";
|
||||
buf=ep_alloc(buflen);
|
||||
|
||||
if (punct)
|
||||
bytes_to_hexstr_punct(buf, ad, len, punct);
|
||||
else
|
||||
bytes_to_hexstr(buf, ad, len);
|
||||
|
||||
buf[buflen-1] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
buf=ep_alloc(buflen);
|
||||
p = &buf[buflen - 1];
|
||||
*p = '\0';
|
||||
for (;;) {
|
||||
octet = ad[i];
|
||||
*--p = hex_digits[octet&0xF];
|
||||
octet >>= 4;
|
||||
*--p = hex_digits[octet&0xF];
|
||||
if (i <= 0)
|
||||
break;
|
||||
if (punct)
|
||||
*--p = punct;
|
||||
i--;
|
||||
/* Max string length for displaying byte string. */
|
||||
#define MAX_BYTE_STR_LEN 48
|
||||
|
||||
gchar *
|
||||
bytes_to_str(const guint8 *bd, int bd_len) {
|
||||
gchar *cur;
|
||||
gchar *cur_ptr;
|
||||
int truncated = 0;
|
||||
|
||||
cur=ep_alloc(MAX_BYTE_STR_LEN+3+1);
|
||||
|
||||
if (bd_len > MAX_BYTE_STR_LEN/2) { /* bd_len > 24 */
|
||||
truncated = 1;
|
||||
bd_len = MAX_BYTE_STR_LEN/2;
|
||||
}
|
||||
return p;
|
||||
|
||||
cur_ptr = bytes_to_hexstr(cur, bd, bd_len); /* max MAX_BYTE_STR_LEN bytes */
|
||||
|
||||
if (truncated)
|
||||
cur_ptr = g_stpcpy(cur_ptr, "..."); /* 3 bytes */
|
||||
|
||||
*cur_ptr = '\0'; /* 1 byte */
|
||||
return cur;
|
||||
}
|
||||
|
||||
/* Turn an array of bytes into a string showing the bytes in hex with
|
||||
* punct as a bytes separator.
|
||||
*/
|
||||
gchar *
|
||||
bytes_to_str_punct(const guint8 *bd, int bd_len, gchar punct) {
|
||||
gchar *cur;
|
||||
gchar *cur_ptr;
|
||||
int truncated = 0;
|
||||
|
||||
if (!punct)
|
||||
return bytes_to_str(bd, bd_len);
|
||||
|
||||
cur=ep_alloc(MAX_BYTE_STR_LEN+3+1);
|
||||
|
||||
if (bd_len > MAX_BYTE_STR_LEN/3) { /* bd_len > 16 */
|
||||
truncated = 1;
|
||||
bd_len = MAX_BYTE_STR_LEN/3;
|
||||
}
|
||||
|
||||
cur_ptr = bytes_to_hexstr_punct(cur, bd, bd_len, punct); /* max MAX_BYTE_STR_LEN-1 bytes */
|
||||
|
||||
if (truncated) {
|
||||
*cur_ptr++ = punct; /* 1 byte */
|
||||
cur_ptr = g_stpcpy(cur_ptr, "..."); /* 3 bytes */
|
||||
}
|
||||
|
||||
*cur_ptr = '\0';
|
||||
return cur;
|
||||
}
|
||||
|
||||
static int
|
||||
guint32_to_str_buf_len(guint32 u) {
|
||||
if (u >= 1000000000)return 10;
|
||||
if (u >= 100000000) return 9;
|
||||
if (u >= 10000000) return 8;
|
||||
if (u >= 1000000) return 7;
|
||||
if (u >= 100000) return 6;
|
||||
if (u >= 10000) return 5;
|
||||
if (u >= 1000) return 4;
|
||||
if (u >= 100) return 3;
|
||||
if (u >= 10) return 2;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char * const fast_strings[] = {
|
||||
"0", "1", "2", "3", "4", "5", "6", "7",
|
||||
"8", "9", "10", "11", "12", "13", "14", "15",
|
||||
"16", "17", "18", "19", "20", "21", "22", "23",
|
||||
"24", "25", "26", "27", "28", "29", "30", "31",
|
||||
"32", "33", "34", "35", "36", "37", "38", "39",
|
||||
"40", "41", "42", "43", "44", "45", "46", "47",
|
||||
"48", "49", "50", "51", "52", "53", "54", "55",
|
||||
"56", "57", "58", "59", "60", "61", "62", "63",
|
||||
"64", "65", "66", "67", "68", "69", "70", "71",
|
||||
"72", "73", "74", "75", "76", "77", "78", "79",
|
||||
"80", "81", "82", "83", "84", "85", "86", "87",
|
||||
"88", "89", "90", "91", "92", "93", "94", "95",
|
||||
"96", "97", "98", "99", "100", "101", "102", "103",
|
||||
"104", "105", "106", "107", "108", "109", "110", "111",
|
||||
"112", "113", "114", "115", "116", "117", "118", "119",
|
||||
"120", "121", "122", "123", "124", "125", "126", "127",
|
||||
"128", "129", "130", "131", "132", "133", "134", "135",
|
||||
"136", "137", "138", "139", "140", "141", "142", "143",
|
||||
"144", "145", "146", "147", "148", "149", "150", "151",
|
||||
"152", "153", "154", "155", "156", "157", "158", "159",
|
||||
"160", "161", "162", "163", "164", "165", "166", "167",
|
||||
"168", "169", "170", "171", "172", "173", "174", "175",
|
||||
"176", "177", "178", "179", "180", "181", "182", "183",
|
||||
"184", "185", "186", "187", "188", "189", "190", "191",
|
||||
"192", "193", "194", "195", "196", "197", "198", "199",
|
||||
"200", "201", "202", "203", "204", "205", "206", "207",
|
||||
"208", "209", "210", "211", "212", "213", "214", "215",
|
||||
"216", "217", "218", "219", "220", "221", "222", "223",
|
||||
"224", "225", "226", "227", "228", "229", "230", "231",
|
||||
"232", "233", "234", "235", "236", "237", "238", "239",
|
||||
"240", "241", "242", "243", "244", "245", "246", "247",
|
||||
"248", "249", "250", "251", "252", "253", "254", "255"
|
||||
};
|
||||
|
||||
void
|
||||
guint32_to_str_buf(guint32 u, gchar *buf, int buf_len) {
|
||||
int str_len = guint32_to_str_buf_len(u)+1;
|
||||
|
||||
gchar *bp = &buf[str_len];
|
||||
gchar const *p;
|
||||
|
||||
if (buf_len < str_len) {
|
||||
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
|
||||
return;
|
||||
}
|
||||
|
||||
*--bp = '\0';
|
||||
|
||||
while (u >= 10) {
|
||||
p = fast_strings[100 + (u % 100)];
|
||||
|
||||
*--bp = p[2];
|
||||
*--bp = p[1];
|
||||
|
||||
u /= 100;
|
||||
}
|
||||
|
||||
if (bp != buf) /* ugly, fixme! */
|
||||
*--bp = (u % 10) | '0';
|
||||
}
|
||||
|
||||
gchar *
|
||||
guint32_to_str(guint32 u) {
|
||||
int str_len = 16; /* guint32_to_str_buf_len(u)+1; */
|
||||
|
||||
gchar *bp = ep_alloc(str_len);
|
||||
guint32_to_str_buf(u, bp, str_len);
|
||||
|
||||
return bp;
|
||||
}
|
||||
|
||||
#define PLURALIZE(n) (((n) > 1) ? "s" : "")
|
||||
|
@ -727,40 +922,6 @@ ip_to_str(const guint8 *ad) {
|
|||
This function is very fast and this function is called a lot.
|
||||
XXX update the ep_address_to_str stuff to use this function.
|
||||
*/
|
||||
static const char * const fast_strings[] = {
|
||||
"0", "1", "2", "3", "4", "5", "6", "7",
|
||||
"8", "9", "10", "11", "12", "13", "14", "15",
|
||||
"16", "17", "18", "19", "20", "21", "22", "23",
|
||||
"24", "25", "26", "27", "28", "29", "30", "31",
|
||||
"32", "33", "34", "35", "36", "37", "38", "39",
|
||||
"40", "41", "42", "43", "44", "45", "46", "47",
|
||||
"48", "49", "50", "51", "52", "53", "54", "55",
|
||||
"56", "57", "58", "59", "60", "61", "62", "63",
|
||||
"64", "65", "66", "67", "68", "69", "70", "71",
|
||||
"72", "73", "74", "75", "76", "77", "78", "79",
|
||||
"80", "81", "82", "83", "84", "85", "86", "87",
|
||||
"88", "89", "90", "91", "92", "93", "94", "95",
|
||||
"96", "97", "98", "99", "100", "101", "102", "103",
|
||||
"104", "105", "106", "107", "108", "109", "110", "111",
|
||||
"112", "113", "114", "115", "116", "117", "118", "119",
|
||||
"120", "121", "122", "123", "124", "125", "126", "127",
|
||||
"128", "129", "130", "131", "132", "133", "134", "135",
|
||||
"136", "137", "138", "139", "140", "141", "142", "143",
|
||||
"144", "145", "146", "147", "148", "149", "150", "151",
|
||||
"152", "153", "154", "155", "156", "157", "158", "159",
|
||||
"160", "161", "162", "163", "164", "165", "166", "167",
|
||||
"168", "169", "170", "171", "172", "173", "174", "175",
|
||||
"176", "177", "178", "179", "180", "181", "182", "183",
|
||||
"184", "185", "186", "187", "188", "189", "190", "191",
|
||||
"192", "193", "194", "195", "196", "197", "198", "199",
|
||||
"200", "201", "202", "203", "204", "205", "206", "207",
|
||||
"208", "209", "210", "211", "212", "213", "214", "215",
|
||||
"216", "217", "218", "219", "220", "221", "222", "223",
|
||||
"224", "225", "226", "227", "228", "229", "230", "231",
|
||||
"232", "233", "234", "235", "236", "237", "238", "239",
|
||||
"240", "241", "242", "243", "244", "245", "246", "247",
|
||||
"248", "249", "250", "251", "252", "253", "254", "255"
|
||||
};
|
||||
void
|
||||
ip_to_str_buf(const guint8 *ad, gchar *buf, int buf_len)
|
||||
{
|
||||
|
@ -852,38 +1013,24 @@ ipxnet_to_string(const guint8 *ad)
|
|||
gchar *
|
||||
ipxnet_to_str_punct(const guint32 ad, char punct)
|
||||
{
|
||||
gchar *buf;
|
||||
gchar *p;
|
||||
int i;
|
||||
guint32 octet;
|
||||
/* At least one version of Apple's C compiler/linker is buggy, causing
|
||||
a complaint from the linker about the "literal C string section"
|
||||
not ending with '\0' if we initialize a 16-element "char" array with
|
||||
a 16-character string, the fact that initializing such an array with
|
||||
such a string is perfectly legitimate ANSI C nonwithstanding, the 17th
|
||||
'\0' byte in the string nonwithstanding. */
|
||||
static const gchar hex_digits[16] =
|
||||
{ '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
static const guint32 octet_mask[4] =
|
||||
{ 0xff000000 , 0x00ff0000, 0x0000ff00, 0x000000ff };
|
||||
gchar *buf = ep_alloc(12);
|
||||
|
||||
buf=ep_alloc(12);
|
||||
p = &buf[12];
|
||||
*--p = '\0';
|
||||
i = 3;
|
||||
for (;;) {
|
||||
octet = (ad & octet_mask[i]) >> ((3 - i) * 8);
|
||||
*--p = hex_digits[octet&0xF];
|
||||
octet >>= 4;
|
||||
*--p = hex_digits[octet&0xF];
|
||||
if (i == 0)
|
||||
break;
|
||||
if (punct)
|
||||
*--p = punct;
|
||||
i--;
|
||||
*dword_to_hex_punct(buf, ad, punct) = '\0';
|
||||
return buf;
|
||||
}
|
||||
return p;
|
||||
|
||||
static void
|
||||
vines_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
|
||||
{
|
||||
if (buf_len < 14) {
|
||||
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len); /* Let the unexpected value alert user */
|
||||
return;
|
||||
}
|
||||
|
||||
buf = dword_to_hex(buf, pntohl(&addrp[0])); /* 8 bytes */
|
||||
*buf++ = '.'; /* 1 byte */
|
||||
buf = word_to_hex(buf, pntohs(&addrp[4])); /* 4 bytes */
|
||||
*buf = '\0'; /* 1 byte */
|
||||
}
|
||||
|
||||
gchar *
|
||||
|
@ -891,20 +1038,14 @@ vines_addr_to_str(const guint8 *addrp)
|
|||
{
|
||||
gchar *buf;
|
||||
|
||||
buf=ep_alloc(214);
|
||||
buf=ep_alloc(214); /* XXX, 14 here? */
|
||||
|
||||
vines_addr_to_str_buf(addrp, buf, 214);
|
||||
return buf;
|
||||
}
|
||||
|
||||
void
|
||||
vines_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
|
||||
{
|
||||
g_snprintf(buf, buf_len, "%08x.%04x", pntohl(&addrp[0]), pntohs(&addrp[4]));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
static void
|
||||
usb_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
|
||||
{
|
||||
if(pletohl(&addrp[0])==0xffffffff){
|
||||
|
@ -914,7 +1055,7 @@ usb_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
tipc_addr_to_str_buf( const guint8 *data, gchar *buf, int buf_len){
|
||||
guint8 zone;
|
||||
guint16 subnetwork;
|
||||
|
@ -964,10 +1105,12 @@ fcwwn_to_str (const guint8 *ad)
|
|||
int fmt;
|
||||
guint8 oui[6];
|
||||
gchar *ethstr;
|
||||
gchar *ethptr;
|
||||
|
||||
if (ad == NULL) return NULL;
|
||||
|
||||
ethstr=ep_alloc(512);
|
||||
ethptr = bytes_to_hexstr_punct(ethstr, ad, 8, ':'); /* 23 bytes */
|
||||
|
||||
fmt = (ad[0] & 0xF0) >> 4;
|
||||
|
||||
|
@ -976,9 +1119,8 @@ fcwwn_to_str (const guint8 *ad)
|
|||
case FC_NH_NAA_IEEE:
|
||||
case FC_NH_NAA_IEEE_E:
|
||||
memcpy (oui, &ad[2], 6);
|
||||
g_snprintf (ethstr, 512, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)", ad[0],
|
||||
ad[1], ad[2], ad[3], ad[4], ad[5], ad[6], ad[7],
|
||||
get_manuf_name (oui));
|
||||
|
||||
g_snprintf (ethptr, 512-23, " (%s)", get_manuf_name (oui));
|
||||
break;
|
||||
|
||||
case FC_NH_NAA_IEEE_R:
|
||||
|
@ -989,14 +1131,11 @@ fcwwn_to_str (const guint8 *ad)
|
|||
oui[4] = ((ad[4] & 0x0F) << 4) | ((ad[5] & 0xF0) >> 4);
|
||||
oui[5] = ((ad[5] & 0x0F) << 4) | ((ad[6] & 0xF0) >> 4);
|
||||
|
||||
g_snprintf (ethstr, 512, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)", ad[0],
|
||||
ad[1], ad[2], ad[3], ad[4], ad[5], ad[6], ad[7],
|
||||
get_manuf_name (oui));
|
||||
g_snprintf (ethptr, 512-23, " (%s)", get_manuf_name (oui));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_snprintf (ethstr, 512, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", ad[0],
|
||||
ad[1], ad[2], ad[3], ad[4], ad[5], ad[6], ad[7]);
|
||||
*ethptr = '\0';
|
||||
break;
|
||||
}
|
||||
return (ethstr);
|
||||
|
@ -1036,52 +1175,6 @@ se_address_to_str(const address *addr)
|
|||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX - see also bytes_to_str() and bytes_to_str_punct() in strutil.c.
|
||||
* They fill in an ep_allocated buffer, rather than a buffer supplied
|
||||
* to them, and put in "..." if the string is "too long".
|
||||
*/
|
||||
|
||||
static inline char *
|
||||
byte_to_hex(char *out, guint8 octet) {
|
||||
/* At least one version of Apple's C compiler/linker is buggy, causing
|
||||
a complaint from the linker about the "literal C string section"
|
||||
not ending with '\0' if we initialize a 16-element "char" array with
|
||||
a 16-character string, the fact that initializing such an array with
|
||||
such a string is perfectly legitimate ANSI C nonwithstanding, the 17th
|
||||
'\0' byte in the string nonwithstanding. */
|
||||
static const gchar hex_digits[16] =
|
||||
{ '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
|
||||
*out++ = hex_digits[octet >> 4];
|
||||
*out++ = hex_digits[octet & 0xF];
|
||||
return out;
|
||||
}
|
||||
|
||||
/* buffer need to be at least len * 2 size */
|
||||
static inline char *
|
||||
bytes_to_hexstr(char *out, const guint8 *ad, guint32 len) {
|
||||
guint32 i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
out = byte_to_hex(out, ad[i]);
|
||||
return out;
|
||||
}
|
||||
|
||||
/* buffer need to be at least len * 3 - 1 size */
|
||||
static inline char *
|
||||
bytes_to_hexstr_punct(char *out, const guint8 *ad, guint32 len, char punct) {
|
||||
guint32 i;
|
||||
|
||||
out = byte_to_hex(out, ad[0]);
|
||||
for (i = 1; i < len; i++) {
|
||||
*out++ = punct;
|
||||
out = byte_to_hex(out, ad[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void
|
||||
address_to_str_buf(const address *addr, gchar *buf, int buf_len)
|
||||
{
|
||||
|
@ -1179,9 +1272,25 @@ gchar* guid_to_str(const e_guid_t *guid) {
|
|||
}
|
||||
|
||||
gchar* guid_to_str_buf(const e_guid_t *guid, gchar *buf, int buf_len) {
|
||||
g_snprintf(buf, buf_len, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
guid->data1, guid->data2, guid->data3,
|
||||
guid->data4[0], guid->data4[1], guid->data4[2], guid->data4[3], guid->data4[4], guid->data4[5], guid->data4[6], guid->data4[7]);
|
||||
char *tempptr = buf;
|
||||
|
||||
if (buf_len < GUID_STR_LEN) {
|
||||
g_strlcpy(buf, BUF_TOO_SMALL_ERR, buf_len);/* Let the unexpected value alert user */
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* 37 bytes */
|
||||
tempptr = dword_to_hex(tempptr, guid->data1); /* 8 bytes */
|
||||
*tempptr++ = '-'; /* 1 byte */
|
||||
tempptr = word_to_hex(tempptr, guid->data2); /* 4 bytes */
|
||||
*tempptr++ = '-'; /* 1 byte */
|
||||
tempptr = word_to_hex(tempptr, guid->data3); /* 4 bytes */
|
||||
*tempptr++ = '-'; /* 1 byte */
|
||||
tempptr = bytes_to_hexstr(tempptr, &guid->data4[0], 2); /* 4 bytes */
|
||||
*tempptr++ = '-'; /* 1 byte */
|
||||
tempptr = bytes_to_hexstr(tempptr, &guid->data4[2], 6); /* 12 bytes */
|
||||
|
||||
*tempptr = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,6 @@ extern gchar* ipx_addr_to_str(guint32, const guint8 *);
|
|||
extern gchar* ipxnet_to_string(const guint8 *ad);
|
||||
extern gchar* ipxnet_to_str_punct(const guint32 ad, char punct);
|
||||
extern gchar* vines_addr_to_str(const guint8 *addrp);
|
||||
extern void vines_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len);
|
||||
extern gchar* time_secs_to_str(gint32);
|
||||
extern gchar* time_secs_to_str_unsigned(guint32);
|
||||
extern gchar* time_msecs_to_str(gint32);
|
||||
|
@ -79,13 +78,14 @@ extern gchar* abs_time_secs_to_str(time_t, gboolean);
|
|||
extern void display_signed_time(gchar *, int, gint32, gint32, to_str_time_res_t);
|
||||
extern void display_epoch_time(gchar *, int, time_t, gint32, to_str_time_res_t);
|
||||
|
||||
extern gchar* guint32_to_str(guint32 u);
|
||||
extern void guint32_to_str_buf(guint32 u, gchar *buf, int buf_len);
|
||||
|
||||
extern gchar* rel_time_to_str(nstime_t*);
|
||||
extern gchar* rel_time_to_secs_str(nstime_t*);
|
||||
extern gchar* guid_to_str(const e_guid_t*);
|
||||
extern gchar* guid_to_str_buf(const e_guid_t*, gchar*, int);
|
||||
|
||||
void tipc_addr_to_str_buf( const guint8 *data, gchar *buf, int buf_len);
|
||||
|
||||
extern char *decode_bits_in_field(gint bit_offset, gint no_of_bits, guint64 value);
|
||||
|
||||
extern char *other_decode_bitfield_value(char *buf, guint32 val, guint32 mask,
|
||||
|
|
Loading…
Reference in New Issue