libdill: Structured Concurrency for C


ipaddr_local - resolve a name of a local network interface


int ipaddr_local(struct ipaddr *addr, const char *name, int port, int mode);


Converts an IP address in human-readable format, or a name of a local network interface, into an ipaddr object:

ipaddr_local(&addr, "", 80, 0);
ipaddr_local(&addr, "::1", 443, 0);
ipaddr_local(&addr, "eth0", 25, 0);

addr is thr address strucure to hold the result. name is the string to convert. port is the port number to use. mode specifies which kind of addresses should be returned. Possible values are:

Setting the argument to zero invokes default behaviour, which, at the present, is IPADDR_PREF_IPV4. However, in the future when IPv6 becomes more common it may be switched to IPADDR_PREF_IPV6.

If address parameter is set to NULL, INADDR_ANY or in6addr_any, respectively, is returned. This value is useful when binding to all local network interfaces.


The function returns 0 on success. On error, it returns -1 and sets errno to one of the values below.



struct ipaddr addr;
int rc = ipaddr_local(&addr, "eth0", 5555, 0);