Packing and unpacking IP addresses into 32-bit integers

Ben Gertzfield che at
Mon Aug 9 21:52:32 EDT 1999

>>>>> "Mike" == Mike Fletcher <mcfletch at> 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+ --

More information about the Python-list mailing list