[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2

socks5udp_sendto Subroutine


Send UDP packets through a SOCKSv5 server.


Standard C Library (libc.a)


#include <sys/types.h>
#include <sys/socket.h>
#include <socks5_api.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 DstSvr 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.


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.

Return Values

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:

Error Codes (placed in errno; inherited from underlying call to sendto())

The socks5tcp_connect subroutine is unsuccessful if any of the following errors occurs:

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.

Error Codes (placed in socks5_errno; SOCKSv5-specific errors)

The socks5tcp_connect subroutine is unsuccessful if any of the following errors occurs:

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));

Implementation Specifics

The socks5tcp_connect subroutine is part of Base Operating System (BOS) Runtime.

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.

Related Information

The socks5udp_associate subroutine, socks5_getserv subroutine, /etc/socks5c.conf file, bind subroutine, getsockname subroutine, sendto subroutine, socket subroutine.

Initiating UNIX Stream Connections Example Program, Sockets Overview, and Understanding Socket Connections in AIX 5L Version 5.1 Communications Programming Concepts.

SOCKS5C_CONFIG Environment Variable in AIX 5L Version 5.1 Files Reference.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]