00001 // Copyright 2006 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the 00015 // Free Software Foundation, Inc., 00016 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 /*! 00019 * @defgroup addr Internet address conversion 00020 * 00021 * The addr_hton() and addr_ntoh() functions convert from host- to 00022 * network-byteorder, and vice versa, respectively. 00023 * 00024 * The addr_from_str() function converts the Internet host address in standard 00025 * numbers-and-dots notation pointed to by the string str into binary data and 00026 * stores result in the ip/mask pair of pointers. addr_from_str() returns 0 if 00027 * no argument was converted, 1 if ip was converted, 2 for mask and 3 for both. 00028 * 00029 * The addr_to_str() function converts the Internet host address given in the 00030 * ip/mask pair of pointers to a string in standard numbers-and-dots notation. 00031 * The returned string is obtained by malloc and should be free(3)'d by the 00032 * caller. 00033 * 00034 * @{ 00035 */ 00036 00037 #ifndef _LUCID_ADDR_H 00038 #define _LUCID_ADDR_H 00039 00040 #include <stdint.h> 00041 00042 /*! 00043 * @brief convert address from host to network byte order 00044 * 00045 * @param[in] addr address in host byte order 00046 * 00047 * @return address in network byte order 00048 */ 00049 uint32_t addr_hton(uint32_t addr); 00050 00051 /*! 00052 * @brief convert address from network to host byte order 00053 * 00054 * @param[in] addr address in network byte order 00055 * 00056 * @return address in host byte order 00057 */ 00058 uint32_t addr_ntoh(uint32_t addr); 00059 00060 /*! 00061 * @brief convert string to IP address and netmask 00062 * 00063 * @param[in] str string in CIDR or netmask notation 00064 * @param[out] ip pointer to store IP address 00065 * @param[out] mask pointer to store netmask 00066 * 00067 * @return 0 if no argument was converted, 1 if ip was 00068 * converted, 2 for mask and 3 for both. 00069 */ 00070 int addr_from_str(const char *str, uint32_t *ip, uint32_t *mask); 00071 00072 /*! 00073 * @brief convert IP address and netmask to string 00074 * 00075 * @param[in] ip IP adress to convert 00076 * @param[in] mask netmask to convert 00077 * 00078 * @return string in netmask notation (obtained with malloc(3)) 00079 * 00080 * @note The caller should free obtained memory using free(3) 00081 * 00082 * @see malloc(3) 00083 * @see free(3) 00084 */ 00085 char *addr_to_str(uint32_t ip, uint32_t mask); 00086 00087 #endif 00088 00089 /*! @} addr */