Overview
The netctl library provides functions to:- Initialize and manage network connections
- Query network configuration and status
- Get network interface information (IP address, DNS, etc.)
- Monitor network state changes
Initialization
netCtlInit
Returns 0 on success, error code on failure.
netCtlTerm
Network State
netCtlGetState
Pointer to receive the network state:
NET_CTL_STATE_Disconnected(0) - Not connectedNET_CTL_STATE_Connecting(1) - Connection in progressNET_CTL_STATE_IPObtaining(2) - Obtaining IP addressNET_CTL_STATE_IPObtained(3) - IP address obtained, ready for use
Returns 0 on success, error code on failure.
Network Information
netCtlGetInfo
Information code to retrieve:
NET_CTL_INFO_DEVICE(1) - Device type (wired/wireless)NET_CTL_INFO_ETHER_ADDR(2) - MAC addressNET_CTL_INFO_MTU(3) - Maximum transmission unitNET_CTL_INFO_LINK(4) - Link statusNET_CTL_INFO_LINK_TYPE(5) - Link type (10/100/1000 Mbps)NET_CTL_INFO_BSSID(6) - Wireless BSSIDNET_CTL_INFO_SSID(7) - Wireless SSIDNET_CTL_INFO_WLAN_SECURITY(8) - Wireless security typeNET_CTL_INFO_IP_ADDRESS(16) - IP address stringNET_CTL_INFO_NETMASK(17) - Netmask stringNET_CTL_INFO_DEFAULT_ROUTE(18) - Default gatewayNET_CTL_INFO_PRIMARY_DNS(19) - Primary DNS serverNET_CTL_INFO_SECONDARY_DNS(20) - Secondary DNS serverNET_CTL_INFO_HTTP_PROXY_CONFIG(21) - HTTP proxy configNET_CTL_INFO_HTTP_PROXY_SERVER(22) - HTTP proxy serverNET_CTL_INFO_HTTP_PROXY_PORT(23) - HTTP proxy port
Pointer to union to receive the information. The union contains fields corresponding to each info code.
Returns 0 on success, error code on failure.
NAT Information
netCtlGetNatInfo
Pointer to NAT info structure to be filled:
size- Size of structureupnp_status- UPnP statusstun_status- STUN statusnat_type- NAT type (1, 2, or 3)mapped_addr- Mapped external address
Returns 0 on success, error code on failure.
Data Structures
net_ctl_info
Union containing various network information types:Network device type:
NET_CTL_DEVICE_WIRED(0) - Wired EthernetNET_CTL_DEVICE_WIRELESS(1) - Wireless LAN
Ethernet MAC address (6 bytes).
Maximum Transmission Unit size.
Link status:
NET_CTL_LINK_DISCONNECTED(0) - Cable disconnectedNET_CTL_LINK_CONNECTED(1) - Cable connected
Link speed and duplex:
NET_CTL_LINK_TYPE_AUTO(0) - Auto-negotiateNET_CTL_LINK_TYPE_10BASE_HALF(1) - 10Mbps half-duplexNET_CTL_LINK_TYPE_10BASE_FULL(2) - 10Mbps full-duplexNET_CTL_LINK_TYPE_100BASE_HALF(3) - 100Mbps half-duplexNET_CTL_LINK_TYPE_100BASE_FULL(4) - 100Mbps full-duplexNET_CTL_LINK_TYPE_1000BASE_HALF(5) - 1000Mbps half-duplexNET_CTL_LINK_TYPE_1000BASE_FULL(6) - 1000Mbps full-duplex
Wireless access point BSSID.
Wireless network SSID (up to 32 bytes).
Wireless security type:
NET_CTL_WLAN_SECURITY_NOAUTH(0) - No authenticationNET_CTL_WLAN_SECURITY_WEP(1) - WEPNET_CTL_WLAN_SECURITY_WPAPSK_TKIP(2) - WPA-PSK (TKIP)NET_CTL_WLAN_SECURITY_WPAPSK_AES(3) - WPA-PSK (AES)NET_CTL_WLAN_SECURITY_WPA2PSK_TKIP(5) - WPA2-PSK (TKIP)NET_CTL_WLAN_SECURITY_WPA2PSK_AES(6) - WPA2-PSK (AES)NET_CTL_WLAN_SECURITY_WPAPSK_WPA2PSK(7) - Mixed mode
IP configuration method:
NET_CTL_IP_DHCP(0) - DHCPNET_CTL_IP_STATIC(1) - Static IPNET_CTL_IP_PPPOE(2) - PPPoE
IP address as string (e.g., “192.168.1.100”).
Network mask as string (e.g., “255.255.255.0”).
Default gateway as string.
Primary DNS server as string.
Secondary DNS server as string.
HTTP proxy configuration:
NET_CTL_HTTP_PROXY_OFF(0) - Proxy disabledNET_CTL_HTTP_PROXY_ON(1) - Proxy enabled
HTTP proxy server hostname.
HTTP proxy server port.
net_ctl_nat_info
NAT information structure:Size of structure (set before calling).
UPnP status:
NET_CTL_NATINFO_UPNP_UNCHECKED(0)NET_CTL_NATINFO_UPNP_NO(1)NET_CTL_NATINFO_UPNP_USED(2)
STUN status:
NET_CTL_NATINFO_STUN_UNCHECKED(0)NET_CTL_NATINFO_STUN_FAILED(1)NET_CTL_NATINFO_STUN_OK(2)
NAT type:
NET_CTL_NATINFO_NAT_TYPE_1(1) - Type 1 (Open)NET_CTL_NATINFO_NAT_TYPE_2(2) - Type 2 (Moderate)NET_CTL_NATINFO_NAT_TYPE_3(3) - Type 3 (Strict)
External mapped IP address.
Error Codes
Common error codes returned by netctl functions:NET_CTL_ERROR_NOT_INITIALIZED(0x80130101) - Library not initializedNET_CTL_ERROR_NOT_TERMINATED(0x80130102) - Not terminatedNET_CTL_ERROR_INVALID_ID(0x80130105) - Invalid IDNET_CTL_ERROR_INVALID_CODE(0x80130106) - Invalid info codeNET_CTL_ERROR_NOT_CONNECTED(0x80130108) - Not connected to networkNET_CTL_ERROR_NOT_AVAIL(0x80130109) - Information not availableNET_CTL_ERROR_NET_DISABLED(0x80130181) - Network disabledNET_CTL_ERROR_NET_NOT_CONNECTED(0x80130182) - No IP addressNET_CTL_ERROR_NET_CABLE_NOT_CONNECTED(0x80130186) - Cable not connected