00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (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 Free Software 00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00016 00017 #include "addr.h" 00018 #include "printf.h" 00019 00020 char *addr_to_str(uint32_t ip, uint32_t mask) 00021 { 00022 char *buf; 00023 00024 char *ipp = (char *) &ip; 00025 char *maskp = (char *) &mask; 00026 00027 if (mask) 00028 _lucid_asprintf(&buf, "%hhu.%hhu.%hhu.%hhu/%hhu.%hhu.%hhu.%hhu", 00029 ipp[0], ipp[1], ipp[2], ipp[3], 00030 maskp[0], maskp[1], maskp[2], maskp[3]); 00031 00032 else 00033 _lucid_asprintf(&buf, "%hhu.%hhu.%hhu.%hhu", 00034 ipp[0], ipp[1], ipp[2], ipp[3]); 00035 00036 return buf; 00037 }