Networking Services Library Functions netdir(3NSL)
NAME
netdir, netdirgetbyname, netdirgetbyaddr, netdirfree,
netdiroptions, taddr2uaddr, uaddr2taddr, netdirperror,
netdirsperror, netdirmergeaddr - generic transport name-
to-address translation
SYNOPSIS
cc [ flag... ] file... -lnsl [ library...]
#include
int netdirgetbyname(struct netconfig *config,
struct ndhostserv *service, struct ndaddrlist **addrs);
int netdirgetbyaddr(struct netconfig *config,
struct ndhostservlist **service, struct netbuf *netaddr);
void netdirfree(void *ptr, int structtype);
int netdiroptions(struct netconfig *config, int option, int fildes,
char *pointtoargs);
char *taddr2uaddr(struct netconfig *config, struct netbuf *addr);
struct netbuf *uaddr2taddr(struct netconfig *config, char *uaddr);
void netdirperror(char *s);
char *netdirsperror(void);
DESCRIPTION
The netdir functions provide a generic interface for name-
to-address mapping that will work with all transport proto-
cols. This interface provides a generic way for programs to
convert transport specific addresses into common structures
and back again. The netconfig structure, described on the
netconfig(4) manual page, identifies the transport.
The netdirgetbyname() function maps the machine name and
service name in the ndhostserv structure to a collection of
addresses of the type understood by the transport identified
in the netconfig structure. This function returns all
addresses that are valid for that transport in the
ndaddrlist structure. The ndhostserv structure contains
SunOS 5.11 Last change: 28 Jan 2005 1
Networking Services Library Functions netdir(3NSL)
the following members:
char *hhost; /* host name */
char *hserv; /* service name */
The ndaddrlist structure contains the following members:
int ncnt; /* number of addresses */
struct netbuf *naddrs;
The netdirgetbyname() function accepts some special-case
host names. The host names are defined in . The
currently defined host names are:
HOSTSELF Represents the address to which local
programs will bind their endpoints.
HOSTSELF differs from the host name
provided by gethostname(3C), which
represents the address to which remote
programs will bind their endpoints.
HOSTANY Represents any host accessible by this
transport provider. HOSTANY allows
applications to specify a required ser-
vice without specifying a particular
host name.
HOSTSELFCONECT Represents the host address that can be
used to connect to the local host.
HOSTBROADCAST Represents the address for all hosts
accessible by this transport provider.
Network requests to this address are
received by all machines.
All fields of the ndhostserv structure must be initialized.
To find the address of a given host and service on all
available transports, call the netdirgetbyname() function
with each struct netconfig structure returned by
getnetconfig(3NSL).
SunOS 5.11 Last change: 28 Jan 2005 2
Networking Services Library Functions netdir(3NSL)
The netdirgetbyaddr() function maps addresses to service
names. The function returns service, a list of host and ser-
vice pairs that yield these addresses. If more than one
tuple of host and service name is returned, the first tuple
contains the preferred host and service names:
struct ndhostservlist {
int *hcnt; /* number of hostservs found */
struct hostserv *hhostservs;
}
The netdirfree() structure is used to free the structures
allocated by the name to address translation functions. The
ptr parameter points to the structure that has to be freed.
The parameter structtype identifies the structure:
struct netbuf NDADR
struct ndaddrlist NDADRLIST
struct hostserv NDHOSTSERV
struct ndhostservlist NDHOSTSERVLIST
The free() function is used to free the universal address
returned by the taddr2uaddr() function.
The netdiroptions() function is used to do all transport-
specific setups and option management. fildes is the associ-
ated file descriptor. option, fildes, and pointertoargs
are passed to the netdiroptions() function for the tran-
sport specified in config. Currently four values are defined
for option:
NDSETBROADCAST
NDSETRESERVEDPORT
NDCHECKRESERVEDPORT
NDMERGEADR
The taddr2uaddr() and uaddr2taddr() functions support trans-
lation between universal addresses and TLI type netbufs. The
taddr2uaddr() function takes a struct netbuf data structure
and returns a pointer to a string that contains the univer-
sal address. It returns NUL if the conversion is not possi-
ble. This is not a fatal condition as some transports do not
support a universal address form.
The uaddr2taddr() function is the reverse of the
taddr2uaddr() function. It returns the struct netbuf data
SunOS 5.11 Last change: 28 Jan 2005 3
Networking Services Library Functions netdir(3NSL)
structure for the given universal address.
If a transport provider does not support an option,
netdiroptions returns -1 and the error message can be
printed through netdirperror() or netdirsperror().
The specific actions of each option follow.
NDSETBROADCAST Sets the transport provider up to
allow broadcast if the transport
supports broadcast. fildes is a
file descriptor into the transport,
that is, the result of a topen of
/dev/udp. pointertoargs is not
used. If this completes, broadcast
operations can be performed on file
descriptor fildes.
NDSETRESERVEDPORT Allows the application to bind to a
reserved port if that concept
exists for the transport provider.
fildes is an unbound file descrip-
tor into the transport. If
pointertoargs is NUL, fildes is
bound to a reserved port. If
pointertoargs is a pointer to a
netbuf structure, an attempt is
made to bind to any reserved port
on the specified address.
NDCHECKRESERVEDPORT Used to verify that the address
corresponds to a reserved port if
that concept exists for the tran-
sport provider. fildes is not used.
pointertoargs is a pointer to a
netbuf structure that contains the
address. This option returns 0 only
if the address specified in
pointertoargs is reserved.
NDMERGEADR Used to take a ``local address''
such as a 0.0.0.0 TCP address and
return a ``real address'' to which
client machines can connect. fildes
is not used. pointertoargs is a
pointer to a struct ndmergearg
which has the following members:
SunOS 5.11 Last change: 28 Jan 2005 4
Networking Services Library Functions netdir(3NSL)
char suaddr; /* server's universal address */
char cuaddr; /* client's universal address */
char muaddr; /* the result */
If suaddr is an address such as
0.0.0.0.1.12, and the call is suc-
cessful muaddr is set to an
address such as 192.11.109.89.1.12.
For most transports, muaddr is
identical to suaddr.
RETURN VALUES
The netdirperror() function prints an error message in
standard output that states the cause of a name-to-address
mapping failure. The error message is preceded by the string
given as an argument.
The netdirsperror() function returns a string with an error
message that states the cause of a name-to-address mapping
failure.
The netdirsperror() function returns a pointer to a buffer
which contains the error message string. The buffer is
overwritten on each call. In multithreaded applications,
thise buffer is implemented as thread-specific data.
The netdirgetbyaddr() function returns 0 on success and a
non-zero value on failure.
ATRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
ATRIBUTE TYPE ATRIBUTE VALUE
MT-Level Safe
SEE ALSO
gethostname(3C), getnetconfig(3NSL), getnetpath(3NSL),
netconfig(4), attributes(5)
SunOS 5.11 Last change: 28 Jan 2005 5
|