converting IPv4 string to uint32 (and back again)

Nate Finch nate.finch at canonical.com
Thu Dec 4 19:50:04 UTC 2014


http://play.golang.org/p/H1DI2Bw1OY

Michael was working on translating an ipv4 strings to uint32 (he said int,
but I hope he meant uint32).  He was hand coding it, but I figured there
was a better way using the built-in libraries.  Turns out it's not too
bad.  The code is in the link above.  I thought it was interesting, so I'm
cc'ing juju-dev.

The only thing I wasn't sure about was BigEndian vs. LittleEndian.  IMO,
0.0.0.5 -> 5 makes the most sense, so I went with BigEndian.  I suppose it
doesn't matter as long as the conversions are kept consistent in both
directions.

-Nate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju-dev/attachments/20141204/22d7ee82/attachment.html>


More information about the Juju-dev mailing list