Packing and unpacking IP addresses into 32-bit integers
che at debian.org
Tue Aug 10 03:52:32 CEST 1999
>>>>> "Mike" == Mike Fletcher <mcfletch at vrtelecom.com> writes:
Mike> Wouldn't it be something like: '>bbbb' or '!bbbb'
Mike> instead (for portability to non-big-endian machines (I'm
Mike> assuming the packed representation is supposed to have
Mike> network byte order))?
Unfortunately Python isn't smart enough to assume that:
struct.pack('!bbbb', a, b, c, d)
struct.pack('!bbbb', d, c, b, a)
but it's easy enough to just change the order of the arguments, which
is what I did, since it's well-defined which order the arguments
will come in (they'll always come in a b c d and go out d c b a).
Brought to you by the letters N and G and the number 7.
"You have my pills!"
Debian GNU/Linux maintainer of Gimp and GTK+ -- http://www.debian.org/
More information about the Python-list