/* * $port: configure_network.cpp,v 1.7 2009/11/20 22:44:19 tuxbox-cvs Exp $ * * (C) 2003 by thegoodguy * (C) 2011 Stefan Seyfried * * 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 3 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, see . */ #include #include /* perror... */ #include #include /* u_char */ #include #include "configure_network.h" #include "libnet.h" /* netGetNameserver, netSetNameserver */ #include "network_interfaces.h" /* getInetAttributes, setInetAttributes */ #include /* system */ #include #include #include #include #include CNetworkConfig::CNetworkConfig() { char our_nameserver[16]; netGetNameserver(our_nameserver); nameserver = our_nameserver; ifname = "eth0"; } 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) { char mask[16]; char _broadcast[16]; char router[16]; char ip[16]; unsigned char addr[6]; hostname = netGetHostname(); 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((char *) ifname.c_str(), ip, mask, _broadcast); netmask = mask; broadcast = _broadcast; address = ip; } netGetMacAddr((char *) ifname.c_str(), addr); std::stringstream mac_tmp; for(int i=0;i<6;++i) mac_tmp<