int netdir_getbyname(const struct netconfig *config, const struct nd_hostserv *service, struct nd_addrlist **addrs);
int netdir_getbyaddr(const struct netconfig *config, struct nd_hostservlist **service, const struct netbuf *netaddr);
void netdir_free(void *ptr, int ident);
char *taddr2uaddr(const struct netconfig *config, const struct netbuf *addr);
struct netbuf *uaddr2taddr(const struct netconfig *config, const char *uaddr);
int netdir_options(const struct netconfig *netconfig, int option, int fd, const char *pointer_to_args);
void netdir_perror(char *s);
The netdir_getbyname routine maps the machine name and service name in the nd_hostserv structure to a collection of addresses of the type understood by the transport identified in the netconfig structure. This routine returns all addresses that are valid for that transport in the nd_addrlist structure. The netconfig structure is described on the netconfig(4bnu) manual page. The nd_addrlist and nd_hostserv structures have the following elements:
int n_cnt; /* number of netbufs */ struct netbuf *n_addrs; /* the netbufs */
char *h_host; /* the hostname */ char *h_serv; /* the service name */netdir_getbyname accepts some special-case hostnames. These hostnames are hints to the underlying mapping routines that define the intent of the request. This information is required for some transport provider developers to provide the correct information back to the caller. The hostnames are defined in netdir.h. The currently defined hostnames are:
To find all available transports, call the netdir_getbyname routine with each netconfig structure returned by the getnetpath call.
The netdir_getbyaddr routine maps addresses to service names. This routine returns a list of host and service pairs that would yield this address. If more than one tuple of host and service name is returned then the first tuple contains the preferred host and service names. The nd_hostservlist structure contains the following members:
int h_cnt; /* the number of nd_hostservs */ struct hostserv *h_hostservs; /* the entries */The netdir_free structure is used to free the structures allocated by the name to address translation routines.
The following types of structures may be specified by the ident argument:
The taddr2uaddr and uaddr2taddr routines support translation between universal addresses and TLI type netbufs. They take and return character string pointers. The taddr2uaddr routine returns a pointer to a string that contains the universal address and returns NULL if the conversion is not possible. This is not a fatal condition, as some transports may not support a universal address form.
The netdir_options routine is used to pass options in a transport-independent manner to the transport provider specified by netconfig.
If a transport provider does not support an option, netdir_options returns -1 and sets _nderror to ND_FAILCTRL. If an option is specified that is not on the above list, netdir_options returns -1 and sets _nderror to ND_NOCTRL. In case of any other failure, to perform the required action, netdir_options returns -1 and sets _nderror to the appropriate value.
The specific actions of each option follow:
char *s_uaddr; /* server's universal address */ char *c_uaddr; /* client's universal address */ char *m_uaddr; /* merged universal address */For example, using TCP/IP,
s_uaddrcould be 0.0.0.0.1.12 (specifying a local port). The merged address would be set to a value such as 220.127.116.11.1.12 upon the return of the call.
The netdir_sperror routine returns a string containing an error message stating why one of the name-to-address mapping routines failed.
taddr2uaddr and uaddr2taddr return NULL in case of failure.
netdir_options returns -1 in case of error and 0 for success.
All functions set _nderror in case of failure. For netdir_options, when the fd parameter is used (denoting use of TLI calls), t_errno may provide additional insights into why a call failed.