#ifndef DK4SOCK_H_INCLUDED /** Protection against multiple inclusions. */ #define DK4SOCK_H_INCLUDED 1 /** @file dk4sock.h Socket functions. The functions in this module are for both networking and local UNIX domain sockets. Use dk4socket_up() before using any other function shown here, use dk4socket_down() to release the socket subsystem when you are done. These functions simply indicate success on POSIX systems but are required for subsystem initialization and release on Windows. Exception: dk4socket_htons(), dk4socket_ntohs(), dk4socket_htonl() and dk4socket_ntohl() and some other bit/byte handling functions can be used without calling dk4socket_up() before. Errors from the systems native socket functions are stored in errno on POSIX systems. On Windows you can use WSAGetLastError() to find an error code. The dk4socket_error_reset(), dk4socket_error_get() and dk4socket_error_report() functions are used to hide this difference. */ #include "dk4conf.h" #if DK4_ON_WINDOWS #if DK4_HAVE_WINSOCK2_H #ifndef WINSOCK2_H_INCLUDED #include #define WINSOCK2_H_INCLUDED 1 #endif #endif #if DK4_HAVE_WS2TCPIP_H #ifndef WS2TCPIP_H_INCLUDED #include #define WS2TCPIP_H_INCLUDED #endif #endif #ifndef WINDOWS_H_INCLUDED #include #define WINDOWS_H_INCLUDED 1 #endif #endif /* if DK4_ON_WINDOWS*/ #if DK4_HAVE_SYS_TYPES_H #ifndef SYS_TYPES_H_INCLUDED #include #define SYS_TYPES_H_INCLUDED 1 #endif #endif #if DK4_HAVE_SYS_SOCKET_H #ifndef SYS_SOCKET_H_INCLUDED #include #define SYS_SOCKET_H_INCLUDED 1 #endif #endif #if DK4_HAVE_SYS_UN_H #ifndef SYS_UN_H_INCLUDED #include #define SYS_UN_H_INCLUDED 1 #endif #endif #if DK4_HAVE_ARPA_INET_H #ifndef ARPA_INET_H_INCLUDED #include #define ARPA_INET_H_INCLUDED 1 #endif #endif #if DK4_HAVE_NETINET_IN_H #ifndef NETINET_IN_H_INCLUDED #include #define NETINET_IN_H_INCLUDED 1 #endif #endif #if DK4_HAVE_NETINET_IN6_H #ifndef NETINET_IN6_H_INCLUDED #include #define NETINET_IN6_H_INCLUDED 1 #endif #endif #if DK4_HAVE_NETDB_H #ifndef NETDB_H_INCLUDED #include #define NETDB_H_INCLUDED 1 #endif #endif #if DK4_ON_WINDOWS /** Data type for sockets. */ typedef SOCKET dk4_socket_t; #else /** Data type for sockets. */ typedef int dk4_socket_t; #endif #ifndef DK4TYPES_H_INCLUDED #include "dk4types.h" #endif #ifndef DK4ERROR_H_INCLUDED #include "dk4error.h" #endif /** Set of sockets, for listening or for receiving datagrams. */ typedef struct { dk4_socket_t *pSockets; /**< Array of sockets. */ size_t szMax; /**< Array size allocated, no of sockets. */ size_t szUsed; /**< Number of used sockets in array. */ } dk4_socket_set_t; #if !DK4_HAVE_IN_ADDR /** IPv4 internet address. */ typedef struct in_addr IN_ADDR; #endif #if DK4_HAVE_STRUCT_SOCKADDR_IN6 #if !DK4_HAVE_IN6_ADDR /** IPv6 internet address. */ typedef struct in6_addr IN6_ADDR; #endif #endif /** Allowed IPv4 peer address or address range. */ typedef struct { IN_ADDR ad; /**< Address or address base. */ IN_ADDR ma; /**< Net mask. */ } dk4_allowed_peer_ipv4_t; #if DK4_HAVE_STRUCT_SOCKADDR_IN6 /** Allowed IPv6 peer address or address range. */ typedef struct { IN6_ADDR ad; /**< Address or address base. */ IN6_ADDR ma; /**< Net mask. */ } dk4_allowed_peer_ipv6_t; #endif /** Allowed IPv6 or IPv4 peer address or range. */ typedef struct { int af; /**< Addr family AF_INET or AF_INET6. */ union { dk4_allowed_peer_ipv4_t ipv4; /**< IPv4 peer data. */ #if DK4_HAVE_STRUCT_SOCKADDR_IN6 dk4_allowed_peer_ipv6_t ipv6; /**< IPv6 peer data. */ #endif } data; /**< Peer data. */ } dk4_allowed_peer_t; #if DK4_HAVE_SOCKADDR_STORAGE /** Buffer large enough to hold all sockaddr_xxx structures. */ typedef struct sockaddr_storage dk4_sockaddr_storage_t; #else /** Buffer large enough to hold all sockaddr_xxx structures. */ typedef union { struct sockaddr sa; /**< Default sockaddr. */ struct sockaddr_in i4; /**< IPv4 address. */ #if DK4_HAVE_STRUCT_SOCKADDR_IN6 struct sockaddr_in6 i6; /**< IPv6 address. */ #endif #if DK4_HAVE_STRUCT_SOCKADDR_UN struct sockaddr_un su; /**< UNIX domain socket address. */ #endif } dk4_sockaddr_storage_t; #endif /** Operation result values. */ enum { /** The operation failed. */ DK4_SOCKET_RESULT_FAILED = -1, /** The operation is still in progress, not yet finished. */ DK4_SOCKET_RESULT_IN_PROGRESS = 0, /** The operation succeeded. */ DK4_SOCKET_RESULT_SUCCESS = 1 }; #if DK4_ON_WINDOWS /** How to shut down a socket. */ enum { /** Shut down read (receive) operations. */ DK4_SOCKET_SHUT_READ = SD_RECEIVE , /** Shut down write (send) operations. */ DK4_SOCKET_SHUT_WRITE = SD_SEND , /** Shut down both. */ DK4_SOCKET_SHUT_RDWR = SD_BOTH }; #else /** How to shut down a socket. */ enum { /** Shut down read (receive) operations. */ DK4_SOCKET_SHUT_READ = SHUT_RD , /** Shut down write (send) operations. */ DK4_SOCKET_SHUT_WRITE = SHUT_WR , /** Shut down both. */ DK4_SOCKET_SHUT_RDWR = SHUT_RDWR }; #endif #ifndef INVALID_SOCKET /** Special socket values. */ enum { /** Invalid socket. */ INVALID_SOCKET = -1 }; #endif #ifdef __cplusplus extern "C" { #endif /* Error reporting. ---------------- Module: dk4sock01 */ /** Reset error code variable (either errno or WSAGetLastError()). */ void dk4socket_error_reset(void); /** Get error code (either from errno or via WSAGetLastError()). @return Error code. */ int dk4socket_error_get(void); /** Note error in error report, use error details from either errno or WSAGetLastError(). @param erp Error report to fill. @param ec Error code DK4_E_xxx. */ void dk4socket_error_report(dk4_er_t *erp, int ec); /** Write IP address to debug output file. For internal use only. @param text Text to show before address. @param addr Start of address buffer. @param sz Size of address. */ void dk4socket_debug_address(const char *text, struct sockaddr *addr, size_t sz); #if (DK4_HAVE_SETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_ERROR) /** Check integer result from getsockopt() for non-null value. On some systems the getsockopt() function writes an int value for boolean flags, a simple byte is used on other systems. After calling getsockopt() you can use this function to check boolean values for true or false. @param optval The value stored in an int variable by getsockopt(). @param slo The length stored in the size variable. @return 1 for non-null value, 0 for 0 value. */ int dk4socket_non_null_getsockopt(int optval, socklen_t slo); #endif /* Long and short conversion between network and host representation. ------------------------------------------------------------------ Module: dk4sock02 */ /** Convert short from host to network representation. Does not require dk4socket_up() to be called before. @param u Value to convert. @return Conversion result. */ uint16_t dk4socket_htons(uint16_t u); /** Convert short from network to host representation. Does not require dk4socket_up() to be called before. @param u Value to convert. @return Conversion result. */ uint16_t dk4socket_ntohs(uint16_t u); /** Convert long from host to network representation. Does not require dk4socket_up() to be called before. @param u Value to convert. @return Conversion result. */ uint32_t dk4socket_htonl(uint32_t u); /** Convert long from network to host representation. Does not require dk4socket_up() to be called before. @param u Value to convert. @return Conversion result. */ uint32_t dk4socket_ntohl(uint32_t u); /** Change byte order for arbitrary data types, if the Does not require dk4socket_up() to be called before. systems byte order is not big-endian. Does not require dk4socket_up() to be called before. @param buf Address of variable. @param sz Size of variable. */ void dk4socket_swap_bytes_if_not_bigendian(void *buf, size_t sz); /** Create a netmask in host representation for a given bit number. Does not require dk4socket_up() to be called before. @param dptr Address of destination variable. @param sz Number of bits to set. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if inp is NULL, - DK4_E_SYNTAX
if the number of bits is out of range. */ int dk4socket_mask_bits(unsigned long *dptr, size_t sz, dk4_er_t *erp); /** Set all bytes to 0x01. Does not require dk4socket_up() to be called before. @param ptr Pointer to variable. @param nbytes Number of bytes in variable. */ void dk4socket_set_one_bytes(void *ptr, size_t nbytes); #if DK4_HAVE_STRUCT_SOCKADDR_IN6 /** Create IPv6 netmask in network representation. @param inp Address of destination variable. @param sz Number of bits to set (1 to 128). @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if inp is NULL, - DK4_E_SYNTAX
if the number of bits is out of range. */ int dk4socket_mask6_bits(struct in6_addr *inp, size_t sz, dk4_er_t *erp); #endif #if DK4_HAVE_STRUCT_SOCKADDR_UN /** Find socket address length for local UNIX domain socket. For UNIX sockets the address size is not the size of struct sockaddr_un, only the used part of the file name buffer is counted. @param sock Pointer to socket address structure. @return Number of bytes used by address. */ size_t dk4socket_unix_length(const struct sockaddr_un *sock); #endif /** Get protocol family for address family. @param af Address family. @return Protocol family on success, PF_UNSPEC on error. */ int dk4socket_pf_for_af(int af); /** Check address length, correct if necessary. This function allows to pass a dk4_sockaddr_storage_t address and sizeof(dk4_sockaddr_storage_t), the dk4socket_bind(), dk4socket_connect() and dk4socket_sendto() use the correct size for the address family stored. @param soa Socket address. @param plgt Address of length variable. @return 1 on success, 0 on error. */ int dk4socket_correct_addr_lgt(const struct sockaddr *soa, size_t *plgt); /* Convert addresses to text and vice versa. ----------------------------------------- Module: dk4sock03 */ /** Convert address to text representation (char). @param dptr Destination buffer address. @param dsz Destination buffer size. @param afam Address family (AF_INET or AF_INET6). @param src Pointer to struct in_addr or struct in6_addr. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Restriction: If the inet_ntop() function is not available (i.e. on Windows with DK4_WINDOWS_LEGACY enabled) IPv6 adddresses containing zero sequences are not abbreviated using ``::''. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or src is NULL, dsz is 0 or afam is an invalid family, - DK4_E_BUFFER_TOO_SMALL
if the output buffer is too small, - DK4_E_MATH_OVERFLOW
if a mathematical overflow occured in size calculations, - DK4_E_SOCKET_INET_NTOP
if the inet_ntop() function failed (details in iDetails1). */ int dk4socket_c8_inet_ntop( char *dptr, size_t dsz, int afam, const void *src, dk4_er_t *erp ); /** Convert IP address including port number to char text. @param dptr Destination buffer address. @param dsz Destination buffer size. @param afam Address family. @param saptr Address buffer. @param sasz Address size. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Restriction: If neither the getnameinfo() nor the inet_ntop() function is available (i.e. on Windows with DK4_WINDOWS_LEGACY enabled) IPv6 adddresses containing zero sequences are not abbreviated using ``::''. Error codes: - DK4_E_INVALID_ARGUMENTS - DK4_SOCKET_GETADDRINFO - DK4_E_BUFFER_TOO_SMALL */ int dk4socket_c8_addr_port_to_text( char *dptr, size_t dsz, int afam, const struct sockaddr *saptr, size_t sasz, dk4_er_t *erp ); /** Convert generic socket address structure to char text. @param dptr Destination buffer address. @param dsz Destination buffer size. @param saptr Pointer to socket address structure. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Restriction: If neither the getnameinfo() nor the inet_ntop() function is available (i.e. on Windows with DK4_WINDOWS_LEGACY enabled) IPv6 adddresses containing zero sequences are not abbreviated using ``::''. Error codes: - DK4_E_INVALID_ARGUMENTS - DK4_E_SOCKET_GETADDRINFO - DK4_E_SYNTAX - DK4_E_BUFFER_TOO_SMALL */ int dk4socket_c8_sockaddr_to_text( char *dptr, size_t dsz, const dk4_sockaddr_storage_t *saptr, dk4_er_t *erp ); /* Convert addresses to text and vice versa. ----------------------------------------- Module: dk4sock04 */ /** Convert address to text representation (wchar_t). @param dptr Destination buffer address. @param dsz Destination buffer size (number of wchar_t). @param afam Address family (AF_INET or AF_INET6). @param src Pointer to struct in_addr or struct in6_addr. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Restriction: If the inet_ntop() function is not available (i.e. on Windows with DK4_WINDOWS_LEGACY enabled) IPv6 adddresses containing zero sequences are not abbreviated using ``::''. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or src is NULL, dsz is 0 or afam is an invalid family, - DK4_E_BUFFER_TOO_SMALL
if the output buffer is too small, - DK4_E_MATH_OVERFLOW
if a mathematical overflow occured in size calculations, - DK4_E_SOCKET_INET_NTOP
if the inet_ntop() function failed (details in iDetails1), - DK4_E_NOT_SUPPORTED
if there is not wchar_t support. */ int dk4socket_wc_inet_ntop( wchar_t *dptr, size_t dsz, int afam, const void *src, dk4_er_t *erp ); /** Convert IP address including port number to wchar_t text. @param dptr Destination buffer address. @param dsz Destination buffer size (number of wchar_t). @param afam Address family. @param saptr Address buffer. @param sasz Address size. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Restriction: If neither the getnameinfo() nor the inet_ntop() function is available (i.e. on Windows with DK4_WINDOWS_LEGACY enabled) IPv6 adddresses containing zero sequences are not abbreviated using ``::''. Error codes: - DK4_E_INVALID_ARGUMENTS - DK4_SOCKET_GETADDRINFO - DK4_E_BUFFER_TOO_SMALL - DK4_E_NOT_SUPPORTED */ int dk4socket_wc_addr_port_to_text( wchar_t *dptr, size_t dsz, int afam, const struct sockaddr *saptr, size_t sasz, dk4_er_t *erp ); /** Convert generic socket address structure to wchar_t text. @param dptr Destination buffer address. @param dsz Destination buffer size (Number of wchar_t). @param saptr Pointer to socket address structure. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Restriction: If neither the getnameinfo() nor the inet_ntop() function is available (i.e. on Windows with DK4_WINDOWS_LEGACY enabled) IPv6 adddresses containing zero sequences are not abbreviated using ``::''. Error codes: - DK4_E_INVALID_ARGUMENTS - DK4_E_SOCKET_GETADDRINFO - DK4_E_SYNTAX - DK4_E_BUFFER_TOO_SMALL */ int dk4socket_wc_sockaddr_to_text( wchar_t *dptr, size_t dsz, const dk4_sockaddr_storage_t *saptr, dk4_er_t *erp ); /* Convert addresses to text and vice versa. ----------------------------------------- Module: dk4sock05 */ /** Convert address to text representation (dkChar). @param dptr Destination buffer address. @param dsz Destination buffer size (number of dkChar). @param afam Address family (AF_INET or AF_INET6). @param src Pointer to struct in_addr or struct in6_addr. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Restriction: If the inet_ntop() function is not available (i.e. on Windows with DK4_WINDOWS_LEGACY enabled) IPv6 adddresses containing zero sequences are not abbreviated using ``::''. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or src is NULL, dsz is 0 or afam is an invalid family, - DK4_E_BUFFER_TOO_SMALL
if the output buffer is too small, - DK4_E_MATH_OVERFLOW
if a mathematical overflow occured in size calculations, - DK4_E_SOCKET_INET_NTOP
if the inet_ntop() function failed (details in iDetails1). */ int dk4socket_inet_ntop( dkChar *dptr, size_t dsz, int afam, const void *src, dk4_er_t *erp ); /** Convert IP address including port number to dkChar text. @param dptr Destination buffer address. @param dsz Destination buffer size (number of dkChar). @param afam Address family. @param saptr Address buffer. @param sasz Address size. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Restriction: If neither the getnameinfo() nor the inet_ntop() function is available (i.e. on Windows with DK4_WINDOWS_LEGACY enabled) IPv6 adddresses containing zero sequences are not abbreviated using ``::''. */ int dk4socket_addr_port_to_text( dkChar *dptr, size_t dsz, int afam, const struct sockaddr *saptr, size_t sasz, dk4_er_t *erp ); /** Convert generic socket address structure to dkChar text. @param dptr Destination buffer address. @param dsz Destination buffer size (Number of dkChar). @param saptr Pointer to socket address structure. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Restriction: If neither the getnameinfo() nor the inet_ntop() function is available (i.e. on Windows with DK4_WINDOWS_LEGACY enabled) IPv6 adddresses containing zero sequences are not abbreviated using ``::''. Error codes: - DK4_E_INVALID_ARGUMENTS - DK4_E_SOCKET_GETADDRINFO - DK4_E_SYNTAX - DK4_E_BUFFER_TOO_SMALL */ int dk4socket_sockaddr_to_text( dkChar *dptr, size_t dsz, const dk4_sockaddr_storage_t *saptr, dk4_er_t *erp ); /* Convert text to IP address (char). ---------------------------------- Module: dk4sock06 */ /** Convert text IP address to struct in_addr or struct in6_addr. @param pAddr Pointer to destination buffer. @param szAddr Destination buffer size. @param afam Address family (AF_INET or AF_INET6). @param src Source text. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error Error codes: - DK4_E_INVALID_ARGUMENTS
if pAddr or src is NULL or szAddr is 0, or szAddr does not have the correct size for the specified family, - DK4_E_SYNTAX
if src does not contain a valid IPv4 or IPv6 address, - DK4_E_SOCKET_INET_PTON
if the inet_pton() function failed for some reason. */ int dk4socket_c8_inet_pton( void *pAddr, size_t szAddr, int afam, const char *src, dk4_er_t *erp ); /* Convert text to IP address (wchar_t). ------------------------------------- Module: dk4sock07 */ /** Convert text IP address to struct in_addr or struct in6_addr. @param pAddr Pointer to destination buffer. @param szAddr Destination buffer size. @param afam Address family (AF_INET or AF_INET6). @param src Source text. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error Error codes: - DK4_E_INVALID_ARGUMENTS
if pAddr or src is NULL or szAddr is 0, - DK4_E_BUFFER_TOO_SMALL
if src is too long for conversion into an internal buffer, - DK4_E_SYNTAX
if src contains non-ASCII characters or is not a valid IPv6 or IPv6 address, - DK4_E_SOCKET_INET_PTON
if InetPtonW() fails for some reason. */ int dk4socket_wc_inet_pton( void *pAddr, size_t szAddr, int afam, const wchar_t *src, dk4_er_t *erp ); /* Convert text to IP address (dkChar). ------------------------------------ Module: dk4sock08 */ /** Convert text IP address to struct in_addr or struct in6_addr. @param pAddr Pointer to destination buffer. @param szAddr Destination buffer size. @param afam Address family (AF_INET or AF_INET6). @param src Source text. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if pAddr or src is NULL or szAddr is 0, - DK4_E_BUFFER_TOO_SMALL
if src is too long for conversion into an internal buffer, - DK4_E_SYNTAX
if src contains non-ASCII characters or is not a valid IPv6 or IPv6 address, - DK4_E_SOCKET_INET_PTON
if inet_pton() or InetPtonW() fails for some reason. */ int dk4socket_inet_pton( void *pAddr, size_t szAddr, int afam, const dkChar *src, dk4_er_t *erp ); /* Bring socket subsystem up and down. ----------------------------------- Module: dk4sock09 */ /** Bring socket subsystem up. This function calls WSAStartup() on Windows, simply indicates success on all other systems. @param er Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: * DK4_E_SOCKET_UP
with WSAGetLastError() result in iDetails1 if a WinSock error occured. */ int dk4socket_up(dk4_er_t *er); /** Bring socket subsystem down. This function calls WSACleanup() on Windows, simply indicates success on all other systems. @param er Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: * DK4_E_SOCKET_DOWN
with WSAGetLastError() result in iDetails1 if a WinSock error occured. */ int dk4socket_down(dk4_er_t *er); /* Basic socket operations (open and close). ----------------------------------------- Module: dk4sock10 */ /** Open a socket. @param af Address family (AF_INET or AF_INET6). @param tp Socket type (SOCK_STREAM or SOCK_DGRAM). @param pr Protocol (0). @param erp Error report, may be NULL. @return New socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if af is not one from AF_INET, AF_INET6, AF_UNIX, or AF_LOCAL or tp is not one from SOCK_STREAM or SOCK_DGRAM or pr is not 0, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. */ dk4_socket_t dk4socket_open(int af, int tp, int pr, dk4_er_t *erp); /** Shut down socket. @param so Socket to shut down. @param how Choose tasks to end, one from: DK4_SOCKET_SHUT_READ to stop reading (receiving), DK4_SOCKET_SHUT_WRITE to stop writing (sending), or DK4_SOCKET_SHUT_RDWR to stop both. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. */ int dk4socket_shutdown(dk4_socket_t so, int how, dk4_er_t *erp); /** Close a socket. @param so Socket to close. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if af is not one from AF_INET, AF_INET6, AF_UNIX, or AF_LOCAL or tp is not one from SOCK_STREAM or SOCK_DGRAM or pr is not 0, - DK4_E_SOCKET_CLOSE
with errno/WSAGetLastError() value in iDetails1 if the close()/closesocket() function failed. */ int dk4socket_close(dk4_socket_t so, dk4_er_t *erp); /* Address binding. ---------------- Module: dk4sock11 */ /** Bind a local address. @param sock Socket to configure. @param pAddr Pointer to socket address buffer. @param szAddr Size of socket address buffer. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if the address pointer is NULL or the address size is 0, - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. */ int dk4socket_bind( dk4_socket_t sock, const struct sockaddr *pAddr, size_t szAddr, dk4_er_t *erp ); /* Client side: connecting to remote server. ----------------------------------------- Module: dk4sock12 */ /** Connect to remote server. @param sock Socket to configure. @param pAddr Pointer to remote socket address buffer. @param szAddr Size of remote socket address buffer. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_IN_PROGRESS if the operation is still in progress, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if remote address pointer is NULL or remote address size is 0, - DK4_E_SOCKET_CONNECT
with errno/WSAGetLastError() value in iDetails1 if the connect() function failed. */ int dk4socket_connect( dk4_socket_t sock, const struct sockaddr *pAddr, size_t szAddr, dk4_er_t *erp ); #if DK4_HAVE_STRUCT_SOCKADDR_UN /** Create a UNIX domain socket in client mode. @param filename File name, max 107 characters long. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. */ dk4_socket_t dk4socket_c8_unix_client( const char *filename, dk4_er_t *erp ); #endif /* Server side: listen and accept. ------------------------------- Module: dk4sock13 */ /** Listen on a socket. @param sock Socket to configure for listening. @param bl Backlog (Number of connections requests to queue). @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. */ int dk4socket_listen( dk4_socket_t sock, int bl, dk4_er_t *erp ); /** Accept incoming connection requests on listener socket. @param sock Listener socket. @param pAddr Pointer to address buffer, address of a dk4_sockaddr_storage_t recommended, NULL allowed. @param pSzAddr Pointer to address buffer size variable, in: buffer size, out: used size, should be NULL if pAddr is NULL. @param erp Error report, may be NULL. @return Socket for new connection on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_ACCEPT
with errno/WSAGetLastError() value in iDetails1 if the accept() function failed. */ dk4_socket_t dk4socket_accept( dk4_socket_t sock, struct sockaddr *pAddr, size_t *pSzAddr, dk4_er_t *erp ); #if DK4_HAVE_STRUCT_SOCKADDR_UN /** Create a UNIX domain socket in listening state. @param filename File name, max 107 characters long. @param backlog Number of connection requests to queue. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if filename is NULL or backlog is 0, - DK4_E_SYNTAX
if the file name is too long, - DK4_E_NON_SOCKET
if the file exists but is not a socket, - DK4_E_UNLINK_FAILED
if deletion of an already existing socket failed, - DK4_E_SOCKET_SOCKET
with errno value in iDetails1 if the socket() function failed, - DK4_E_SOCKET_BIND
with errno value in iDetails1 if the bind() function failed, - DK4_E_SOCKET_LISTEN
with errno value in iDetails1 if the listen() function failed, - DK4_E_CHMOD_FAILED
with errno value in iDetails1 if the chmod() function failed. */ dk4_socket_t dk4socket_c8_unix_listener( const char *filename, int backlog, dk4_er_t *erp ); /** Create a UNIX domain socket in listening state, change ownership and permission. This function is intended for use in daemons which will give up root privileges before doing any service. @param filename File name, max 107 characters long. @param backlog Number of connection requests to queue. @param owner Owner UID. @param group Owner GID. @param mode File permissions in octal notation. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if filename is NULL or backlog is 0, - DK4_E_SYNTAX
if the file name is too long, - DK4_E_NON_SOCKET
if the file exists but is not a socket, - DK4_E_UNLINK_FAILED
if deletion of an already existing socket failed, - DK4_E_SOCKET_SOCKET
with errno value in iDetails1 if the socket() function failed, - DK4_E_SOCKET_BIND
with errno value in iDetails1 if the bind() function failed, - DK4_E_SOCKET_LISTEN
with errno value in iDetails1 if the listen() function failed, - DK4_E_CHOWN_FAILED
with errno value in iDetails1 if the chown() function failed, - DK4_E_CHMOD_FAILED
with errno value in iDetails1 if the chmod() function failed. */ dk4_socket_t dk4socket_c8_unix_listener_owner_group_mode( const char *filename, int backlog, uid_t owner, gid_t group, mode_t mode, dk4_er_t *erp ); #endif /* Set socket options. ------------------- Module: dk4sock14 */ /** Set reuse flag for socket. Typically you should call this function immediately after creating the socket before binding any local address. @param sock @param val @param erp @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_NOT_SUPPORTED
if the setsockopt() function is not available, - DK4_E_INVALID_ARGUMENTS
if the socket is invalid, - DK4_E_SOCKET_SETSOCKOPT
if setsockopt() indicated an error. */ int dk4socket_option_set_reuse( dk4_socket_t sock, int val, dk4_er_t *erp ); /** Set broadcast flag for socket. Typically you should call this function immediately after creating the socket before binding any local address. @param sock @param val @param erp @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_NOT_SUPPORTED
if the setsockopt() function is not available, - DK4_E_INVALID_ARGUMENTS
if the socket is invalid, - DK4_E_SOCKET_SETSOCKOPT
if setsockopt() indicated an error. */ int dk4socket_option_set_broadcast( dk4_socket_t sock, int val, dk4_er_t *erp ); /* Set non-blocking mode. ---------------------- Module: dk4sock15 */ /** Set non-blocking mode for socket. @param sock @param val @param erp @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_FCNTL
with errno value in iDetails1 if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET with WSAGetLastError() value in iDetails1 if the ioctlsocket() function failed. */ int dk4socket_option_set_nonblock( dk4_socket_t sock, int val, dk4_er_t *erp ); /* Create client side connection. ------------------------------ Module: dk4sock16 */ /** Create client side socket for a given address pair (remote and local address). @param protfam Protocol family (PF_INET or PF_INET6). @param pRemoteAddr Pointer to address structure containing remote address. @param szRemoteAddr Size of remote address. @param pLocalAddr Pointer to address structure for local address to bind, may be NULL to chose any address. @param szLocalAddr Size of remote address, must be 0 if pLocalAddr is NULL. @param seconds Timeout in seconds. @param microSeconds Timeout in microseconds. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. For all error codes - except DK4_E_SOCKET_TIMEOUT - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_tcp_client_for_addr( int protfam, struct sockaddr *pRemoteAddr, size_t szRemoteAddr, struct sockaddr *pLocalAddr, size_t szLocalAddr, long seconds, long microSeconds, dk4_er_t *erp ); /* Choose remote and optionaly local address and connect. ------------------------------------------------------ Module: dk4sock17 */ /** Connect to a specified host name and service name. @param hostname Host name to connect to. @param svcname Service name or port number as string. @param lsvcname Local service name or port number as string. @param secs Timeout seconds (may be 0). @param usecs Timeout microseconds (may be 0). @param nsrv Flag: svname and lsvcname are numeric strings. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_GETHOSTBYNAME
if the gethostbyname() function failed to find the remote host. - DK4_E_SOCKET_GETSERVBYNAME
if the getservbyname() function failed to find the port number for the remote or local service. - DK4_E_SOCKET_GETADDRLOC
if the getaddrinfo() function failed to find local addresses. - DK4_E_SOCKET_GETADDRINFO
if the getaddrinfo() function failed to find the remote host, - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. - DK4_E_BUG
if the gethostbyname() function returned non-matching or otherwise illegal address lengths. For all error codes - except DK4_E_SOCKET_TIMEOUT and DK4_E_BUG - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_c8_tcp_client_host_num_srv( const char *hostname, const char *svcname, const char *lsvcname, long secs, long usecs, int nsrv, dk4_er_t *erp ); /** Connect to a specified host name and service name. @param hostname Host name to connect to. @param svcname Service name or port number as string. @param lsvcname Local service name or port number as string. @param secs Timeout seconds (may be 0). @param usecs Timeout microseconds (may be 0). @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_GETHOSTBYNAME
if the gethostbyname() function failed to find the remote host. - DK4_E_SOCKET_GETSERVBYNAME
if the getservbyname() function failed to find the port number for the remote or local service. - DK4_E_SOCKET_GETADDRLOC
if the getaddrinfo() function failed to find local addresses. - DK4_E_SOCKET_GETADDRINFO
if the getaddrinfo() function failed to find the remote host, - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. - DK4_E_BUG
if the gethostbyname() function returned non-matching or otherwise illegal address lengths. For all error codes - except DK4_E_SOCKET_TIMEOUT and DK4_E_BUG - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_c8_tcp_client_host_srv( const char *hostname, const char *svcname, const char *lsvcname, long secs, long usecs, dk4_er_t *erp ); /** Connect to a specified host name and port number. @param hostname Host name to connect to. @param portno Port number in host byte order to connect to. @param lportno Local port number in host byte order (0 = any). @param secs Timeout seconds (may be 0). @param usecs Timeout microseconds (may be 0). @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_GETHOSTBYNAME
if the gethostbyname() function failed to find the remote host. - DK4_E_SOCKET_GETSERVBYNAME
if the getservbyname() function failed to find the port number for the remote or local service. - DK4_E_SOCKET_GETADDRLOC
if the getaddrinfo() function failed to find local addresses. - DK4_E_SOCKET_GETADDRINFO
if the getaddrinfo() function failed to find the remote host, - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. - DK4_E_BUG
if the gethostbyname() function returned non-matching or otherwise illegal address lengths. For all error codes - except DK4_E_SOCKET_TIMEOUT and DK4_E_BUG - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_c8_tcp_client_host_port( const char *hostname, unsigned short portno, unsigned short lportno, long secs, long usecs, dk4_er_t *erp ); /* Choose remote and optionally local address and connect (wchar_t). ----------------------------------------------------------------- Module: dk4sock18 */ /** Connect to a specified host name and service name. @param hostname Host name to connect to. @param svcname Service name or port number as string. @param lsvcname Local service name or port number as string. @param secs Timeout seconds (may be 0). @param usecs Timeout microseconds (may be 0). @param nsrv Flag: svname and lsvcname are numeric strings. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_GETHOSTBYNAME
if the gethostbyname() function failed to find the remote host. - DK4_E_SOCKET_GETSERVBYNAME
if the getservbyname() function failed to find the port number for the remote or local service. - DK4_E_SOCKET_GETADDRLOC
if the getaddrinfo() function failed to find local addresses. - DK4_E_SOCKET_GETADDRINFO
if the getaddrinfo() function failed to find the remote host, - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. - DK4_E_BUG
if the gethostbyname() function returned non-matching or otherwise illegal address lengths, - DK4_E_NOT_SUPPORTED
if wide character functions for networking are not available. For all error codes - except DK4_E_SOCKET_TIMEOUT and DK4_E_BUG - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_wc_tcp_client_host_num_srv( const wchar_t *hostname, const wchar_t *svcname, const wchar_t *lsvcname, long secs, long usecs, int nsrv, dk4_er_t *erp ); /** Connect to a specified host name and service name. @param hostname Host name to connect to. @param svcname Service name or port number as string. @param lsvcname Local service name or port number as string. @param secs Timeout seconds (may be 0). @param usecs Timeout microseconds (may be 0). @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_GETHOSTBYNAME
if the gethostbyname() function failed to find the remote host. - DK4_E_SOCKET_GETSERVBYNAME
if the getservbyname() function failed to find the port number for the remote or local service. - DK4_E_SOCKET_GETADDRLOC
if the getaddrinfo() function failed to find local addresses. - DK4_E_SOCKET_GETADDRINFO
if the getaddrinfo() function failed to find the remote host, - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. - DK4_E_BUG
if the gethostbyname() function returned non-matching or otherwise illegal address lengths, - DK4_E_NOT_SUPPORTED
if no wide character functions for networking are avaialble. For all error codes - except DK4_E_SOCKET_TIMEOUT, DK4_E_NOT_SUPPORTED and DK4_E_BUG - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_wc_tcp_client_host_srv( const wchar_t *hostname, const wchar_t *svcname, const wchar_t *lsvcname, long secs, long usecs, dk4_er_t *erp ); /** Connect to a specified host name and port number. @param hostname Host name to connect to. @param portno Port number in host byte order to connect to. @param lportno Local port number in host byte order (0 = any). @param secs Timeout seconds (may be 0). @param usecs Timeout microseconds (may be 0). @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_GETHOSTBYNAME
if the gethostbyname() function failed to find the remote host. - DK4_E_SOCKET_GETSERVBYNAME
if the getservbyname() function failed to find the port number for the remote or local service. - DK4_E_SOCKET_GETADDRLOC
if the getaddrinfo() function failed to find local addresses. - DK4_E_SOCKET_GETADDRINFO
if the getaddrinfo() function failed to find the remote host, - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. - DK4_E_BUG
if the gethostbyname() function returned non-matching or otherwise illegal address lengths, - DK4_E_NOT_SUPPORTED
if no wide character functions for networking are available. For all error codes - except DK4_E_SOCKET_TIMEOUT and DK4_E_BUG - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_wc_tcp_client_host_port( const wchar_t *hostname, unsigned short portno, unsigned short lportno, long secs, long usecs, dk4_er_t *erp ); /* Choose remote and optionaly local address and connect (dkChar). --------------------------------------------------------------- Module: dk4sock19 */ /** Connect to a specified host name and service name. @param hostname Host name to connect to. @param svcname Service name or port number as string. @param lsvcname Local service name or port number as string. @param secs Timeout seconds (may be 0). @param usecs Timeout microseconds (may be 0). @param nsrv Flag: svname and lsvcname are numeric strings. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_GETHOSTBYNAME
if the gethostbyname() function failed to find the remote host. - DK4_E_SOCKET_GETSERVBYNAME
if the getservbyname() function failed to find the port number for the remote or local service. - DK4_E_SOCKET_GETADDRLOC
if the getaddrinfo() function failed to find local addresses. - DK4_E_SOCKET_GETADDRINFO
if the getaddrinfo() function failed to find the remote host, - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. - DK4_E_BUG
if the gethostbyname() function returned non-matching or otherwise illegal address lengths, - DK4_E_NOT_SUPPORTED
if wide character functions for networking are not available. For all error codes - except DK4_E_SOCKET_TIMEOUT and DK4_E_BUG - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_tcp_client_host_num_srv( const dkChar *hostname, const dkChar *svcname, const dkChar *lsvcname, long secs, long usecs, int nsrv, dk4_er_t *erp ); /** Connect to a specified host name and service name. @param hostname Host name to connect to. @param svcname Service name or port number as string. @param lsvcname Local service name or port number as string. @param secs Timeout seconds (may be 0). @param usecs Timeout microseconds (may be 0). @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_GETHOSTBYNAME
if the gethostbyname() function failed to find the remote host. - DK4_E_SOCKET_GETSERVBYNAME
if the getservbyname() function failed to find the port number for the remote or local service. - DK4_E_SOCKET_GETADDRLOC
if the getaddrinfo() function failed to find local addresses. - DK4_E_SOCKET_GETADDRINFO
if the getaddrinfo() function failed to find the remote host, - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. - DK4_E_BUG
if the gethostbyname() function returned non-matching or otherwise illegal address lengths, - DK4_E_NOT_SUPPORTED
if no wide character functions for networking are avaialble. For all error codes - except DK4_E_SOCKET_TIMEOUT, DK4_E_NOT_SUPPORTED and DK4_E_BUG - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_tcp_client_host_srv( const dkChar *hostname, const dkChar *svcname, const dkChar *lsvcname, long secs, long usecs, dk4_er_t *erp ); /** Connect to a specified host name and port number. @param hostname Host name to connect to. @param portno Port number in host byte order to connect to. @param lportno Local port number in host byte order (0 = any). @param secs Timeout seconds (may be 0). @param usecs Timeout microseconds (may be 0). @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is bad, - DK4_E_SOCKET_SOCKET
if the socket() function failed to create a new socket, - DK4_E_SOCKET_BIND
if the bind() function failed to bind the requested local address, - DK4_E_SOCKET_FCNTL
if the fcntl() function failed, - DK4_E_SOCKET_IOCTLSOCKET if the ioctlsocket() function failed. - DK4_E_SOCKET_GETHOSTBYNAME
if the gethostbyname() function failed to find the remote host. - DK4_E_SOCKET_GETSERVBYNAME
if the getservbyname() function failed to find the port number for the remote or local service. - DK4_E_SOCKET_GETADDRLOC
if the getaddrinfo() function failed to find local addresses. - DK4_E_SOCKET_GETADDRINFO
if the getaddrinfo() function failed to find the remote host, - DK4_E_SOCKET_CONNECT
if the connect() function failed, - DK4_E_SOCKET_TIMEOUT
if a timeout occured in the connect attempt, - DK4_E_SOCKET_SELECT
if the select() function failed, - DK4_E_SOCKET_GETSOCKOPT
if the getsockopt() function failed. - DK4_E_BUG
if the gethostbyname() function returned non-matching or otherwise illegal address lengths, - DK4_E_NOT_SUPPORTED
if no wide character functions for networking are available. For all error codes - except DK4_E_SOCKET_TIMEOUT and DK4_E_BUG - the iDetails1 field contains the errno or WSAGetLastError() value. */ dk4_socket_t dk4socket_tcp_client_host_port( const dkChar *hostname, unsigned short portno, unsigned short lportno, long secs, long usecs, dk4_er_t *erp ); /* Send and receive data over an established connection. ----------------------------------------------------- Module: dk4sock20 */ /** Send data. @param sock Socket to use. @param buf Start address of buffer. @param pszbuf Pointer to size variable (in: buffer size, out: bytes send). @param flags Flags for send() function. @param secs Seconds for timeout. @param usecs Microseconds for timeout. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error (0 bytes send), DK4_SOCKET_RESULT_IN_PROGRESS on partial success. Error codes: - DK4_E_INVALID_ARGUMENTS
if sock is an invalid socket, buf is NULL, pszbuf is NULL, *pszbuf is 0 or *pszbuf is too large to fit into an ssize_t or int, - DK4_E_SOCKET_TIMEOUT
if the timeout was reached without getting the socket writable, - DK4_E_SOCKET_SELECT
if the select() function failed (details in iDetails1), - DK4_E_SOCKET_SEND
if the send() function failed (details in iDetails1). */ int dk4socket_send( dk4_socket_t sock, const void *buf, size_t *pszbuf, int flags, long secs, long usecs, dk4_er_t *erp ); /** Receive data. @param sock Socket to use. @param buf Start address of buffer. @param pszbuf Pointer to size variable (in: buffer size, out: bytes received). @param flags Flags for send() function. @param secs Seconds for timeout. @param usecs Microseconds for timeout. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if sock is an invalid socket, buf is NULL, pszbuf is NULL, *pszbuf is 0 or *pszbuf is too large to fit into an ssize_t or int, - DK4_E_SOCKET_TIMEOUT
if the timeout was reached without getting data on the socket, - DK4_E_SOCKET_SELECT
if the select() function failed (details in iDetails1), - DK4_E_SOCKET_RECV
if the send() function failed (details in iDetails1). */ int dk4socket_recv( dk4_socket_t sock, void *buf, size_t *pszbuf, int flags, long secs, long usecs, dk4_er_t *erp ); /* Connectionless send and receive operations. ------------------------------------------- Module: dk4sock21 */ /** Send UDP datagram. @param sock Socket to use. @param buf Start address of buffer. @param pszbuf Pointer to size variable (in: buffer size, out: bytes send). @param flags Flags for sendto() function. @param saddr Pointer to destination address. @param addrlen Length of destination address. @param secs Seconds for timeout. @param usecs Microseconds for timeout. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_IN_PROGRESS on partial success (not all bytes send), DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if sock is an invalid socket, buf is NULL, pszbuf is NULL, *pszbuf is 0 or *pszbuf is too large to fit into an ssize_t or int, - DK4_E_SOCKET_TIMEOUT
if the timeout was reached without getting data on the socket, - DK4_E_SOCKET_SELECT
if the select() function failed (details in iDetails1), - DK4_E_SOCKET_RECV
if the send() function failed (details in iDetails1). */ int dk4socket_sendto( dk4_socket_t sock, const void *buf, size_t *pszbuf, int flags, const struct sockaddr *saddr, size_t addrlen, long secs, long usecs, dk4_er_t *erp ); /** Receive UDP datagram. @param sock Socket to use. @param buf Start address of buffer. @param pszbuf Pointer to size variable (in: buffer size, out: bytes used). @param flags Flags for recvfrom() function. @param saddr Pointer to buffer for source address. @param paddrlen Source address buffer size. @param secs Seconds for timeout. @param usecs Microseconds for timeout. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if sock is an invalid socket, buf is NULL, pszbuf is NULL, *pszbuf is 0 or *pszbuf is too large to fit into an ssize_t or int, - DK4_E_SOCKET_TIMEOUT
if the timeout was reached without getting data on the socket, - DK4_E_SOCKET_SELECT
if the select() function failed (details in iDetails1), - DK4_E_SOCKET_RECV
if the send() function failed (details in iDetails1). */ int dk4socket_recvfrom( dk4_socket_t sock, void *buf, size_t *pszbuf, int flags, struct sockaddr *saddr, size_t *paddrlen, long secs, long usecs, dk4_er_t *erp ); /* Listener socket set (create and delete). ---------------------------------------- Module: dk4sock22 */ /** Allocate memory for a socket set but do not open any socket (set all to INVALID_SOCKET). @param max Number of sockets to plan for. @param erp Error report, may be NULL. @return Pointer to new socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if max is 0, - DK4_E_MATH_OVERFLOW
on numeric overflow when calculating the number of bytes to allocate, - DK4_E_MEMORY_ALLOCATION_FAILED
with mem.elsize and mem.nelem set if there is not enough memory available. */ dk4_socket_set_t * dk4socket_set_new( size_t max, dk4_er_t *erp ); /** Delete socket set (do not close anything, just release the memory). @param set Socket set to destroy. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if set is NULL. */ void dk4socket_set_delete( dk4_socket_set_t *set, dk4_er_t *erp ); /** Close all sockets and delete the socket set (release memory). @param set Socket set to close. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if set is NULL. - DK4_E_SOCKET_CLOSE
with errno/WSAGetLastError() value in iDetails1 if the close()/closesocket() function failed. */ void dk4socket_set_close( dk4_socket_set_t *set, dk4_er_t *erp ); /* Create listener socket set for local/remote connections. -------------------------------------------------------- Module: dk4sock23 */ /** Create listener socket set for a local port number, do not use getaddrinfo() to obtain local addresses, construct addresses. @param portno Local port number to listen on. @param local Flag: Allow local connections only. @param backlog Number of connection requests to queue. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. */ dk4_socket_set_t * dk4socket_set_server_directly( unsigned short portno, int backlog, int local, dk4_er_t *erp ); /* Create listener socket set for local/remote connections. -------------------------------------------------------- Module: dk4sock24 */ /** Create listener socket set for a local port number, use getaddrinfo() if available to obtain a collection of local addresses. @param portno Local port number to listen on. @param local Flag: Allow local connections only. @param backlog Number of connection requests to queue. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. - DK4_E_SOCKET_GETADDRLOC
with errno/WSAGetLastError() value in iDetails1 if the getaddrinfo() function failed. */ dk4_socket_set_t * dk4socket_c8_set_server( unsigned short portno, int backlog, int local, dk4_er_t *erp ); /** Create listener socket set for a local port number. @param servicename Local service name. @param backlog Number of connection requests to queue. @param local Flag: Allow local connections only. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. - DK4_E_SOCKET_GETADDRLOC
with errno/WSAGetLastError() value in iDetails1 if the getaddrinfo() function failed. - DK4_E_SYNTAX
if a non-digit was found in a port number, - DK4_E_SOCKET_GETSERVBYNAME
with errno/WSAGetLastError() value in iDetails1 if the getservbyname() function failed to find a port number of a service, */ dk4_socket_set_t * dk4socket_c8_set_service( const char *servicename, int backlog, int local, dk4_er_t *erp ); /* dkChar variants of the functions above. --------------------------------------- Module: dk4sock25 */ /** Create listener socket set for a local port number. @param portno Local port number to listen on. @param local Flag: Allow local connections only. @param backlog Number of connection requests to queue. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. - DK4_E_SOCKET_GETADDRLOC
with errno/WSAGetLastError() value in iDetails1 if the getaddrinfo() function failed. */ dk4_socket_set_t * dk4socket_set_server( unsigned short portno, int backlog, int local, dk4_er_t *erp ); /** Create listener socket set for a local port number. @param servicename Local service name. @param backlog Number of connection requests to queue. @param local Flag: Allow local connections only. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. - DK4_E_SOCKET_GETADDRLOC
with errno/WSAGetLastError() value in iDetails1 if the getaddrinfo() function failed. - DK4_E_SOCKET_GETSERVBYNAME
with errno/WSAGetLastError() value in iDetails1 if the getservbyname() function failed to find a port number of a service, */ dk4_socket_set_t * dk4socket_set_service( const dkChar *servicename, int backlog, int local, dk4_er_t *erp ); /* Get allowed peer from char string. ---------------------------------- Module: dk4sock26 */ /** Get allowed peer from string. @param peerptr Data structure to save peer information. @param str Text containing the information. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS - DK4_E_BUFFER_TOO_SMALL - DK4_E_SYNTAX
if the IP address component in str is not a valid IPv4 or IPv6 address, the mask component is not a valid IPv4 or IPv6 address or an unsigned bit number or the bit number is too large, - DK4_E_SOCKET_INET_PTON
if the inet_pton() function failed for some reason. */ int dk4socket_c8_get_allowed_peer( dk4_allowed_peer_t *peerptr, const char *str, dk4_er_t *erp ); /* Get allowed peer from dkChar string. ------------------------------------ Module: dk4sock27 */ /** Get allowed peer from string. @param peerptr Data structure to save peer information. @param str Text containing the information. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS - DK4_E_BUFFER_TOO_SMALL - DK4_E_SYNTAX
if the IP address component in str is not a valid IPv4 or IPv6 address, the mask component is not a valid IPv4 or IPv6 address or an unsigned bit number or the bit number is too large, - DK4_E_SOCKET_INET_PTON
if the inet_pton() function failed for some reason. */ int dk4socket_get_allowed_peer( dk4_allowed_peer_t *peerptr, const dkChar *str, dk4_er_t *erp ); /* Comparison of allowed peers. ---------------------------- Module: dk4sock28 */ /** Compare allowed peers. @param pl Left pointer, always dk4_allowed_peer_t. @param pr Right pointer, dk4_allowed_peer_t or struct sockaddr. @param cr Comparison criteria: 1: pr is struct sockaddr, else pr is dk4_allowed_peer_t. @return -1, 0 or 1 for plpr. */ int dk4socket_allowed_peer_compare( const void *pl, const void *pr, int cr ); /* Create UDP socket set for local/remote connections. --------------------------------------------------- Module: dk4sock29 */ /** Create server UDP socket set for a local port number, do not use getaddrinfo() to obtain local addresses, construct addresses. @param portno Local port number to listen on. @param local Flag: Allow local connections only. @param broadcast Flag: Prepare for broadcast sending. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. */ dk4_socket_set_t * dk4socket_set_udp_directly( unsigned short portno, int local, int broadcast, dk4_er_t *erp ); /* Create UDP socket set for local/remote connections. --------------------------------------------------- Module: dk4sock30 */ /** Create UDP socket set for a local port number, use getaddrinfo() if available to obtain a collection of local addresses. @param portno Local port number to listen on. @param local Flag: Allow local connections only. @param broadcast Flag: Prepare for broadcast send. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. - DK4_E_SOCKET_GETADDRLOC
with errno/WSAGetLastError() value in iDetails1 if the getaddrinfo() function failed. */ dk4_socket_set_t * dk4socket_c8_set_udp( unsigned short portno, int local, int broadcast, dk4_er_t *erp ); /** Create UDP socket set for a local port number. @param servicename Local service name. @param local Flag: Allow local connections only. @param broadcast Flag: Prepare for broadcast transmission. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. - DK4_E_SOCKET_GETADDRLOC
with errno/WSAGetLastError() value in iDetails1 if the getaddrinfo() function failed. - DK4_E_SYNTAX
if a non-digit was found in a port number, - DK4_E_SOCKET_GETSERVBYNAME
with errno/WSAGetLastError() value in iDetails1 if the getservbyname() function failed to find a port number of a service, */ dk4_socket_set_t * dk4socket_c8_set_udp_service( const char *servicename, int local, int broadcast, dk4_er_t *erp ); /* Create UDP socket set for local/remote connections. --------------------------------------------------- Module: dk4sock31 */ /** Create UDP socket set for a local port number, use getaddrinfo() if available to obtain a collection of local addresses. @param portno Local port number to listen on. @param local Flag: Allow local connections only. @param broadcast Flag: Prepare for broadcast send. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. - DK4_E_SOCKET_GETADDRLOC
with errno/WSAGetLastError() value in iDetails1 if the getaddrinfo() function failed. */ dk4_socket_set_t * dk4socket_set_udp( unsigned short portno, int local, int broadcast, dk4_er_t *erp ); /** Create UDP socket set for a local port number. @param servicename Local service name. @param local Flag: Allow local connections only. @param broadcast Flag: Prepare for broadcast transmission. @param erp Error report, may be NULL. @return Socket set on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if an invalid argument was specified, - DK4_E_MATH_OVERFLOW
if there was a numeric overflow in memory size calculation (should not happen), - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed. - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. - DK4_E_SOCKET_LISTEN
with errno/WSAGetLastError() value in iDetails1 if the listen() function failed. - DK4_E_SOCKET_GETADDRLOC
with errno/WSAGetLastError() value in iDetails1 if the getaddrinfo() function failed. - DK4_E_SYNTAX
if a non-digit was found in a port number, - DK4_E_SOCKET_GETSERVBYNAME
with errno/WSAGetLastError() value in iDetails1 if the getservbyname() function failed to find a port number of a service, */ dk4_socket_set_t * dk4socket_set_udp_service( const dkChar *servicename, int local, int broadcast, dk4_er_t *erp ); /* Prepare addresses for UDP client socket. ---------------------------------------- Module: dk4sock32 */ /** Get address family for generic socket address structure. @param aptr Address of generic socket address structure. @return AF_INET or AF_INET6 on success, AF_UNSPEC on error. */ int dk4socket_address_family(dk4_sockaddr_storage_t *aptr); /** Get used structure size for generic socket address structure. @param aptr Address of generic socket address structure. @return Size of sockaddr_in or sockaddr_in6 on success, 0 on error. */ size_t dk4socket_address_size(dk4_sockaddr_storage_t *aptr); /** Complete address structures if IP address was found (add port numbers). @param array Address structures array (2 elements: 0=remote, 1=local). @param remport Remote port number. @param locport Local port number. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. */ int dk4socket_complete_addresses( dk4_sockaddr_storage_t *array, unsigned short remport, unsigned short locport ); /* Prepare addresses for UDP client socket. ---------------------------------------- Module: dk4sock33 */ /** Find addresses to send UDP packets to a remote host. @param array Destination array (2 elements), element 0 is the remote address to send to, element 1 is the local address to bind. @param remhost Remote host name or IP address. @param remport Remote port number in host representation. @param locport Local port number in host representation. @param ip4 Flag: Prefer IPv4 addresses. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
for invalid arguments, - DK4_E_NOT_FOUND
if the requested host was not found. */ int dk4socket_c8_udp_addresses_numeric( dk4_sockaddr_storage_t *array, const char *remhost, unsigned short remport, unsigned short locport, int ip4, dk4_er_t *erp ); /* Prepare addresses for UDP client socket. ---------------------------------------- Module: dk4sock34 */ /** Find addresses to send UDP packets to a remote host (wchar_t). @param array Destination array (2 elements), element 0 is the remote address to send to, element 1 is the local address to bind. @param remhost Remote host name or IP address. @param remport Remote port number in host representation. @param locport Local port number in host representation. @param ip4 Flag: Prefer IPv4 addresses. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
for invalid arguments, - DK4_E_NOT_FOUND
if the requested host was not found. */ int dk4socket_wc_udp_addresses_numeric( dk4_sockaddr_storage_t *array, const wchar_t *remhost, unsigned short remport, unsigned short locport, int ip4, dk4_er_t *erp ); /** Find addresses to send UDP packets to a remote host (dkChar). @param array Destination array (2 elements), element 0 is the remote address to send to, element 1 is the local address to bind. @param remhost Remote host name or IP address. @param remport Remote port number in host representation. @param locport Local port number in host representation. @param ip4 Flag: Prefer IPv4 addresses. @param erp Error report, may be NULL. @return DK4_SOCKET_RESULT_SUCCESS on success, DK4_SOCKET_RESULT_FAILED on error. Error codes: - DK4_E_INVALID_ARGUMENTS
for invalid arguments, - DK4_E_NOT_FOUND
if the requested host was not found. - DK4_E_NOT_SUPPORTED
if networking with wide characters is not supported. */ int dk4socket_udp_addresses_numeric( dk4_sockaddr_storage_t *array, const dkChar *remhost, unsigned short remport, unsigned short locport, int ip4, dk4_er_t *erp ); /* Create UDP socket and bind to local port. ----------------------------------------- Module: dk4sock35 */ /** Create UDP socket bound to local port. @param protfam Protocol family, PF_INET or PF_INET6. @param pLocalAddr Local address to bind. @param szLocalAddr Size of local address. @param erp Error report. may be NULL. @return Valid socket on success, INVALID_SOCKET on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if pLocalAddr is NULL or szLocalAddr is 0 or protfam is not a valid protocol family, - DK4_E_SOCKET_SOCKET
with errno/WSAGetLastError() value in iDetails1 if the socket() function failed, - DK4_E_SOCKET_BIND
with errno/WSAGetLastError() value in iDetails1 if the bind() function failed. */ dk4_socket_t dk4socket_udp_client_for_addr( int protfam, struct sockaddr *pLocalAddr, size_t szLocalAddr, dk4_er_t *erp ); /* Create UDP socket and bind to local port. ----------------------------------------- Module: dk4sock36 */ /** Create UDP socket for communication to remote host (char). @param array Destination array (2 elements), element 0 is the remote address we want to send data to, element 1 is the local address to use. @param remhost Remote host name or address. @param remport Remote port number in host representation. @param locport Local port number in host representation. @param ip4 Flag: Prefer IPv4 over IPv6. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. */ dk4_socket_t dk4socket_c8_udp_client_for_host( dk4_sockaddr_storage_t *array, const char *remhost, unsigned short remport, unsigned short locport, int ip4, dk4_er_t *erp ); /* Create UDP socket and bind to local port. ----------------------------------------- Module: dk4sock37 */ /** Create UDP socket for communication to remote host (wchar_t). @param array Destination array (2 elements), element 0 is the remote address we want to send data to, element 1 is the local address to use. @param remhost Remote host name or address. @param remport Remote port number in host representation. @param locport Local port number in host representation. @param ip4 Flag: Prefer IPv4 over IPv6. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. */ dk4_socket_t dk4socket_wc_udp_client_for_host( dk4_sockaddr_storage_t *array, const wchar_t *remhost, unsigned short remport, unsigned short locport, int ip4, dk4_er_t *erp ); /** Create UDP socket for communication to remote host (dkChar). @param array Destination array (2 elements), element 0 is the remote address we want to send data to, element 1 is the local address to use. @param remhost Remote host name or address. @param remport Remote port number in host representation. @param locport Local port number in host representation. @param ip4 Flag: Prefer IPv4 over IPv6. @param erp Error report, may be NULL. @return Valid socket on success, INVALID_SOCKET on error. */ dk4_socket_t dk4socket_udp_client_for_host( dk4_sockaddr_storage_t *array, const dkChar *remhost, unsigned short remport, unsigned short locport, int ip4, dk4_er_t *erp ); #ifdef __cplusplus } #endif #endif /* ifndef DK4SOCK_H_INCLUDED */