libwebsockets
Lightweight C library for HTML5 websockets
Network related helper APIs

Macros

#define LWS_ITOSA_USABLE   0
 
#define LWS_ITOSA_NOT_EXIST   -1
 
#define LWS_ITOSA_NOT_USABLE   -2
 
#define LWS_ITOSA_BUSY
 

Functions

LWS_VISIBLE LWS_EXTERN const char *LWS_WARN_UNUSED_RESULT lws_canonical_hostname (struct lws_context *context)
 
LWS_VISIBLE LWS_EXTERN void lws_get_peer_addresses (struct lws *wsi, lws_sockfd_type fd, char *name, int name_len, char *rip, int rip_len)
 
LWS_VISIBLE LWS_EXTERN const char * lws_get_peer_simple (struct lws *wsi, char *name, int namelen)
 
LWS_VISIBLE LWS_EXTERN int lws_interface_to_sa (int ipv6, const char *ifname, struct sockaddr_in *addr, size_t addrlen)
 

Detailed Description

Network related helper APIs

These wrap miscellaneous useful network-related functions

Macro Definition Documentation

◆ LWS_ITOSA_BUSY

#define LWS_ITOSA_BUSY

#include <include/libwebsockets/lws-network-helper.h>

Value:
-3 /* only returned by lws_socket_bind() on
EADDRINUSE */

Function Documentation

◆ lws_canonical_hostname()

LWS_VISIBLE LWS_EXTERN const char* LWS_WARN_UNUSED_RESULT lws_canonical_hostname ( struct lws_context *  context)

#include <include/libwebsockets/lws-network-helper.h>

lws_canonical_hostname() - returns this host's hostname

This is typically used by client code to fill in the host parameter when making a client connection. You can only call it after the context has been created.

Parameters
contextWebsocket context

◆ lws_get_peer_addresses()

LWS_VISIBLE LWS_EXTERN void lws_get_peer_addresses ( struct lws *  wsi,
lws_sockfd_type  fd,
char *  name,
int  name_len,
char *  rip,
int  rip_len 
)

#include <include/libwebsockets/lws-network-helper.h>

lws_get_peer_addresses() - Get client address information

Parameters
wsiLocal struct lws associated with
fdConnection socket descriptor
nameBuffer to take client address name
name_lenLength of client address name buffer
ripBuffer to take client address IP dotted quad
rip_lenLength of client address IP buffer
 This function fills in name and rip with the name and IP of
 the client connected with socket descriptor fd.  Names may be
 truncated if there is not enough room.  If either cannot be
 determined, they will be returned as valid zero-length strings.

◆ lws_get_peer_simple()

LWS_VISIBLE LWS_EXTERN const char* lws_get_peer_simple ( struct lws *  wsi,
char *  name,
int  namelen 
)

#include <include/libwebsockets/lws-network-helper.h>

lws_get_peer_simple() - Get client address information without RDNS

Parameters
wsiLocal struct lws associated with
nameBuffer to take client address name
namelenLength of client address name buffer

This provides a 123.123.123.123 type IP address in name from the peer that has connected to wsi

◆ lws_interface_to_sa()

LWS_VISIBLE LWS_EXTERN int lws_interface_to_sa ( int  ipv6,
const char *  ifname,
struct sockaddr_in *  addr,
size_t  addrlen 
)

#include <include/libwebsockets/lws-network-helper.h>

lws_interface_to_sa() - Convert interface name or IP to sockaddr struct

Parameters
ipv6Allow IPV6 addresses
ifnameInterface name or IP
addrstruct sockaddr_in * to be written
addrlenLength of addr

This converts a textual network interface name to a sockaddr usable by other network functions.

If the network interface doesn't exist, it will return LWS_ITOSA_NOT_EXIST.

If the network interface is not usable, eg ethernet cable is removed, it may logically exist but not have any IP address. As such it will return LWS_ITOSA_NOT_USABLE.

If the network interface exists and is usable, it will return LWS_ITOSA_USABLE.