libctru  v1.6.0
Data Structures | Macros | Enumerations | Functions
soc.h File Reference

SOC service for sockets communications. More...

#include <netinet/in.h>
#include <sys/socket.h>

Go to the source code of this file.

Data Structures

struct  SOCU_ARPTableEntry
 One entry of the ARP table retrieved by using SOCU_GetNetworkOpt and NETOPT_ARP_TABLE. More...
 
struct  SOCU_IPInfo
 Structure returned by SOCU_GetNetworkOpt when using NETOPT_IP_INFO. More...
 
struct  SOCU_RoutingTableEntry
 One entry of the routing table retrieved by using SOCU_GetNetworkOpt and NETOPT_ROUTING_TABLE. More...
 
struct  SOCU_UDPTableEntry
 One entry of the UDP sockets table retrieved by using SOCU_GetNetworkOpt and NETOPT_UDP_TABLE. More...
 
struct  SOCU_TCPTableEntry
 One entry of the TCP sockets table retrieved by using SOCU_GetNetworkOpt and NETOPT_TCP_TABLE. More...
 
struct  SOCU_DNSTableEntry
 One entry of the DNS servers table retrieved by using SOCU_GetNetworkOpt and NETOPT_DNS_TABLE. More...
 

Macros

#define SOL_CONFIG   0xfffe
 The config level to be used with SOCU_GetNetworkOpt.
 
#define ROUTING_FLAG_G   0x01
 The route uses a gateway.
 
TCP states
#define TCP_STATE_CLOSED   1
 
#define TCP_STATE_LISTEN   2
 
#define TCP_STATE_ESTABLISHED   5
 
#define TCP_STATE_FINWAIT1   6
 
#define TCP_STATE_FINWAIT2   7
 
#define TCP_STATE_CLOSE_WAIT   8
 
#define TCP_STATE_LAST_ACK   9
 
#define TCP_STATE_TIME_WAIT   11
 

Enumerations

enum  NetworkOpt {
  NETOPT_MAC_ADDRESS = 0x1004,
  NETOPT_ARP_TABLE = 0x3002,
  NETOPT_IP_INFO = 0x4003,
  NETOPT_IP_MTU = 0x4004,
  NETOPT_ROUTING_TABLE = 0x4006,
  NETOPT_UDP_NUMBER = 0x8002,
  NETOPT_UDP_TABLE = 0x8003,
  NETOPT_TCP_NUMBER = 0x9002,
  NETOPT_TCP_TABLE = 0x9003,
  NETOPT_DNS_TABLE = 0xB003,
  NETOPT_DHCP_LEASE_TIME = 0xC001
}
 Options to be used with SOCU_GetNetworkOpt. More...
 

Functions

Result socInit (u32 *context_addr, u32 context_size)
 Initializes the SOC service. More...
 
Result socExit (void)
 Closes the soc service. More...
 
long gethostid (void)
 Gets the system's host ID. More...
 
int gethostname (char *name, size_t namelen)
 
int SOCU_ShutdownSockets (void)
 
int SOCU_CloseSockets (void)
 
int SOCU_GetNetworkOpt (int level, NetworkOpt optname, void *optval, socklen_t *optlen)
 Retrieves information from the network configuration. More...
 
int SOCU_GetIPInfo (struct in_addr *ip, struct in_addr *netmask, struct in_addr *broadcast)
 Gets the system's IP address, netmask, and subnet broadcast. More...
 
int SOCU_AddGlobalSocket (int sockfd)
 Adds a global socket. More...
 

Detailed Description

SOC service for sockets communications.

After initializing this service you will be able to use system calls from netdb.h, sys/socket.h etc.

Enumeration Type Documentation

◆ NetworkOpt

enum NetworkOpt

Options to be used with SOCU_GetNetworkOpt.

Enumerator
NETOPT_MAC_ADDRESS 

The mac address of the interface (u32 mac[6])

NETOPT_ARP_TABLE 

The ARP table.

See also
SOCU_ARPTableEntry
NETOPT_IP_INFO 

The cureent IP setup.

See also
SOCU_IPInfo
NETOPT_IP_MTU 

The value of the IP MTU (u32)

NETOPT_ROUTING_TABLE 

The routing table.

See also
SOCU_RoutingTableEntry
NETOPT_UDP_NUMBER 

The number of sockets in the UDP table (u32)

NETOPT_UDP_TABLE 

The table of opened UDP sockets.

See also
SOCU_UDPTableEntry
NETOPT_TCP_NUMBER 

The number of sockets in the TCP table (u32)

NETOPT_TCP_TABLE 

The table of opened TCP sockets.

See also
SOCU_TCPTableEntry
NETOPT_DNS_TABLE 

The table of the DNS servers.

See also
SOCU_DNSTableEntry – Returns a buffer of size 336 but only 2 entries are set ?
NETOPT_DHCP_LEASE_TIME 

The DHCP lease time remaining, in seconds.

Function Documentation

◆ gethostid()

long gethostid ( void  )

Gets the system's host ID.

Returns
The system's host ID.
Examples
network/sockets/source/sockets.c.

◆ socExit()

Result socExit ( void  )

Closes the soc service.

Note
You need to call this in order to be able to use the buffer again.
Examples
network/sockets/source/sockets.c, and network/sslc/source/ssl.c.

◆ socInit()

Result socInit ( u32 context_addr,
u32  context_size 
)

Initializes the SOC service.

Parameters
context_addrAddress of a page-aligned (0x1000) buffer to be used.
context_sizeSize of the buffer, a multiple of 0x1000.
Note
The specified context buffer can no longer be accessed by the process which called this function, since the userland permissions for this block are set to no-access.
Examples
network/sockets/source/sockets.c, and network/sslc/source/ssl.c.

◆ SOCU_AddGlobalSocket()

int SOCU_AddGlobalSocket ( int  sockfd)

Adds a global socket.

Parameters
sockfdThe socket fd.
Returns
error

◆ SOCU_GetIPInfo()

int SOCU_GetIPInfo ( struct in_addr ip,
struct in_addr netmask,
struct in_addr broadcast 
)

Gets the system's IP address, netmask, and subnet broadcast.

Returns
error

◆ SOCU_GetNetworkOpt()

int SOCU_GetNetworkOpt ( int  level,
NetworkOpt  optname,
void *  optval,
socklen_t *  optlen 
)

Retrieves information from the network configuration.

Similar to getsockopt().

Parameters
levelOnly value allowed seems to be SOL_CONFIG
optnameThe option to be retrieved
optvalWill contain the output of the command
optlenSize of the optval buffer, will be updated to hold the size of the output
Returns
0 if successful. -1 if failed, and errno will be set accordingly. Can also return a system error code.