当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.ParseRoutingSockaddr函数代码示例

本文整理汇总了Golang中syscall.ParseRoutingSockaddr函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseRoutingSockaddr函数的具体用法?Golang ParseRoutingSockaddr怎么用?Golang ParseRoutingSockaddr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ParseRoutingSockaddr函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: parseRoutingSockaddrs

func parseRoutingSockaddrs(m syscall.RoutingMessage) ([]syscall.Sockaddr, error) {
	switch m := m.(type) {
	case *syscall.RouteMessage:
		sas, err := syscall.ParseRoutingSockaddr(m)
		if err != nil {
			return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
		}
		if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
			return nil, err
		}
		return sas, nil
	case *syscall.InterfaceMessage:
		sas, err := syscall.ParseRoutingSockaddr(m)
		if err != nil {
			return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
		}
		if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
			return nil, err
		}
		return sas, nil
	case *syscall.InterfaceAddrMessage:
		sas, err := syscall.ParseRoutingSockaddr(m)
		if err != nil {
			return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
		}
		if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
			return nil, err
		}
		return sas, nil
	default:
		panic(fmt.Sprintf("unknown routing message type: %T", m))
	}
}
开发者ID:tomwans,项目名称:gorump,代码行数:33,代码来源:route_noifma_test.go

示例2: newMulticastAddr

func newMulticastAddr(m *syscall.InterfaceMulticastAddrMessage) ([]Addr, os.Error) {
	var ifmat []Addr

	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.SockaddrInet4:
			ifma := &IPAddr{IP: IPv4(v.Addr[0], v.Addr[1], v.Addr[2], v.Addr[3])}
			ifmat = append(ifmat, ifma.toAddr())
		case *syscall.SockaddrInet6:
			ifma := &IPAddr{IP: make(IP, IPv6len)}
			copy(ifma.IP, v.Addr[:])
			// NOTE: KAME based IPv6 protcol stack usually embeds
			// the interface index in the interface-local or link-
			// local address as the kernel-internal form.
			if ifma.IP.IsInterfaceLocalMulticast() ||
				ifma.IP.IsLinkLocalMulticast() {
				// remove embedded scope zone ID
				ifma.IP[2], ifma.IP[3] = 0, 0
			}
			ifmat = append(ifmat, ifma.toAddr())
		}
	}

	return ifmat, nil
}
开发者ID:WXB506,项目名称:golang,代码行数:30,代码来源:interface_darwin.go

示例3: newMulticastAddr

func newMulticastAddr(ifi *Interface, m *syscall.InterfaceMulticastAddrMessage) ([]Addr, error) {
	sas, err := syscall.ParseRoutingSockaddr(m)
	if err != nil {
		return nil, os.NewSyscallError("route sockaddr", err)
	}
	var ifmat []Addr
	for _, sa := range sas {
		switch sa := sa.(type) {
		case *syscall.SockaddrInet4:
			ifma := &IPAddr{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])}
			ifmat = append(ifmat, ifma.toAddr())
		case *syscall.SockaddrInet6:
			ifma := &IPAddr{IP: make(IP, IPv6len)}
			copy(ifma.IP, sa.Addr[:])
			// NOTE: KAME based IPv6 protcol stack usually embeds
			// the interface index in the interface-local or link-
			// local address as the kernel-internal form.
			if ifma.IP.IsInterfaceLocalMulticast() || ifma.IP.IsLinkLocalMulticast() {
				ifma.IP[2], ifma.IP[3] = 0, 0
			}
			ifmat = append(ifmat, ifma.toAddr())
		}
	}
	return ifmat, nil
}
开发者ID:hfeeki,项目名称:golang,代码行数:25,代码来源:interface_darwin.go

示例4: 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
}
开发者ID:ChrisYangLiu,项目名称:fakewechat,代码行数:27,代码来源:interface_bsd.go

示例5: newAddr

func newAddr(ifi *Interface, m *syscall.InterfaceAddrMessage) (*IPNet, error) {
	sas, err := syscall.ParseRoutingSockaddr(m)
	if err != nil {
		return nil, os.NewSyscallError("parseroutingsockaddr", err)
	}
	ifa := &IPNet{}
	switch sa := sas[syscall.RTAX_NETMASK].(type) {
	case *syscall.SockaddrInet4:
		ifa.Mask = IPv4Mask(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])
	case *syscall.SockaddrInet6:
		ifa.Mask = make(IPMask, IPv6len)
		copy(ifa.Mask, sa.Addr[:])
	}
	switch sa := sas[syscall.RTAX_IFA].(type) {
	case *syscall.SockaddrInet4:
		ifa.IP = IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])
	case *syscall.SockaddrInet6:
		ifa.IP = make(IP, IPv6len)
		copy(ifa.IP, sa.Addr[:])
		// NOTE: KAME based IPv6 protcol stack usually embeds
		// the interface index in the interface-local or
		// link-local address as the kernel-internal form.
		if ifa.IP.IsLinkLocalUnicast() {
			ifa.IP[2], ifa.IP[3] = 0, 0
		}
	}
	if ifa.IP == nil || ifa.Mask == nil {
		return nil, nil // Sockaddrs contain syscall.SockaddrDatalink on NetBSD
	}
	return ifa, nil
}
开发者ID:tomwans,项目名称:gorump,代码行数:31,代码来源:interface_bsd.go

