diff options
author | Luke Mewburn <luke@mewburn.net> | 2014-12-21 01:05:07 +1100 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2014-12-21 01:56:56 +0000 |
commit | d7fd00de9f35e4f54765e3e0e6025f004b678dd9 (patch) | |
tree | 2dfc85919ed72e50138545021162b1723bfe66d7 | |
parent | 210aaf11bab9b71decb810a64e15dc358eca8fa0 (diff) | |
download | wireshark-d7fd00de9f35e4f54765e3e0e6025f004b678dd9.tar.gz |
MIPv6: simplify fixed point degrees conversion
* Simplify the conversion of degrees from 24 bit fixed point to a float.
Avoids strict-aliasing warning by gcc 4.4.
* Add reference to RFC 6757.
* Correct spelling of 'convert' in degrees_convert_fixed_to_float().
Change-Id: Icb680d009fdd960e8668fa3020060799d6a74c2f
Reviewed-on: https://code.wireshark.org/review/5913
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r-- | epan/dissectors/packet-mip6.c | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/epan/dissectors/packet-mip6.c b/epan/dissectors/packet-mip6.c index 731913836f..897eb54c39 100644 --- a/epan/dissectors/packet-mip6.c +++ b/epan/dissectors/packet-mip6.c @@ -42,6 +42,7 @@ * RFC 5949, Fast Handovers for Proxy Mobile IPv6 * RFC 6275, Mobility Support in IPv6 (Obsoletes RFC 3775). * RFC 6602, Bulk Binding Update Support for Proxy Mobile IPv6 + * RFC 6757, Access Network Identifier (ANI) Option for Proxy Mobile IPv6 * */ @@ -3105,46 +3106,28 @@ static const value_string mip6_opt_acc_net_id_sub_opt_op_id_type[] = { { 2, "Realm of the operator"}, { 0, NULL} }; -static float degrees_covert_fixed_to_float(guint value) -{ - guint mantissa=0,exponent=0, sign=0, position=0, mask = 1,*ptrNumber = NULL, i ; - float floatNumber =0; - ptrNumber = (guint *) &floatNumber; - if(!value) +static float degrees_convert_fixed_to_float(guint value) +{ + if (!value) return 0; - /* If negative number save sign bit and take 2' complement*/ - if(value & 0x800000) /* Input value is 24 bit number*/ - { - value -= 1; - value ^= -1; - sign = 1; - } + /* + * RFC 6757 section 3.1.2. + * two's complement, fixed point number with 9 whole bits + */ - /* Find position of left most 1*/ - for(i=0;i<24;i++) - { - if(value & mask ) - position = i; - mask = (mask << 1); + /* If high bit of 24 bit number, process as negative number */ + if (value & 0x800000) { + return ((float)(0x1000000 - value)) / -32768.0f; + } else { + return ((float)value) / 32768.0f; } - - mantissa = (value << (32 - position - 8 -1)); - mantissa &= 0x007FFFFF; - - if(sign) - mantissa = (mantissa | 0x80000000); - - exponent = (position - 15 +127) << 23; - - *ptrNumber = (mantissa | exponent);/* club mantissa, exponent and sign*/ - return floatNumber; } static void degrees_base_custom(gchar *str, guint degrees) { - g_snprintf(str, ITEM_LABEL_LENGTH, "%f", degrees_covert_fixed_to_float(degrees) ); + g_snprintf(str, ITEM_LABEL_LENGTH, "%f", degrees_convert_fixed_to_float(degrees) ); } static void |