From 757fecc686730866fb130c3ffa479450f633c0ed Mon Sep 17 00:00:00 2001 From: nessi Date: Fri, 10 Jul 2026 14:24:09 +0200 Subject: [PATCH] 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 --- backend/app/agent_assets/nexafabric-ebpf.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/app/agent_assets/nexafabric-ebpf.go b/backend/app/agent_assets/nexafabric-ebpf.go index f28e519..1c244eb 100644 --- a/backend/app/agent_assets/nexafabric-ebpf.go +++ b/backend/app/agent_assets/nexafabric-ebpf.go @@ -69,8 +69,12 @@ type payload struct { Diagnostics diagnostics `json:"diagnostics"` } -func htons(value uint16) int { - return int((value<<8)&0xff00 | value>>8) +func htons(value uint16) uint16 { + return (value<<8)&0xff00 | value>>8 +} + +func htonsInt(value uint16) int { + return int(htons(value)) } func intPtr(value int) *int { @@ -167,7 +171,7 @@ func openSocket(interfaceName string) (int, error) { if err != nil { 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 { return -1, err }