DTS Application Library
0.2.3
Application library containing referenced objects and interfaces to common libraries
|
Allocate and initialise a socket for use as a client or server. More...
Modules | |
SSL socket support | |
TLSv1 SSLv2 SSLv3 DTLSv1 support. | |
Unix domain sockets | |
Support for unixdomain sockets using sockets interface. | |
Multicast sockets | |
Support for multicast sockets either IPv4 or IPv6. | |
Files | |
file | socket.c |
Allocate and initialise a socket for use as a client or server. | |
file | sslutil.c |
TLSv1 SSLv2 SSLv3 DTLSv1 support. | |
Data Structures | |
union | sockstruct |
Socket union describing all address types. More... | |
struct | fwsocket |
Socket data structure. More... | |
struct | socket_handler |
Socket handling thread data. More... | |
Typedefs | |
typedef void(* | socketrecv )(struct fwsocket *, void *) |
Callback function to register with a socket that will be called when there is data available. More... | |
Enumerations | |
enum | sock_flags { SOCK_FLAG_BIND = 1 << 0, SOCK_FLAG_CLOSE = 1 << 1, SOCK_FLAG_SSL = 1 << 2, SOCK_FLAG_UNIX = 1 << 3, SOCK_FLAG_MCAST = 1 << 4 } |
Socket flags controling a socket. More... | |
Functions | |
void | close_socket (struct fwsocket *sock) |
Mark the socket for closure and release the reference. More... | |
struct fwsocket * | make_socket (int family, int type, int proto, void *ssl) |
Allocate a socket structure and return reference. More... | |
struct fwsocket * | accept_socket (struct fwsocket *sock) |
Create and return a socket structure from accept() More... | |
struct fwsocket * | sockconnect (int family, int stype, int proto, const char *ipaddr, const char *port, void *ssl) |
Generic client socket. More... | |
struct fwsocket * | udpconnect (const char *ipaddr, const char *port, void *ssl) |
UDP Socket client. More... | |
struct fwsocket * | tcpconnect (const char *ipaddr, const char *port, void *ssl) |
TCP Socket client. More... | |
struct fwsocket * | sockbind (int family, int stype, int proto, const char *ipaddr, const char *port, void *ssl, int backlog) |
Generic server socket. More... | |
struct fwsocket * | udpbind (const char *ipaddr, const char *port, void *ssl) |
UDP server socket. More... | |
struct fwsocket * | tcpbind (const char *ipaddr, const char *port, void *ssl, int backlog) |
Generic server socket. More... | |
void | socketserver (struct fwsocket *sock, socketrecv read, socketrecv acceptfunc, threadcleanup cleanup, void *data) |
Create a server thread with a socket that has been created with sockbind udpbind or tcpbind. More... | |
void | socketclient (struct fwsocket *sock, void *data, socketrecv read, threadcleanup cleanup) |
Create a server thread with a socket that has been created with sockbind udpbind or tcpbind. More... | |
const char * | sockaddr2ip (union sockstruct *addr, char *buff, int blen) |
Return the ip address of a sockstruct addr. More... | |
int | socketread_d (struct fwsocket *sock, void *buf, int num, union sockstruct *addr) |
Read from a socket into a buffer. More... | |
int | socketread (struct fwsocket *sock, void *buf, int num) |
Read from a socket into a buffer. More... | |
int | socketwrite_d (struct fwsocket *sock, const void *buf, int num, union sockstruct *addr) |
Write a buffer to a socket. More... | |
int | socketwrite (struct fwsocket *sock, const void *buf, int num) |
Write a buffer to a socket. More... | |
Allocate and initialise a socket for use as a client or server.
typedef void(* socketrecv)(struct fwsocket *, void *) |
enum sock_flags |
Socket flags controling a socket.
Definition at line 102 of file dtsapp.h.
Create and return a socket structure from accept()
sock | Reference to the socket its accepted on. |
Definition at line 144 of file socket.c.
References fwsocket::addr, objalloc(), objlock(), objunlock(), objunref(), fwsocket::proto, sockstruct::sa, fwsocket::sock, fwsocket::ssl, tlsaccept(), and fwsocket::type.
void close_socket | ( | struct fwsocket * | sock | ) |
Mark the socket for closure and release the reference.
sock | Socket to close. |
Definition at line 79 of file socket.c.
References objunref(), setflag, and SOCK_FLAG_CLOSE.
Referenced by socktest(), and unixsocktest().
struct fwsocket* make_socket | ( | int | family, |
int | type, | ||
int | proto, | ||
void * | ssl | ||
) |
Allocate a socket structure and return reference.
The socket FD is assined by a call to socket.
family | Protocol family. |
type | Socket type. |
proto | Protocol to be used. |
ssl | SSL structure to associate with the socket. |
Definition at line 120 of file socket.c.
References objalloc(), objunref(), fwsocket::proto, fwsocket::sock, fwsocket::ssl, and fwsocket::type.
Referenced by dtls_listenssl(), mcast_socket(), unixsocket_client(), and unixsocket_server().
const char* sockaddr2ip | ( | union sockstruct * | addr, |
char * | buff, | ||
int | blen | ||
) |
Return the ip address of a sockstruct addr.
addr | Socketstruct to return the address for. |
buff | Buffer the IP will be copied too. |
blen | Buffer length. |
Definition at line 504 of file socket.c.
References inet_ntop(), sockstruct::sa4, sockstruct::sa6, and sockstruct::ss.
struct fwsocket* sockbind | ( | int | family, |
int | stype, | ||
int | proto, | ||
const char * | ipaddr, | ||
const char * | port, | ||
void * | ssl, | ||
int | backlog | ||
) |
Generic server socket.
family | Protocol family. |
stype | Socket type. |
proto | Socket protocol. |
ipaddr | Ipaddr to connect too. |
port | Port to connect too. |
ssl | SSL structure to associate with socket. |
backlog | Connection backlog passed to listen. |
Definition at line 290 of file socket.c.
struct fwsocket* sockconnect | ( | int | family, |
int | stype, | ||
int | proto, | ||
const char * | ipaddr, | ||
const char * | port, | ||
void * | ssl | ||
) |
Generic client socket.
family | Protocol family. |
stype | Socket type. |
proto | Socket protocol. |
ipaddr | Ipaddr to connect too. |
port | Port to connect too. |
ssl | SSL structure to associate with socket. |
Definition at line 250 of file socket.c.
void socketclient | ( | struct fwsocket * | sock, |
void * | data, | ||
socketrecv | read, | ||
threadcleanup | cleanup | ||
) |
Create a server thread with a socket that has been created with sockbind udpbind or tcpbind.
sock | Reference to a bound socket. |
data | to send to the callbacks in paramaters. |
read | Callback to handle data when ready to read. |
cleanup | Thread cleanup function for when the socket closes. |
Definition at line 493 of file socket.c.
References startsslclient().
Referenced by socktest().
int socketread | ( | struct fwsocket * | sock, |
void * | buf, | ||
int | num | ||
) |
Read from a socket into a buffer.
There are 2 functions each for reading and writing data to a socket.
sock | Socket structure to read from. |
buf | Buffer to fill. |
num | Size of the buffer. |
Definition at line 489 of file sslutil.c.
References socketread_d().
Referenced by client_func().
int socketread_d | ( | struct fwsocket * | sock, |
void * | buf, | ||
int | num, | ||
union sockstruct * | addr | ||
) |
Read from a socket into a buffer.
There are 2 functions each for reading and writing data to a socket.
sock | Socket structure to read from. |
buf | Buffer to fill. |
num | Size of the buffer. |
addr | Addr structure to fill remote address in. |
Definition at line 406 of file sslutil.c.
References fwsocket::flags, objlock(), objunlock(), objunref(), sockstruct::sa, fwsocket::sock, SOCK_FLAG_CLOSE, SOCK_FLAG_SSL, ssldata::ssl, fwsocket::ssl, testflag, and fwsocket::type.
Referenced by server_func(), and socketread().
void socketserver | ( | struct fwsocket * | sock, |
socketrecv | read, | ||
socketrecv | acceptfunc, | ||
threadcleanup | cleanup, | ||
void * | data | ||
) |
Create a server thread with a socket that has been created with sockbind udpbind or tcpbind.
sock | Reference to a bound socket. |
read | Callback to handle data when ready to read. |
acceptfunc | Function to call on connection accept. |
cleanup | Thread cleanup function for when the socket closes. |
data | to send to the callbacks in paramaters. |
Definition at line 463 of file socket.c.
References fwsocket::children, create_bucketlist(), dtsl_serveropts(), fwsocket::flags, objlock(), objunlock(), fwsocket::ssl, and fwsocket::type.
Referenced by socktest().
int socketwrite | ( | struct fwsocket * | sock, |
const void * | buf, | ||
int | num | ||
) |
Write a buffer to a socket.
There are 2 functions each for reading and writing data to a socket.
sock | Socket structure to send data too. |
buf | Buffer to send. |
num | Lengthe of the buffer. |
Definition at line 629 of file sslutil.c.
References socketwrite_d().
Referenced by client_func(), and socktest().
int socketwrite_d | ( | struct fwsocket * | sock, |
const void * | buf, | ||
int | num, | ||
union sockstruct * | addr | ||
) |
Write a buffer to a socket.
There are 2 functions each for reading and writing data to a socket.
sock | Socket structure to send data too. |
buf | Buffer to send. |
num | Lengthe of the buffer. |
addr | Addr structure to send the buffer too (SOCK_DGRAM) see notes. |
Definition at line 508 of file sslutil.c.
References fwsocket::addr, fwsocket::flags, objlock(), objunlock(), objunref(), sockstruct::sa, setflag, fwsocket::sock, SOCK_FLAG_CLOSE, SOCK_FLAG_MCAST, SOCK_FLAG_SSL, SOCK_FLAG_UNIX, sockstruct::ss, ssldata::ssl, fwsocket::ssl, testflag, fwsocket::type, and sockstruct::un.
Referenced by server_func(), socketwrite(), and unixsocktest().
struct fwsocket* tcpbind | ( | const char * | ipaddr, |
const char * | port, | ||
void * | ssl, | ||
int | backlog | ||
) |
Generic server socket.
ipaddr | Ipaddr to connect too. |
port | Port to connect too. |
ssl | SSL structure to associate with socket. |
backlog | Connection backlog passed to listen. |
Definition at line 315 of file socket.c.
Referenced by socktest().
struct fwsocket* tcpconnect | ( | const char * | ipaddr, |
const char * | port, | ||
void * | ssl | ||
) |
TCP Socket client.
ipaddr | Ipaddr to connect too. |
port | Port to connect too. |
ssl | SSL structure to associate with socket. |
Definition at line 274 of file socket.c.
Referenced by socktest().
struct fwsocket* udpbind | ( | const char * | ipaddr, |
const char * | port, | ||
void * | ssl | ||
) |
UDP server socket.
ipaddr | Ipaddr to connect too. |
port | Port to connect too. |
ssl | SSL structure to associate with socket. |
Definition at line 302 of file socket.c.
Referenced by socktest().
struct fwsocket* udpconnect | ( | const char * | ipaddr, |
const char * | port, | ||
void * | ssl | ||
) |
UDP Socket client.
ipaddr | Ipaddr to connect too. |
port | Port to connect too. |
ssl | SSL structure to associate with socket. |
Definition at line 262 of file socket.c.
Referenced by socktest().