diff --git a/bitops.go b/bitops.go index 9892cd8..ee79640 100644 --- a/bitops.go +++ b/bitops.go @@ -53,18 +53,26 @@ func log2b(x uint) uint { return bitLen(x) - 1 } -// ntohll converts a uint64 from network byte order to host byte order -func ntohll(x uint64) uint64 { +// ntohs converts a uint16 from network byte order to host byte order +func ntohs(x uint16) uint16 { if nativeEndian == binary.LittleEndian { - return swapUint64(x) + return swapUint16(x) } return x } -// ntohs converts a uint16 from network byte order to host byte order -func ntohs(x uint16) uint16 { +// ntohll converts a uint32 from network byte order to host byte order +func ntohl(x uint32) uint32 { if nativeEndian == binary.LittleEndian { - return swapUint16(x) + return swapUint32(x) + } + return x +} + +// ntohll converts a uint64 from network byte order to host byte order +func ntohll(x uint64) uint64 { + if nativeEndian == binary.LittleEndian { + return swapUint64(x) } return x } @@ -73,6 +81,11 @@ func swapUint16(n uint16) uint16 { return (n&0x00ff)<<8 | (n&0xff00)>>8 } +func swapUint32(n uint32) uint32 { + return (n&0x000000ff)<<24 | (n&0x0000ff00)<<8 | + (n&0x00ff0000)>>8 | (n&0xff000000)>>24 +} + func swapUint64(n uint64) uint64 { return ((n & 0x00000000000000ff) << 56) | ((n & 0x000000000000ff00) << 40) | diff --git a/webui/js/fabricmon.js b/webui/js/fabricmon.js index e26ea54..618a799 100644 --- a/webui/js/fabricmon.js +++ b/webui/js/fabricmon.js @@ -52,22 +52,22 @@ d3.json(fabric + ".json", function(error, graph) { .on("end", dragended)); node.append("image") - .attr("xlink:href", function(d) { - if (d.nodetype == 2) { - return "img/switch.svg"; - } else if (d.nodetype == 3) { - return "img/router.svg"; - } else { - for (var i = 0; i < nodeImageMap.length; i++) { - if (nodeImageMap[i][0].test(d.desc)) - return nodeImageMap[i][1]; - } + .attr("xlink:href", function(d) { + if (d.nodetype == 2) { + return "img/switch.svg"; + } else if (d.nodetype == 3) { + return "img/router.svg"; + } else { + for (var i = 0; i < nodeImageMap.length; i++) { + if (nodeImageMap[i][0].test(d.desc)) + return nodeImageMap[i][1]; } - }) - .attr("x", -8) - .attr("y", -8) - .attr("width", 16) - .attr("height", 16); + } + }) + .attr("x", -8) + .attr("y", -8) + .attr("width", 16) + .attr("height", 16); node.append("text") .attr("dx", 12)