refactor: fix htons return type to uint16 and add htonsInt wrapper for syscall.Socket compatibility
Split htons to return uint16 instead of int for correct byte order conversion, add htonsInt wrapper that converts uint16 to int for syscall.Socket protocol parameter, update openSocket to use htonsInt for ethPAll protocol value
This commit is contained in:
@@ -69,8 +69,12 @@ type payload struct {
|
|||||||
Diagnostics diagnostics `json:"diagnostics"`
|
Diagnostics diagnostics `json:"diagnostics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func htons(value uint16) int {
|
func htons(value uint16) uint16 {
|
||||||
return int((value<<8)&0xff00 | value>>8)
|
return (value<<8)&0xff00 | value>>8
|
||||||
|
}
|
||||||
|
|
||||||
|
func htonsInt(value uint16) int {
|
||||||
|
return int(htons(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
func intPtr(value int) *int {
|
func intPtr(value int) *int {
|
||||||
@@ -167,7 +171,7 @@ func openSocket(interfaceName string) (int, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
fd, err := syscall.Socket(syscall.AF_PACKET, syscall.SOCK_RAW, htons(ethPAll))
|
fd, err := syscall.Socket(syscall.AF_PACKET, syscall.SOCK_RAW, htonsInt(ethPAll))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user