mUPnP for C
socket.c File Reference
#include <mupnp/net/interface.h>
#include <mupnp/net/socket.h>
#include <mupnp/util/time.h>
#include <mupnp/util/log.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

Macros

#define mupnp_socket_getrawtype(socket)
 
#define MUPNP_NET_SOCKET_SEND_RETRY_CNT   10
 
#define MUPNP_NET_SOCKET_SEND_RETRY_WAIT_MSEC   20
 

Functions

bool mupnp_socket_tosockaddrin (const char *addr, int port, struct sockaddr_in *sockaddr, bool isBindAddr)
 
bool mupnp_socket_tosockaddrinfo (int sockType, const char *addr, int port, struct addrinfo **addrInfo, bool isBindAddr)
 
void mupnp_socket_startup ()
 
void mupnp_socket_cleanup ()
 
mUpnpSocketmupnp_socket_new (int type)
 
bool mupnp_socket_delete (mUpnpSocket *sock)
 
bool mupnp_socket_isbound (mUpnpSocket *sock)
 
void mupnp_socket_setid (mUpnpSocket *socket, SOCKET value)
 
bool mupnp_socket_close (mUpnpSocket *sock)
 
bool mupnp_socket_listen (mUpnpSocket *sock)
 
bool mupnp_socket_bind (mUpnpSocket *sock, int bindPort, const char *bindAddr, bool bindFlag, bool reuseFlag)
 
bool mupnp_socket_accept (mUpnpSocket *serverSock, mUpnpSocket *clientSock)
 
bool mupnp_socket_connect (mUpnpSocket *sock, const char *addr, int port)
 
ssize_t mupnp_socket_read (mUpnpSocket *sock, char *buffer, size_t bufferLen)
 
size_t mupnp_socket_write (mUpnpSocket *sock, const char *cmd, size_t cmdLen)
 
ssize_t mupnp_socket_readline (mUpnpSocket *sock, char *buffer, size_t bufferLen)
 
size_t mupnp_socket_skip (mUpnpSocket *sock, size_t skipLen)
 
size_t mupnp_socket_sendto (mUpnpSocket *sock, const char *addr, int port, const char *data, size_t dataLen)
 
ssize_t mupnp_socket_recv (mUpnpSocket *sock, mUpnpDatagramPacket *dgmPkt)
 
bool mupnp_socket_setreuseaddress (mUpnpSocket *sock, bool flag)
 
bool mupnp_socket_setmulticastttl (mUpnpSocket *sock, int ttl)
 
bool mupnp_socket_settimeout (mUpnpSocket *sock, int sec)
 
bool mupnp_socket_joingroup (mUpnpSocket *sock, const char *mcastAddr, const char *ifAddr)
 

Variables

static int socketCnt = 0
 

Macro Definition Documentation

◆ MUPNP_NET_SOCKET_SEND_RETRY_CNT

#define MUPNP_NET_SOCKET_SEND_RETRY_CNT   10

◆ MUPNP_NET_SOCKET_SEND_RETRY_WAIT_MSEC

#define MUPNP_NET_SOCKET_SEND_RETRY_WAIT_MSEC   20

◆ mupnp_socket_getrawtype

#define mupnp_socket_getrawtype ( socket)
Value:
(((socket->type & MUPNP_NET_SOCKET_STREAM) == MUPNP_NET_SOCKET_STREAM) ? SOCK_STREAM : SOCK_DGRAM)
#define MUPNP_NET_SOCKET_STREAM
Definition socket.h:32

Function Documentation

◆ mupnp_socket_accept()

bool mupnp_socket_accept ( mUpnpSocket * serverSock,
mUpnpSocket * clientSock )

◆ mupnp_socket_bind()

bool mupnp_socket_bind ( mUpnpSocket * sock,
int bindPort,
const char * bindAddr,
bool bindFlag,
bool reuseFlag )

◆ mupnp_socket_cleanup()

void mupnp_socket_cleanup ( void )

◆ mupnp_socket_close()

bool mupnp_socket_close ( mUpnpSocket * sock)

◆ mupnp_socket_connect()

bool mupnp_socket_connect ( mUpnpSocket * sock,
const char * addr,
int port )

◆ mupnp_socket_delete()

bool mupnp_socket_delete ( mUpnpSocket * sock)

◆ mupnp_socket_isbound()

bool mupnp_socket_isbound ( mUpnpSocket * sock)

◆ mupnp_socket_joingroup()

bool mupnp_socket_joingroup ( mUpnpSocket * sock,
const char * mcastAddr,
const char * ifAddr )

◆ mupnp_socket_listen()

bool mupnp_socket_listen ( mUpnpSocket * sock)

◆ mupnp_socket_new()

mUpnpSocket * mupnp_socket_new ( int type)

◆ mupnp_socket_read()

ssize_t mupnp_socket_read ( mUpnpSocket * sock,
char * buffer,
size_t bufferLen )

◆ mupnp_socket_readline()

ssize_t mupnp_socket_readline ( mUpnpSocket * sock,
char * buffer,
size_t bufferLen )

◆ mupnp_socket_recv()

ssize_t mupnp_socket_recv ( mUpnpSocket * sock,
mUpnpDatagramPacket * dgmPkt )

◆ mupnp_socket_sendto()

size_t mupnp_socket_sendto ( mUpnpSocket * sock,
const char * addr,
int port,
const char * data,
size_t dataLen )

◆ mupnp_socket_setid()

void mupnp_socket_setid ( mUpnpSocket * socket,
SOCKET value )

◆ mupnp_socket_setmulticastttl()

bool mupnp_socket_setmulticastttl ( mUpnpSocket * sock,
int ttl )

◆ mupnp_socket_setreuseaddress()

bool mupnp_socket_setreuseaddress ( mUpnpSocket * sock,
bool flag )

◆ mupnp_socket_settimeout()

bool mupnp_socket_settimeout ( mUpnpSocket * sock,
int sec )

◆ mupnp_socket_skip()

size_t mupnp_socket_skip ( mUpnpSocket * sock,
size_t skipLen )

◆ mupnp_socket_startup()

void mupnp_socket_startup ( void )

◆ mupnp_socket_tosockaddrin()

bool mupnp_socket_tosockaddrin ( const char * addr,
int port,
struct sockaddr_in * sockaddr,
bool isBindAddr )

◆ mupnp_socket_tosockaddrinfo()

bool mupnp_socket_tosockaddrinfo ( int sockType,
const char * addr,
int port,
struct addrinfo ** addrInfo,
bool isBindAddr )

◆ mupnp_socket_write()

size_t mupnp_socket_write ( mUpnpSocket * sock,
const char * cmd,
size_t cmdLen )

Variable Documentation

◆ socketCnt

int socketCnt = 0
static