Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | a771a51 | 2007-02-19 01:13:53 +0000 | [diff] [blame] | 3 | * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #ifndef __PJ_ADDR_RESOLV_H__ |
| 20 | #define __PJ_ADDR_RESOLV_H__ |
| 21 | |
| 22 | /** |
| 23 | * @file addr_resolv.h |
Benny Prijono | 594e4c5 | 2006-09-14 18:51:01 +0000 | [diff] [blame] | 24 | * @brief IP address resolution. |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 25 | */ |
| 26 | |
Benny Prijono | 594e4c5 | 2006-09-14 18:51:01 +0000 | [diff] [blame] | 27 | #include <pj/sock.h> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 28 | |
| 29 | PJ_BEGIN_DECL |
| 30 | |
| 31 | /** |
| 32 | * @defgroup pj_addr_resolve Network Address Resolution |
| 33 | * @ingroup PJ_IO |
| 34 | * @{ |
| 35 | * |
| 36 | * This module provides function to resolve Internet address of the |
| 37 | * specified host name. To resolve a particular host name, application |
| 38 | * can just call #pj_gethostbyname(). |
| 39 | * |
| 40 | * Example: |
| 41 | * <pre> |
| 42 | * ... |
| 43 | * pj_hostent he; |
| 44 | * pj_status_t rc; |
| 45 | * pj_str_t host = pj_str("host.example.com"); |
| 46 | * |
| 47 | * rc = pj_gethostbyname( &host, &he); |
| 48 | * if (rc != PJ_SUCCESS) { |
| 49 | * char errbuf[80]; |
| 50 | * pj_strerror( rc, errbuf, sizeof(errbuf)); |
| 51 | * PJ_LOG(2,("sample", "Unable to resolve host, error=%s", errbuf)); |
| 52 | * return rc; |
| 53 | * } |
| 54 | * |
| 55 | * // process address... |
| 56 | * addr.sin_addr.s_addr = *(pj_uint32_t*)he.h_addr; |
| 57 | * ... |
| 58 | * </pre> |
| 59 | * |
| 60 | * It's pretty simple really... |
| 61 | */ |
| 62 | |
| 63 | /** This structure describes an Internet host address. */ |
| 64 | typedef struct pj_hostent |
| 65 | { |
| 66 | char *h_name; /**< The official name of the host. */ |
| 67 | char **h_aliases; /**< Aliases list. */ |
| 68 | int h_addrtype; /**< Host address type. */ |
| 69 | int h_length; /**< Length of address. */ |
| 70 | char **h_addr_list; /**< List of addresses. */ |
| 71 | } pj_hostent; |
| 72 | |
| 73 | /** Shortcut to h_addr_list[0] */ |
| 74 | #define h_addr h_addr_list[0] |
| 75 | |
| 76 | /** |
| 77 | * This function fills the structure of type pj_hostent for a given host name. |
| 78 | * |
| 79 | * @param name Host name, or IPv4 or IPv6 address in standard dot notation. |
| 80 | * @param he The pj_hostent structure to be filled. |
| 81 | * |
| 82 | * @return PJ_SUCCESS, or the appropriate error codes. |
| 83 | */ |
| 84 | PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he); |
| 85 | |
| 86 | |
Benny Prijono | 594e4c5 | 2006-09-14 18:51:01 +0000 | [diff] [blame] | 87 | /** |
| 88 | * Resolve the primary IP address of local host. |
| 89 | * |
| 90 | * @param ip_addr On successful resolution, this will be filled up with |
| 91 | * the host IP address, in network byte order. |
| 92 | * |
| 93 | * @return PJ_SUCCESS on success, or the appropriate error code. |
| 94 | */ |
| 95 | PJ_DECL(pj_status_t) pj_gethostip(pj_in_addr *ip_addr); |
| 96 | |
| 97 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 98 | /** @} */ |
| 99 | |
| 100 | PJ_END_DECL |
| 101 | |
| 102 | #endif /* __PJ_ADDR_RESOLV_H__ */ |
| 103 | |