addr_linux.go 937 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package nl
  2. import (
  3. "syscall"
  4. "unsafe"
  5. )
  6. type IfAddrmsg struct {
  7. syscall.IfAddrmsg
  8. }
  9. func NewIfAddrmsg(family int) *IfAddrmsg {
  10. return &IfAddrmsg{
  11. IfAddrmsg: syscall.IfAddrmsg{
  12. Family: uint8(family),
  13. },
  14. }
  15. }
  16. // struct ifaddrmsg {
  17. // __u8 ifa_family;
  18. // __u8 ifa_prefixlen; /* The prefix length */
  19. // __u8 ifa_flags; /* Flags */
  20. // __u8 ifa_scope; /* Address scope */
  21. // __u32 ifa_index; /* Link index */
  22. // };
  23. // type IfAddrmsg struct {
  24. // Family uint8
  25. // Prefixlen uint8
  26. // Flags uint8
  27. // Scope uint8
  28. // Index uint32
  29. // }
  30. // SizeofIfAddrmsg = 0x8
  31. func DeserializeIfAddrmsg(b []byte) *IfAddrmsg {
  32. return (*IfAddrmsg)(unsafe.Pointer(&b[0:syscall.SizeofIfAddrmsg][0]))
  33. }
  34. func (msg *IfAddrmsg) Serialize() []byte {
  35. return (*(*[syscall.SizeofIfAddrmsg]byte)(unsafe.Pointer(msg)))[:]
  36. }
  37. func (msg *IfAddrmsg) Len() int {
  38. return syscall.SizeofIfAddrmsg
  39. }