mirror of
https://github.com/soypat/lneto.git
synced 2026-08-06 16:03:42 +00:00
f9748da94f
* pcap: reuse Frame memory * slog: reduce heap allocations of addresses; also prevent heap alloc of dhcp options in pcap * dns: heapless improvement; add StackAsync buffer for more heapless operation; start thinking of errors * reuse function for reclaiming frames among all protocols for lower memory usage * remove extraneous code
23 lines
614 B
Go
23 lines
614 B
Go
package internal
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"log/slog"
|
|
)
|
|
|
|
// SlogAddr4 returns a slog.Attr for a 4-byte IPv4 address
|
|
// packed into a uint64 without allocating a string.
|
|
func SlogAddr4(key string, addr *[4]byte) slog.Attr {
|
|
u64Addr := uint64(binary.BigEndian.Uint32(addr[:]))
|
|
return slog.Uint64(key, u64Addr)
|
|
}
|
|
|
|
// SlogAddr6 returns a slog.Attr for a 6-byte hardware (MAC) address
|
|
// packed into a uint64 without allocating a string.
|
|
func SlogAddr6(key string, addr *[6]byte) slog.Attr {
|
|
var buf [8]byte
|
|
copy(buf[2:], addr[:])
|
|
u64Addr := binary.BigEndian.Uint64(buf[:])
|
|
return slog.Uint64(key, u64Addr)
|
|
}
|