Send UDP packets through a SOCKSv5 server.
Standard C Library (libc.a)
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/socket.h>
int socks5udp_sendto (Socket, Message, MsgLen, Flags, Dst, DstLen, Svr, SvrLen)
int Socket;
void *Message;
size_t MsgLen;
int Flags;
struct sockaddr *Dst;
size_t DstLen;
struct sockaddr *Svr;
size_t SrvLen;
The socks5udp_sendto subroutine sends a UDP packet to Svr for relay to Dst. Svr must be the rendezvous address returned from a previous call to socks5udp_associate.
Socket must be an open socket descriptor of type SOCK_DGRAM; Dst and Svr may be either IPv4 or IPv6 addresses.
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. |
Message | Specifies the address containing the message to be sent. |
MsgLen | Specifies the size of the message in bytes. |
Flags | Allows the sender to control the message transmission. See the description in the sendto subroutine for more specific details. |
Dst | Specifies the external address to which the SOCKSv5 server will attempt to relay the UDP packet. |
DstLength | Specifies the length of the address structure in Dst. |
Svr | Specifies the address of the SOCKSv5 server to send the UDP packet for relay. |
SvrLength | Specifies the length of the address structure in Svr. |
Upon successful completion, the socks5udp_sendto subroutine returns a value of 0.
If the socks5udp_sendto subroutine is unsuccessful, the system handler performs the following functions:
The socks5tcp_connect 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. |
EAFNOSUPPORT | The addresses in the specified address family cannot be used with this socket. |
ENETUNREACH | No route to the network or host is present. |
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. |
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_sendto subroutine by a client to request a connection from a server's socket.
void *message;
size_t msglen;
int flags;
struct sockaddr_in svr;
struct sockaddr_in6 dst;
.
.
.
socks5udp_associate(s,(struct sockaddr*)&dst, sizeof(dst), (struct sockaddr *)&svr, sizeof(svr));
.
.
.
socks5udp_sendto(s, message, msglen, flags (struct sockaddr*)&dst, sizeof(dst), (struct sockaddr *)&svr, sizeof(svr));