本文整理汇总了Golang中syscall.InterfaceMessage类的典型用法代码示例。如果您正苦于以下问题:Golang InterfaceMessage类的具体用法?Golang InterfaceMessage怎么用?Golang InterfaceMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InterfaceMessage类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newLink
func newLink(m *syscall.InterfaceMessage) (*Interface, error) {
sas, err := syscall.ParseRoutingSockaddr(m)
if err != nil {
return nil, os.NewSyscallError("route sockaddr", err)
}
ifi := &Interface{Index: int(m.Header.Index), Flags: linkFlags(m.Header.Flags)}
for _, sa := range sas {
switch sa := sa.(type) {
case *syscall.SockaddrDatalink:
// NOTE: SockaddrDatalink.Data is minimum work area,
// can be larger.
m.Data = m.Data[unsafe.Offsetof(sa.Data):]
var name [syscall.IFNAMSIZ]byte
for i := 0; i < int(sa.Nlen); i++ {
name[i] = byte(m.Data[i])
}
ifi.Name = string(name[:sa.Nlen])
ifi.MTU = int(m.Header.Data.Mtu)
addr := make([]byte, sa.Alen)
for i := 0; i < int(sa.Alen); i++ {
addr[i] = byte(m.Data[int(sa.Nlen)+i])
}
ifi.HardwareAddr = addr[:sa.Alen]
}
}
return ifi, nil
}
示例2: newLink
func newLink(m *syscall.InterfaceMessage) ([]Interface, os.Error) {
var ift []Interface
sas, e := syscall.ParseRoutingSockaddr(m)
if e != 0 {
return nil, os.NewSyscallError("route sockaddr", e)
}
for _, s := range sas {
switch v := s.(type) {
case *syscall.SockaddrDatalink:
// NOTE: SockaddrDatalink.Data is minimum work area,
// can be larger.
m.Data = m.Data[unsafe.Offsetof(v.Data):]
ifi := Interface{Index: int(m.Header.Index), Flags: linkFlags(m.Header.Flags)}
var name [syscall.IFNAMSIZ]byte
for i := 0; i < int(v.Nlen); i++ {
name[i] = byte(m.Data[i])
}
ifi.Name = string(name[:v.Nlen])
ifi.MTU = int(m.Header.Data.Mtu)
addr := make([]byte, v.Alen)
for i := 0; i < int(v.Alen); i++ {
addr[i] = byte(m.Data[int(v.Nlen)+i])
}
ifi.HardwareAddr = addr[:v.Alen]
ift = append(ift, ifi)
}
}
return ift, nil
}