diff options
author | Anders Broman <anders.broman@ericsson.com> | 2009-05-15 18:38:13 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2009-05-15 18:38:13 +0000 |
commit | 1464f7ca84792e42dbaeb57f66efb40783d9fea7 (patch) | |
tree | 3e97b6d2a0fa0012581c37903f754b47aaf3503c /epan/to_str.c | |
parent | 54cfb391431ab5f4bc02bf8265b3ac9e393226b8 (diff) |
Introduce decode_bits_in_field() and use it.
clean up some left owers from previous checkin.
svn path=/trunk/; revision=28373
Diffstat (limited to 'epan/to_str.c')
-rw-r--r-- | epan/to_str.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/epan/to_str.c b/epan/to_str.c index 1cb44687e6..37b6f3c49b 100644 --- a/epan/to_str.c +++ b/epan/to_str.c @@ -741,6 +741,59 @@ fcwwn_to_str (const guint8 *ad) } return (ethstr); } +/* + * Generates a string representing the bits in a bitfield at "bit_offset" from an 8 bit boundary + * with the length in bits of no_of_bits based on value. + * Ex: ..xx x... + */ + +char * +decode_bits_in_field(gint bit_offset, gint no_of_bits, guint64 value) +{ + guint64 mask = 0,tmp; + char *str; + int bit; + int i; + + mask = 1; + mask = mask << (no_of_bits-1); + + /* prepare the string */ + str=ep_alloc(256); + str[0]='\0'; + for(bit=0;bit<((int)(bit_offset&0x07));bit++){ + if(bit&&(!(bit%4))){ + strcat(str, " "); + } + strcat(str,"."); + } + + /* read the bits for the int */ + for(i=0;i<no_of_bits;i++){ + if(bit&&(!(bit%4))){ + strcat(str, " "); + } + if(bit&&(!(bit%8))){ + strcat(str, " "); + } + bit++; + tmp = value & mask; + if(tmp != 0){ + strcat(str, "1"); + } else { + strcat(str, "0"); + } + mask = mask>>1; + } + + for(;bit%8;bit++){ + if(bit&&(!(bit%4))){ + strcat(str, " "); + } + strcat(str,"."); + } + return str; +} /* Generate, into "buf", a string showing the bits of a bitfield. Return a pointer to the character after that string. */ |