Connects to a SOCKSv5 server, and requests a UDP association for subsequent UDP socket communications.
Standard C Library (libc.a)
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/socket.h>
int socks5udp_associate (Socket, Dst, DstLen, Svr, SvrLen)
int Socket;
const struct sockaddr *Dst;
size_t DstLen;
const struct sockaddr *Svr;
size_t SrvLen;
The socks5udp_associate subroutine requests a UDP association for Dst on the SOCKSv5 server specified in Svr. Upon success, Dst is overwritten with a rendezvous address to which subsequent UDP packets should be sent for relay by Svr.
Socket must be an open socket descriptor of type SOCK_STREAM; Dst and Svr may be either IPv4 or IPv6 addresses.
Note that Socket cannot be used to send subsequent UDP packets (a second socket of type SOCK_DGRAM must be created).
The socket applications can be compiled with COMPAT_43 defined. This will make the sockaddr structure BSD 4.3 compatible. For more details refer to socket.h.
Item | Description |
---|---|
Socket | Specifies the unique name of the socket. |
Dst | Specifies the external address of the target socket to which the SOCKSv5 client expects to send UDP packets. |
DstLength | Specifies the length of the address structure in Dst. |
Svr | Specifies the address of the SOCKSv5 server to use to request the association. |
SvrLength | Specifies the length of the address structure in Svr. |
Upon successful completion, the socks5udp_associate subroutine returns a value of 0 and overwrites Dst with the rendezvous address.
If the socks5udp_associate subroutine is unsuccessful, the system handler performs the following functions:
The socks5udp_associate subroutine is unsuccessful if any of the following errors occurs:
Error | Description |
---|---|
EBADF | The Socket parameter is not valid. |
ENOTSOCK | The Socket parameter refers to a file, not a socket. |
EADDRNOTAVAIL | The specified address is not available from the local machine. |
EAFNOSUPPORT | The addresses in the specified address family cannot be used with this socket. |
EISCONN | The socket is already connected. |
ETIMEDOUT | The establishment of a connection timed out before a connection was made. |
ECONNREFUSED | The attempt to connect was rejected. |
ENETUNREACH | No route to the network or host is present. |
EADDRINUSE | The specified address is already in use. |
EFAULT | The Address parameter is not in a writable part of the user address space. |
EINPROGRESS | The socket is marked as nonblocking. The connection cannot be immediately completed. The application program can select the socket for writing during the connection process. |
EINVAL | One or more of the specified arguments is invalid. |
ENETDOWN | The specified physical network is down. |
ENOSPC | There is no space left on a device or system table. |
ENOTCONN | The socket could not be connected. |
The socks5tcp_connect subroutine is unsuccessful if any of the following errors occurs:
Error | Description |
---|---|
S5_ESRVFAIL | General SOCKSv5 server failure. |
S5_EPERM | SOCKSv5 server ruleset rejection. |
S5_ENETUNREACH | SOCKSv5 server could not reach target network. |
S5_EHOSTUNREACH | SOCKSv5 server could not reach target host. |
S5_ECONNREFUSED | SOCKSv5 server connection request refused by target host. |
S5_ETIMEDOUT | SOCKSv5 server connection failure due to TTL expiry. |
S5_EOPNOTSUPP | Command not supported by SOCKSv5 server. |
S5_EAFNOSUPPORT | Address family not supported by SOCKSv5 server. |
S5_ENOSERV | No server found. |
The following program fragment illustrates the use of the socks5udp_associate subroutine by a client to request an association on a server.
struct sockaddr_in svr;
struct sockaddr_in6 dst;
.
.
.
socks5udp_associate(s,(struct sockaddr*)&dst, sizeof(dst), (struct sockaddr *)&svr, sizeof(svr));