示例6: TestParseInterfaceMessage

func TestParseInterfaceMessage(t *testing.T) {
	for i, tt := range parseInterfaceMessageTests {
		if _, err := syscall.ParseRoutingSockaddr(tt); err != nil {
			t.Errorf("#%d: %v", i, err)
		}
	}
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:7,代码来源:route_bsd_test.go

示例7: 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
}
开发者ID:ssrl,项目名称:go,代码行数:32,代码来源:interface_bsd.go

示例8: newMulticastAddr

func newMulticastAddr(ifi *Interface, m *syscall.InterfaceMulticastAddrMessage) (*IPAddr, error) {
	sas, err := syscall.ParseRoutingSockaddr(m)
	if err != nil {
		return nil, os.NewSyscallError("route sockaddr", err)
	}
	switch sa := sas[syscall.RTAX_IFA].(type) {
	case *syscall.SockaddrInet4:
		return &IPAddr{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])}, nil
	case *syscall.SockaddrInet6:
		ifma := IPAddr{IP: make(IP, IPv6len)}
		copy(ifma.IP, sa.Addr[:])
		// NOTE: KAME based IPv6 protcol stack usually embeds
		// the interface index in the interface-local or
		// link-local address as the kernel-internal form.
		if ifma.IP.IsInterfaceLocalMulticast() || ifma.IP.IsLinkLocalMulticast() {
			ifma.IP[2], ifma.IP[3] = 0, 0
		}
		return &ifma, nil
	default:
		return nil, nil
	}
}
开发者ID:klueska,项目名称:go-akaros,代码行数:22,代码来源:interface_darwin.go

示例9: newAddr

func newAddr(m *syscall.InterfaceAddrMessage) (Addr, error) {
	ifa := &IPNet{}

	sas, err := syscall.ParseRoutingSockaddr(m)
	if err != nil {
		return nil, os.NewSyscallError("route sockaddr", err)
	}

	for i, s := range sas {
		switch v := s.(type) {
		case *syscall.SockaddrInet4:
			switch i {
			case 0:
				ifa.Mask = IPv4Mask(v.Addr[0], v.Addr[1], v.Addr[2], v.Addr[3])
			case 1:
				ifa.IP = IPv4(v.Addr[0], v.Addr[1], v.Addr[2], v.Addr[3])
			}
		case *syscall.SockaddrInet6:
			switch i {
			case 0:
				ifa.Mask = make(IPMask, IPv6len)
				copy(ifa.Mask, v.Addr[:])
			case 1:
				ifa.IP = make(IP, IPv6len)
				copy(ifa.IP, v.Addr[:])
				// NOTE: KAME based IPv6 protcol stack usually embeds
				// the interface index in the interface-local or link-
				// local address as the kernel-internal form.
				if ifa.IP.IsLinkLocalUnicast() {
					// remove embedded scope zone ID
					ifa.IP[2], ifa.IP[3] = 0, 0
				}
			}
		}
	}

	return ifa, nil
}
开发者ID:krasin,项目名称:go-deflate,代码行数:38,代码来源:interface_bsd.go

示例10: newAddr

func newAddr(m *syscall.InterfaceAddrMessage) (Addr, error) {
	sas, err := syscall.ParseRoutingSockaddr(m)
	if err != nil {
		return nil, os.NewSyscallError("route sockaddr", err)
	}
	ifa := &IPNet{}
	for i, sa := range sas {
		switch sa := sa.(type) {
		case *syscall.SockaddrInet4:
			switch i {
			case 0:
				ifa.Mask = IPv4Mask(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])
			case 1:
				ifa.IP = IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])
			}
		case *syscall.SockaddrInet6:
			switch i {
			case 0:
				ifa.Mask = make(IPMask, IPv6len)
				copy(ifa.Mask, sa.Addr[:])
			case 1:
				ifa.IP = make(IP, IPv6len)
				copy(ifa.IP, sa.Addr[:])
				// NOTE: KAME based IPv6 protcol stack usually embeds
				// the interface index in the interface-local or link-
				// local address as the kernel-internal form.
				if ifa.IP.IsLinkLocalUnicast() {
					ifa.Zone = zoneToString(int(ifa.IP[2]<<8 | ifa.IP[3]))
					ifa.IP[2], ifa.IP[3] = 0, 0
				}
			}
		default: // Sockaddrs contain syscall.SockaddrDatalink on NetBSD
			return nil, nil
		}
	}
	return ifa, nil
}
开发者ID:serge-hulne,项目名称:golang,代码行数:37,代码来源:interface_bsd.go


注:本文中的syscall.ParseRoutingSockaddr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。