New oid_to_str() and oid_to_str_buf() functions

svn path=/trunk/; revision=14216
This commit is contained in:
Tomas Kukosa 2005-04-28 09:51:55 +00:00
parent 14cd9627b7
commit 3be38ac077
2 changed files with 42 additions and 0 deletions

View File

@ -892,3 +892,41 @@ address_to_str_buf(const address *addr, gchar *buf)
g_assert_not_reached();
}
}
gchar* oid_to_str(guint8 *oid, gint oid_len) {
/* static buffer */
static int cnt = 0;
static gchar strbuf[8][MAX_OID_STR_LEN];
cnt = (cnt + 1) % 8;
return oid_to_str_buf(oid, oid_len, strbuf[cnt]);
}
gchar* oid_to_str_buf(guint8 *oid, gint oid_len, gchar *buf) {
gint i;
guint8 byte;
guint32 value;
gchar *bufp;
bufp = buf; value=0;
for (i=0; i<oid_len; i++){
byte = oid[i];
if ((bufp - buf) > (MAX_OID_STR_LEN - 12)) {
bufp += sprintf(bufp, ".>>>");
break;
}
if (i == 0) {
bufp += sprintf(bufp, "%d.%d", byte/40, byte%40);
continue;
}
value = (value << 7) | (byte & 0x7F);
if (byte & 0x80) {
continue;
}
bufp += sprintf(bufp, ".%d", value);
value = 0;
}
*bufp = '\0';
return buf;
}

View File

@ -30,6 +30,8 @@
#include "nstime.h"
#include "epan/packet_info.h"
#define MAX_OID_STR_LEN 256
/*
* Resolution of a time stamp.
*/
@ -67,6 +69,8 @@ extern gchar* abs_time_secs_to_str(time_t);
extern void display_signed_time(gchar *, int, gint32, gint32, time_res_t);
extern gchar* rel_time_to_str(nstime_t*);
extern gchar* rel_time_to_secs_str(nstime_t*);
extern gchar* oid_to_str(guint8*, gint);
extern gchar* oid_to_str_buf(guint8*, gint, gchar*);
extern char *other_decode_bitfield_value(char *buf, guint32 val, guint32 mask,