BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

Data Structures

struct  pj_hostent
 
struct  pj_addrinfo
 

Macros

#define h_addr   h_addr_list[0]
 

Functions

pj_status_t pj_gethostbyname (const pj_str_t *name, pj_hostent *he)
 
pj_status_t pj_gethostip (int af, pj_sockaddr *addr)
 
pj_status_t pj_getipinterface (int af, const pj_str_t *dst, pj_sockaddr *itf_addr, pj_bool_t allow_resolve, pj_sockaddr *p_dst_addr)
 
pj_status_t pj_getdefaultipinterface (int af, pj_sockaddr *addr)
 
pj_status_t pj_getaddrinfo (int af, const pj_str_t *name, unsigned *count, pj_addrinfo ai[])
 

Detailed Description

This module provides function to resolve Internet address of the specified host name. To resolve a particular host name, application can just call pj_gethostbyname().

Example:

  ...
  pj_hostent he;
  pj_status_t rc;
  pj_str_t host = pj_str("host.example.com");
  rc = pj_gethostbyname( &host, &he);
  if (rc != PJ_SUCCESS) {
     char errbuf[80];
     pj_strerror( rc, errbuf, sizeof(errbuf));
     PJ_LOG(2,("sample", "Unable to resolve host, error=%s", errbuf));
     return rc;
  }
  // process address...
  addr.sin_addr.s_addr = *(pj_uint32_t*)he.h_addr;
  ...

It's pretty simple really...

Macro Definition Documentation

#define h_addr   h_addr_list[0]

Shortcut to h_addr_list[0]

Function Documentation

pj_status_t pj_getaddrinfo ( int  af,
const pj_str_t name,
unsigned *  count,
pj_addrinfo  ai[] 
)

This function translates the name of a service location (for example, a host name) and returns a set of addresses and associated information to be used in creating a socket with which to address the specified service.

Parameters
afThe desired address family to query. Valid values are pj_AF_INET(), pj_AF_INET6(), or pj_AF_UNSPEC().
nameDescriptive name or an address string, such as host name.
countOn input, it specifies the number of elements in ai array. On output, this will be set with the number of address informations found for the specified name.
aiArray of address info to be filled with the information about the host.
Returns
PJ_SUCCESS on success, or the appropriate error code.
pj_status_t pj_getdefaultipinterface ( int  af,
pj_sockaddr addr 
)

Get the IP address of the default interface. Default interface is the interface of the default route.

Parameters
afThe desired address family to query. Valid values are pj_AF_INET() or pj_AF_INET6().
addrOn successful resolution, the address family and address part of this socket address will be filled up with the host IP address, in network byte order. Other parts of the socket address are untouched.
Returns
PJ_SUCCESS on success, or the appropriate error code.
pj_status_t pj_gethostbyname ( const pj_str_t name,
pj_hostent he 
)

This function fills the structure of type pj_hostent for a given host name. For host resolution function that also works with IPv6, please see pj_getaddrinfo().

Parameters
nameHost name to resolve. Specifying IPv4 address here may fail on some platforms (e.g. Windows)
heThe pj_hostent structure to be filled. Note that the pointers in this structure points to temporary variables which value will be reset upon subsequent invocation.
Returns
PJ_SUCCESS, or the appropriate error codes.
pj_status_t pj_gethostip ( int  af,
pj_sockaddr addr 
)

Resolve the primary IP address of local host.

Parameters
afThe desired address family to query. Valid values are pj_AF_INET() or pj_AF_INET6().
addrOn successful resolution, the address family and address part of this socket address will be filled up with the host IP address, in network byte order. Other parts of the socket address are untouched.
Returns
PJ_SUCCESS on success, or the appropriate error code.
pj_status_t pj_getipinterface ( int  af,
const pj_str_t dst,
pj_sockaddr itf_addr,
pj_bool_t  allow_resolve,
pj_sockaddr p_dst_addr 
)

Get the interface IP address to send data to the specified destination.

Parameters
afThe desired address family to query. Valid values are pj_AF_INET() or pj_AF_INET6().
dstThe destination host.
itf_addrOn successful resolution, the address family and address part of this socket address will be filled up with the host IP address, in network byte order. Other parts of the socket address should be ignored.
allow_resolveIf dst may contain hostname (instead of IP address), specify whether hostname resolution should be performed. If not, default interface address will be returned.
p_dst_addrIf not NULL, it will be filled with the IP address of the destination host.
Returns
PJ_SUCCESS on success, or the appropriate error code.

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.