Skip to content

Commit

Permalink
Fix JS indentation, add missing byteswap functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dswarbrick committed May 7, 2017
1 parent 020a71b commit f33b515
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
25 changes: 19 additions & 6 deletions bitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) |
Expand Down
30 changes: 15 additions & 15 deletions webui/js/fabricmon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f33b515

Please sign in to comment.