XSocket API  2.0
XIA Socket Library
Functions
XgetDAGbyName.c File Reference

XgetDAGbyName(), XgetNamebyDAG(), XregisterName(), Xgetpeername(), Xgetsockname(), xia_ntop(), xia_pton() - network address management. More...

#include "Xsocket.h"

Functions

const char * xia_ntop (int af, const sockaddr_x *src, char *dst, socklen_t size)
 convert a DAG from binary to text form More...
 
int xia_pton (int af, const char *src, sockaddr_x *dst)
 convert a DAG from binary to text form More...
 
int _rquery (char *name, int namelen, const sockaddr_x *addr, char flags)
 
int _fquery (const char *name, sockaddr_x *addr, socklen_t *addrlen, char flags)
 
int XgetNamebyDAG (char *name, int namelen, const sockaddr_x *addr)
 reverse lookup, find a name based on the specified network address More...
 
int XgetHostIDbyDAG (char *name, int namelen, const sockaddr_x *addr)
 
int XgetAddrIDbyDAG (char *name, int namelen, const sockaddr_x *addr)
 
int XgetDAGbyName (const char *name, sockaddr_x *addr, socklen_t *addrlen)
 lookup a DAG using a host or service name More...
 
int XgetDAGbyHostID (const char *name, sockaddr_x *addr, socklen_t *addrlen)
 
int XgetDAGbyAddrID (const char *name, sockaddr_x *addr, socklen_t *addrlen)
 
int XregisterName (const char *name, sockaddr_x *DAG)
 register a service or hostname with the name server More...
 
int XregisterAddrID (const char *name, sockaddr_x *DAG)
 
int XregisterHostID (const char *name, sockaddr_x *DAG)
 
int Xgetpeername (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 get name of connected peer socket More...
 
int Xgetsockname (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 get socket name More...
 

Function Documentation

int _fquery ( const char *  name,
sockaddr_x *  addr,
socklen_t *  addrlen,
char  flags 
)
int _rquery ( char *  name,
int  namelen,
const sockaddr_x *  addr,
char  flags 
)
int XgetAddrIDbyDAG ( char *  name,
int  namelen,
const sockaddr_x *  addr 
)
int XgetDAGbyAddrID ( const char *  name,
sockaddr_x *  addr,
socklen_t *  addrlen 
)
int XgetDAGbyHostID ( const char *  name,
sockaddr_x *  addr,
socklen_t *  addrlen 
)
int XgetDAGbyName ( const char *  name,
sockaddr_x *  addr,
socklen_t *  addrlen 
)

Lookup the DAG associated with name.

The local hosts.xia file is checked first and if addr is not found, a query is sent to the nameserver.

Note
Xgetaddrinfo should be used rather than this function as it is very primative.
Parameters
namea test string representing the name of an XIA service or host
addra sockaddr_x to received the address
addrlenpointer to the length of addr on call, contains actual length on return
Returns
0 with addr filled in and addrlen specifying the length of addr
NULL on failure with errno set appropriately
int XgetHostIDbyDAG ( char *  name,
int  namelen,
const sockaddr_x *  addr 
)
int XgetNamebyDAG ( char *  name,
int  namelen,
const sockaddr_x *  addr 
)

Performs a reverse name lookup to find the name associated with addr.

The local hosts.xia file is checked first and if name is not found, a query is sent to the nameserver.

Parameters
namepointer to menory that will contain the returned name
namlenthe size of name
addrthe network address to lookup
Returns
0 with name filled in with a null terminted string. If name is not long enough, the returned name will be truncated.
-1 on failure with errno set appropraitely
int Xgetpeername ( int  sockfd,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

This function returns the address of the peer connected to the Xsocket sockfd, in the buffer pointed to by addr.

Note
See the man page for the standard getpeername() call for more details.
Parameters
sockfda connected Xsocket
dagA sockaddr to hold the returned DAG
lenOn input contans the size of the sockaddr on output contains sizeof(sockaddr_x).
Returns
0 on success
-1 on failure with errno set
errno = EFAULT if dag is NULL
errno = EOPNOTSUPP if sockfd is not of type XSSOCK_STREAM
errno = ENOTCONN if sockfd is not in a connected state
int Xgetsockname ( int  sockfd,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

Returns the current address to which the socket sockfd is bound, in the buffer pointed to by addr.

Note
See the man page for the standard getsockname() call for more details.
Parameters
sockfdAn Xsocket
dagA sockaddr_x to hold the returned DAG.
lenOn input contans the size of the addr, on output contains sizeof(sockaddr_x).
Returns
0 on success
-1 on failure with errno set
errno = EFAULT if dag is NULL
errno = EOPNOTSUPP if sockfd is not an Xsocket
const char* xia_ntop ( int  af,
const sockaddr_x *  src,
char *  dst,
socklen_t  size 
)

This function converts the network address structure src in the AF_XIA address family into a character string. The resulting string is copied to the buffer pointed to by dst, which must be a non-null pointer. The caller specifies the number of bytes available in this buffer in the argument size.

The returned text is formatted in the DAG text string format.

Parameters
affamily (must be AF_XIA)
srcDAG to convert
dstbuffer to hold the converted address
sizelength of dst
Returns
non-null pointer to dst on success
NULL with errno set on failure.
int xia_pton ( int  af,
const char *  src,
sockaddr_x *  dst 
)

This function converts the character string src into an XIA network address structure, then copies the network address structure to dst.

Parameters
affamily (must be AF_XIA)
srctext representation of the DAG to convert. Can be, DAG, RE, or HTTP formatted
dstdestination
Returns
1 on success (network address was successfully converted)
0 if src does not contain a character string representing a valid network address
-1 with errno set to EAFNOSUPPORT If af is not AF_XIA
int XregisterAddrID ( const char *  name,
sockaddr_x *  DAG 
)
int XregisterHostID ( const char *  name,
sockaddr_x *  DAG 
)
int XregisterName ( const char *  name,
sockaddr_x *  DAG 
)

Register a host or service name with the XIA nameserver.

Note
this function does not currently check to ensure that the client is allowed to bind to name.
Parameters
namethe name of an XIA service or host
DAGthe DAG to be bound to name
Returns
0 on success
-1 on failure with errno set