socks5_getserv Subroutine

Purpose

Return the address of the SOCKSv5 server (if any) to use when connecting to a given destination.

Library

Standard C Library (libc.a)

Syntax

#include <stdlib.h>
#include <netinet/in.h>
#include <sys/socket.h>
struct sockaddr * socks5_getserv (Dst, DstLen)
struct sockaddr *Dst;
size_t DstLen;

Description

The socks5_getserv subroutine determines which (if any) SOCKSv5 server should be used as an intermediary when connecting to the address specified in Dst.

The address returned in Dst may be IPv4 or IPv6 or some other family.  The user should check the address family before using the returned data.

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.

Parameters

Item Description
Dst Specifies the external address of the target socket to use as a key for looking up the appropriate SOCKSv5 server.
DstLength Specifies the length of the address structure in Dst.

Return Values

Error Codes (placed in errno)

The socks5_getserv subroutine is unsuccessful if no server is indicated or if any of the following errors occurs:

Error Description
EAFNOSUPPORT The addresses in the specified address family cannot be used with this socket.
EFAULT The Dst parameter is not in a writable part of the user address space.
EINVAL One or more of the specified arguments is invalid.
ENOMEM The Dst parameter is not large enough to hold the server address.

Examples

The following program fragment illustrates the use of the socks5_getserv subroutine by a client to request a connection from a server's socket.

struct sockaddr_in6 dst;

struct sockaddr *srv;
.
.
.
srv = socks5_getserv((struct sockaddr*)&dst, sizeof(dst));

if (srv !=NULL)  {

     /* Success: srv should be used as the socks5 server */

} else {
     /* Failure: no server could be returned.  check errno */
     
}