Benny Prijono | 4766ffe | 2005-11-01 17:56:59 +0000 | [diff] [blame] | 1 | /* $Id$ |
Benny Prijono | 4766ffe | 2005-11-01 17:56:59 +0000 | [diff] [blame] | 2 | */ |
Benny Prijono | dd859a6 | 2005-11-01 16:42:51 +0000 | [diff] [blame] | 3 | |
| 4 | #ifndef __PJ_ADDR_RESOLV_H__ |
| 5 | #define __PJ_ADDR_RESOLV_H__ |
| 6 | |
| 7 | /** |
| 8 | * @file addr_resolv.h |
| 9 | * @brief Address resolve (pj_gethostbyname()). |
| 10 | */ |
| 11 | |
| 12 | #include <pj/types.h> |
| 13 | |
| 14 | PJ_BEGIN_DECL |
| 15 | |
| 16 | /** |
Benny Prijono | a7f64a3 | 2005-11-07 15:47:28 +0000 | [diff] [blame] | 17 | * @defgroup pj_addr_resolve Network Address Resolution |
Benny Prijono | dd859a6 | 2005-11-01 16:42:51 +0000 | [diff] [blame] | 18 | * @ingroup PJ_IO |
| 19 | * @{ |
| 20 | * |
| 21 | * This module provides function to resolve Internet address of the |
| 22 | * specified host name. To resolve a particular host name, application |
| 23 | * can just call #pj_gethostbyname(). |
| 24 | * |
| 25 | * Example: |
| 26 | * <pre> |
| 27 | * ... |
| 28 | * pj_hostent he; |
| 29 | * pj_status_t rc; |
| 30 | * pj_str_t host = pj_str("host.example.com"); |
| 31 | * |
| 32 | * rc = pj_gethostbyname( &host, &he); |
| 33 | * if (rc != PJ_SUCCESS) { |
| 34 | * char errbuf[80]; |
| 35 | * pj_strerror( rc, errbuf, sizeof(errbuf)); |
| 36 | * PJ_LOG(2,("sample", "Unable to resolve host, error=%s", errbuf)); |
| 37 | * return rc; |
| 38 | * } |
| 39 | * |
| 40 | * // process address... |
| 41 | * addr.sin_addr.s_addr = *(pj_uint32_t*)he.h_addr; |
| 42 | * ... |
| 43 | * </pre> |
| 44 | * |
| 45 | * It's pretty simple really... |
| 46 | */ |
| 47 | |
| 48 | /** This structure describes an Internet host address. */ |
| 49 | typedef struct pj_hostent |
| 50 | { |
| 51 | char *h_name; /**< The official name of the host. */ |
| 52 | char **h_aliases; /**< Aliases list. */ |
| 53 | int h_addrtype; /**< Host address type. */ |
| 54 | int h_length; /**< Length of address. */ |
| 55 | char **h_addr_list; /**< List of addresses. */ |
| 56 | } pj_hostent; |
| 57 | |
| 58 | /** Shortcut to h_addr_list[0] */ |
| 59 | #define h_addr h_addr_list[0] |
| 60 | |
| 61 | /** |
| 62 | * This function fills the structure of type pj_hostent for a given host name. |
| 63 | * |
| 64 | * @param name Host name, or IPv4 or IPv6 address in standard dot notation. |
| 65 | * @param he The pj_hostent structure to be filled. |
| 66 | * |
| 67 | * @return PJ_SUCCESS, or the appropriate error codes. |
| 68 | */ |
| 69 | PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he); |
| 70 | |
| 71 | |
| 72 | /** @} */ |
| 73 | |
| 74 | PJ_END_DECL |
| 75 | |
| 76 | #endif /* __PJ_ADDR_RESOLV_H__ */ |
| 77 | |