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 00019 static inline 00020 int islitend(void) { 00021 int i = 0; 00022 ((char *)(&i))[0] = 1; 00023 return i == 1; 00024 } 00025 00026 uint32_t addr_hton(uint32_t addr) 00027 { 00028 if (islitend()) 00029 return (addr >> 24) | 00030 ((addr & 0xff0000) >> 8) | 00031 ((addr & 0xff00 ) << 8) | 00032 (addr << 24); 00033 else 00034 return addr; 00035 }