[Bro-Dev] #908: Need for function bytestring_to_double

Bro Tracker bro at tracker.bro-ids.org
Thu Oct 25 08:55:52 PDT 2012

#908: Need for function bytestring_to_double
  Reporter:  carsten          |      Owner:
      Type:  Feature Request  |     Status:  needs information
  Priority:  Normal           |  Milestone:  Bro2.2
 Component:  Bro              |    Version:  git/master
Resolution:                   |   Keywords:

Comment (by jsiwek):

 > - there is a check that the length of bytestring equals the length of
 the internal representation of double in "if ( s->Len() != sizeof(d))".

 Maybe it also needs a check that `sizeof(uint64) == sizeof(double)` since
 the bytes are copied to `uint64` storage first.

 > - the bit-pattern is first translated from network to host order before
 it is interpreted as double, to avoid invalid bitpatterns as may occur in

 I don't get that entirely, I would have thought doing a `memcpy` in to
 `double` storage and then using `ntohd` would work, but maybe not.

 > - the bitpattern interpretation for a double is defined in IEEE 754,
 http://en.wikipedia.org/wiki/Double-precision_floating-point_format and I
 just *expect* every compiler on every platform to adhere to this spec.

 Yeah, I think in practice if you need to do byteswapping on floating point
 data types, treating it like an integer of same width might be ok.  More
 on that: http://en.wikipedia.org/wiki/Endianness#Floating-

 {{{Because there have been many floating point formats with no "network"
 standard representation for them, there is no formal standard for
 transferring floating point values between heterogeneous systems.
 Theoretically, this means that even standard IEEE floating point data
 written by one machine might not be readable by another. However, on
 modern standard computers (i.e., implementing IEEE 754), one may in
 practice safely assume that the endianness is the same for floating point
 numbers as for integers, making the conversion straightforward regardless
 of data type.}}}

 Otherwise, I still wonder about the second bullet above and whether some
 type casts can be avoided.  And maybe the name should be
 `network_bytestring_to_host_double` to be clear there may be a byteswap
 operation in it.  Or just make separate BIFs for byte swapping bytestrings
 of various lengths and also separate bytestring to other data type
 conversion BIFs.

Ticket URL: <http://tracker.bro-ids.org/bro/ticket/908#comment:7>
Bro Tracker <http://tracker.bro-ids.org/bro>
Bro Issue Tracker

More information about the bro-dev mailing list