/* * $port: configure_network.cpp,v 1.7 2009/11/20 22:44:19 tuxbox-cvs Exp $ * * (C) 2003 by thegoodguy * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include #include /* perror... */ #include #include /* u_char */ #include #include #include "configure_network.h" #include /* netGetNameserver, netSetNameserver */ #include /* getInetAttributes, setInetAttributes */ #include #include #include #include #include CNetworkConfig::CNetworkConfig() { netGetNameserver(nameserver); ifname = "eth0"; orig_automatic_start = false; orig_inet_static = false; automatic_start = false; inet_static = false; wireless = false; } CNetworkConfig* CNetworkConfig::getInstance() { static CNetworkConfig* network_config = NULL; if(!network_config) { network_config = new CNetworkConfig(); printf("[network config] Instance created\n"); } return network_config; } CNetworkConfig::~CNetworkConfig() { } void CNetworkConfig::readConfig(std::string iname) { ifname = iname; inet_static = getInetAttributes(ifname, automatic_start, address, netmask, broadcast, gateway); init_vars(); copy_to_orig(); } void CNetworkConfig::init_vars(void) { std::string mask; std::string _broadcast; std::string router; std::string ip; unsigned char addr[6]; netGetHostname(hostname); netGetDefaultRoute(router); gateway = router; /* FIXME its enough to read IP for dhcp only ? * static config should not be different from settings in etc/network/interfaces */ if(!inet_static) { netGetIP(ifname, ip, mask, _broadcast); netmask = mask; broadcast = _broadcast; address = ip; } netGetMacAddr(ifname, addr); std::stringstream mac_tmp; for(int i=0;i<6;++i) mac_tmp<