Documentation
¶
Overview ¶
Package w32iphelper provides functions for interacting with the IP Helper win32 APIs.
Index ¶
- Constants
- func ListLocalInterfaces(flags GAAFlags) ([]*windows.IpAdapterAddresses, error)
- func NetworkAdapterProperties(naflags GAAFlags, name string) (*windows.IpAdapterAddresses, error)
- func NetworkAdapterPropertiesByMac(naflags GAAFlags, macAddress string) (*windows.IpAdapterAddresses, error)
- func SetForwardRoute(guid *windows.GUID, settings *MIBIPFORWARDROW2) error
- func SetInterfaceDNSSettings(guid *windows.GUID, settings *DNSInterfaceSettings) error
- func SetInterfaceIPAddress(guid *windows.GUID, settings *MIBUNICASTIPADDRESSROW) error
- type DNSFlags
- type DNSInterfaceSettings
- type GAAFlags
- type IPAddressPrefix
- type MIBIPFORWARDROW2
- type MIBUNICASTIPADDRESSROW
- type RouteProtocol
- type SockaddrInet
Constants ¶
const ( // GAAFlagSkipUnicast is a flag to skip unicast adapters. GAAFlagSkipUnicast = 0x01 // GAAFlagSkipAnycast is a flag to skip anycast adapters. GAAFlagSkipAnycast = 0x02 // GAAFlagSkipMulticast is a flag to skip multicast adapters. GAAFlagSkipMulticast = 0x04 // GAAFlagSkipDNSServer is a flag to skip DNS server adapters. GAAFlagSkipDNSServer = 0x08 // GAAFlagIncludePrefix is a flag to include prefix information. GAAFlagIncludePrefix = 0x10 // GAAFlagSkipFriendlyName is a flag to skip friendly name information. GAAFlagSkipFriendlyName = 0x20 // GAAFlagIncludeWinsInfo is a flag to include Windows information. GAAFlagIncludeWinsInfo = 0x40 // GAAFlagIncludeGateways is a flag to include gateway information. GAAFlagIncludeGateways = 0x80 // GAAFlagIncludeAllInterfaces is a flag to include all interfaces. GAAFlagIncludeAllInterfaces = 0x100 // GAAFlagIncludeAllCompartments is a flag to include all compartments. GAAFlagIncludeAllCompartments = 0x200 // GAAFlagIncludeTunnelBindingOrder is a flag to include tunnel binding order. GAAFlagIncludeTunnelBindingOrder = 0x400 )
https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getadaptersaddresses
const ( // DNSInterfaceSettingsVersion1 is the version 1 of the DnsInterfaceSettings structure. DNSInterfaceSettingsVersion1 = 1 // for DnsInterfaceSettings // DNSInterfaceSettingsVersion2 is the version 2 of the DnsInterfaceSettings structure. DNSInterfaceSettingsVersion2 = 2 // for DnsInterfaceSettings // DNSInterfaceSettingsVersion3 is the version 3 of the DnsInterfaceSettings structure. DNSInterfaceSettingsVersion3 = 3 // for DnsInterfaceSettings // DNSInterfaceSettingsFlagIPv6 is the flag for IPv6 DNS. DNSInterfaceSettingsFlagIPv6 = 0x0001 // DNSInterfaceSettingsFlagNameserver is the flag for nameserver. DNSInterfaceSettingsFlagNameserver = 0x0002 // DNSInterfaceSettingsFlagSearchList is the flag for search list. DNSInterfaceSettingsFlagSearchList = 0x0004 // DNSInterfaceSettingsFlagRegistrationEnabled is the flag for registration enabled. DNSInterfaceSettingsFlagRegistrationEnabled = 0x0008 // DNSInterfaceSettingsFlagRegisterAdapterName is the flag for register adapter name. DNSInterfaceSettingsFlagRegisterAdapterName = 0x0010 // DNSInterfaceSettingsFlagDomain is the flag for domain. DNSInterfaceSettingsFlagDomain = 0x0020 // DNSInterfaceSettingsFlagHostname is the flag for hostname. DNSInterfaceSettingsFlagHostname = 0x0040 // DNSInterfaceSettingsFlagEnableLLMNR is the flag for enable LLMNR. DNSInterfaceSettingsFlagEnableLLMNR = 0x0080 // DNSInterfaceSettingsFlagQueryAdapterName is the flag for query adapter name. DNSInterfaceSettingsFlagQueryAdapterName = 0x0100 // DNSInterfaceSettingsFlagProfileNameserver is the flag for profile nameserver. DNSInterfaceSettingsFlagProfileNameserver = 0x0200 // DNSInterfaceSettingsFlagDisableUnconstrainedQueries is the flag for disabling unconstrained queries. DNSInterfaceSettingsFlagDisableUnconstrainedQueries = 0x0400 // v2 only // DNSInterfaceSettingsFlagSupplementalSearchList is the flag for supplemental search list. DNSInterfaceSettingsFlagSupplementalSearchList = 0x0800 // v2 only // DNSInterfaceSettingsFlagDOH is the flag for DNS over HTTP. DNSInterfaceSettingsFlagDOH = 0x1000 // v3 only // DNSInterfaceSettingsFlagDOHProfile is the flag for DNS over HTTP profile. DNSInterfaceSettingsFlagDOHProfile = 0x2000 // v3 only )
https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-setinterfacednssettings
Variables ¶
This section is empty.
Functions ¶
func ListLocalInterfaces ¶
func ListLocalInterfaces(flags GAAFlags) ([]*windows.IpAdapterAddresses, error)
ListLocalInterfaces lists local NIC's that match the given flags.
func NetworkAdapterProperties ¶
func NetworkAdapterProperties(naflags GAAFlags, name string) (*windows.IpAdapterAddresses, error)
NetworkAdapterProperties returns the network adapter with the given name.
func NetworkAdapterPropertiesByMac ¶
func NetworkAdapterPropertiesByMac(naflags GAAFlags, macAddress string) (*windows.IpAdapterAddresses, error)
NetworkAdapterPropertiesByMac returns the network adapter with the given mac address.
func SetForwardRoute ¶
func SetForwardRoute(guid *windows.GUID, settings *MIBIPFORWARDROW2) error
SetForwardRoute sets the IP forward entry for the given interface. https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-setipforwardentry2
func SetInterfaceDNSSettings ¶
func SetInterfaceDNSSettings(guid *windows.GUID, settings *DNSInterfaceSettings) error
SetInterfaceDNSSettings sets the DNS settings for the given interface. https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-setinterfacednssettings
func SetInterfaceIPAddress ¶
func SetInterfaceIPAddress(guid *windows.GUID, settings *MIBUNICASTIPADDRESSROW) error
SetInterfaceIPAddress sets the IP address for the given interface. https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-createunicastipaddressentry
Types ¶
type DNSFlags ¶
type DNSFlags uint32
DNSFlags enumeration defines flags used in SetInterfaceDnsSettings calls https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-setinterfacednssettings
type DNSInterfaceSettings ¶
type DNSInterfaceSettings struct {
Version uint32
Flags DNSFlags
Domain *uint16
NameServer *uint16
SearchList *uint16
RegistrationEnabled uint32
RegisterAdapterName uint32
EnableLLMNR uint32
QueryAdapterName uint32
ProfileNameServer *uint16
}
DNSInterfaceSettings is meant to be used with SetInterfaceDnsSettings https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getinterfacednssettings
type GAAFlags ¶
type GAAFlags uint32
GAAFlags enumeration defines flags used in GetAdaptersAddresses calls https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getadaptersaddresses
type IPAddressPrefix ¶
type IPAddressPrefix struct {
Prefix SockaddrInet
PrefixLength uint8
}
IPAddressPrefix represents an IP address prefix and its length. https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-ip_address_prefix
type MIBIPFORWARDROW2 ¶
type MIBIPFORWARDROW2 struct {
InterfaceLuid uint64
InterfaceIndex uint32
DestinationPrefix IPAddressPrefix
NextHop SockaddrInet
SitePrefixLength uint8
ValidLifetime uint32
PreferredLifetime uint32
Metric uint32
Protocol RouteProtocol
Loopback uint8
AutoconfigureAddress uint8
Publish uint8
Immortal uint8
Origin uint32
}
MIBIPFORWARDROW2 stores information about an IP route entry. https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_ipforward_row2
type MIBUNICASTIPADDRESSROW ¶
type MIBUNICASTIPADDRESSROW struct {
// Address is the IP address of the interface.
Address SockaddrInet
// InterfaceLuid is the unique identifier of the interface.
InterfaceLuid uint64
// InterfaceIndex is the index of the interface.
InterfaceIndex uint32
// PrefixOrigin is the origin of the prefix.
PrefixOrigin uint8 // NL_PREFIX_ORIGIN
// SuffixOrigin is the origin of the suffix.
SuffixOrigin uint8 // NL_SUFFIX_ORIGIN
// ValidLifetime is the lifetime of the prefix.
ValidLifetime uint32
// PreferredLifetime is the lifetime of the prefix.
PreferredLifetime uint32
// OnLinkPrefixLength is the length of the prefix.
OnLinkPrefixLength uint8
// SkipAsSource is the flag to skip the address as a source.
SkipAsSource uint8
// DadState is the DAD state of the prefix.
DadState uint8 // NL_DAD_STATE
// ScopeID is the scope of the prefix.
ScopeID uint32
// CreateTimestamp is the timestamp of the prefix creation.
CreateTimestamp int64
}
MIBUNICASTIPADDRESSROW is the Go equivalent of the Windows structure. https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_unicastipaddress_row
type RouteProtocol ¶
type RouteProtocol uint32
RouteProtocol is the protocol of the route entry. https://learn.microsoft.com/en-us/windows/win32/api/nldef/ne-nldef-nl_route_protocol
const ( // MibIPProtoOther means that the routing mechanism was not specified. MibIPProtoOther RouteProtocol = 1 // MibIPProtoLocal is a local interface. MibIPProtoLocal RouteProtocol = 2 // MibIPProtoNetMgmt is a static route. MibIPProtoNetMgmt RouteProtocol = 3 // DHCP, static, default gateway etc. // MibIPProtoICMP is an ICMP protocol. MibIPProtoICMP RouteProtocol = 4 // MibIPProtoEGP is an EGP protocol. MibIPProtoEGP RouteProtocol = 5 // MibIPProtoGGP is a GGP protocol. MibIPProtoGGP RouteProtocol = 6 // MibIPProtoHELLO is a Hello protocol. MibIPProtoHELLO RouteProtocol = 7 // MibIPProtoRIP is a RIP protocol. MibIPProtoRIP RouteProtocol = 8 // MibIPProtoISIS is an IS-IS protocol. MibIPProtoISIS RouteProtocol = 9 // MibIPProtoESIS is an ES-IS protocol. MibIPProtoESIS RouteProtocol = 10 // MibIPProtoCisco is a Cisco protocol. MibIPProtoCisco RouteProtocol = 11 // MibIPProtoBBN is a BBN protocol. MibIPProtoBBN RouteProtocol = 12 // MibIPProtoOSPF is an OSPF protocol. MibIPProtoOSPF RouteProtocol = 13 // MibIPProtoBGP is a BGP protocol. MibIPProtoBGP RouteProtocol = 14 // MibIPProtoNTAutoStatic is a NT protocol. MibIPProtoNTAutoStatic RouteProtocol = 10002 // MibIPProtoNTStatic is an NT protocol. MibIPProtoNTStatic RouteProtocol = 10006 // MibIPProtoNTStaticNonDOD is an NT protocol. MibIPProtoNTStaticNonDOD RouteProtocol = 10007 )
type SockaddrInet ¶
SockaddrInet can hold either an IPv4 or IPv6 socket address. https://learn.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-sockaddr_inet
func IPToSockaddrInet ¶
func IPToSockaddrInet(ip net.IP) (SockaddrInet, error)
IPToSockaddrInet is a Helper function to convert a net.IP to a SockaddrInet structure.