start using std::map for address storage; as things are easier to store, return and set parameters in header; works great!
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40560 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
c39eaa9d2d
commit
c81df02f40
@ -106,14 +106,14 @@ InterfaceAddressView::RevertFields()
|
||||
{
|
||||
// Populate address fields with current settings
|
||||
|
||||
const char* currMode = fSettings->AutoConfigure() ? "Automatic" : "Static";
|
||||
const char* currMode = fSettings->AutoConfigure(fFamily)
|
||||
? "Automatic" : "Static";
|
||||
|
||||
_EnableFields(!fSettings->AutoConfigure());
|
||||
_EnableFields(!fSettings->AutoConfigure(fFamily));
|
||||
// if Autoconfigured, disable address fields until changed
|
||||
|
||||
// TODO : AutoConfigure needs to be based on family
|
||||
if (fSettings->IPAddr(fFamily).IsEmpty()
|
||||
&& !fSettings->AutoConfigure())
|
||||
&& !fSettings->AutoConfigure(fFamily))
|
||||
{
|
||||
currMode = "None";
|
||||
_EnableFields(false);
|
||||
@ -143,3 +143,4 @@ InterfaceAddressView::SaveFields()
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
@ -95,9 +95,6 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
||||
{
|
||||
BListView* list = dynamic_cast<BListView*>(owner);
|
||||
|
||||
BNetworkAddress addrIPv4 = fSettings->IPAddr(AF_INET);
|
||||
BNetworkAddress addrIPv6 = fSettings->IPAddr(AF_INET6);
|
||||
|
||||
if (!list)
|
||||
return;
|
||||
|
||||
@ -127,8 +124,10 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
||||
} else if (!fInterface.HasLink()) {
|
||||
interfaceState << "no link";
|
||||
stateIcon = fIconOffline;
|
||||
} else if (addrIPv4.IsEmpty() && addrIPv6.IsEmpty()
|
||||
&& fSettings->AutoConfigure()) {
|
||||
} else if ((fSettings->IPAddr(AF_INET).IsEmpty()
|
||||
&& fSettings->IPAddr(AF_INET6).IsEmpty())
|
||||
&& (fSettings->AutoConfigure(AF_INET)
|
||||
|| fSettings->AutoConfigure(AF_INET6))) {
|
||||
interfaceState << "connecting" B_UTF8_ELLIPSIS;
|
||||
stateIcon = fIconPending;
|
||||
} else {
|
||||
@ -177,23 +176,23 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
||||
// Render IPv4 Address
|
||||
BString v4str("IPv4: ");
|
||||
|
||||
if (addrIPv4.IsEmpty())
|
||||
if (fSettings->IPAddr(AF_INET).IsEmpty())
|
||||
v4str << "none";
|
||||
else {
|
||||
v4str << addrIPv4.ToString();
|
||||
v4str << fSettings->IP(AF_INET);
|
||||
}
|
||||
|
||||
if (fSettings->AutoConfigure())
|
||||
if (fSettings->AutoConfigure(AF_INET))
|
||||
v4str << " (DHCP)";
|
||||
else
|
||||
v4str << " (manual)";
|
||||
v4str << " (static)";
|
||||
|
||||
list->DrawString(v4str.String(), v4addrPt);
|
||||
|
||||
// Render IPv6 Address (if present)
|
||||
if (!addrIPv6.IsEmpty()) {
|
||||
if (!fSettings->IPAddr(AF_INET6).IsEmpty()) {
|
||||
BString v6str("IPv6: ");
|
||||
v6str << addrIPv6.ToString();
|
||||
v6str << fSettings->IP(AF_INET6);
|
||||
list->DrawString(v6str, v6addrPt);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ Addon Interfaces :
|
||||
$(TARGET_NETWORK_LIBS)
|
||||
libbnetapi.so
|
||||
$(TARGET_LIBSUPC++)
|
||||
$(TARGET_LIBSTDC++)
|
||||
$(HAIKU_LOCALE_LIBS)
|
||||
libicon.a libagg.a
|
||||
;
|
||||
|
@ -35,13 +35,11 @@
|
||||
|
||||
NetworkSettings::NetworkSettings(const char* name)
|
||||
:
|
||||
fIPv4Auto(true),
|
||||
fIPv6Auto(true),
|
||||
fDisabled(false),
|
||||
fNameServers(5, true)
|
||||
{
|
||||
fSocket4 = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
fSocket6 = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
fSocket[AF_INET] = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
fSocket[AF_INET6] = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
|
||||
fName = name;
|
||||
|
||||
@ -51,13 +49,14 @@ NetworkSettings::NetworkSettings(const char* name)
|
||||
|
||||
NetworkSettings::~NetworkSettings()
|
||||
{
|
||||
close(fSocket4);
|
||||
close(fSocket6);
|
||||
close(fSocket[AF_INET]);
|
||||
close(fSocket[AF_INET6]);
|
||||
}
|
||||
|
||||
|
||||
// -- Interface address read code
|
||||
|
||||
|
||||
void
|
||||
NetworkSettings::ReadConfiguration()
|
||||
{
|
||||
@ -72,20 +71,20 @@ NetworkSettings::ReadConfiguration()
|
||||
|
||||
if (zeroAddrV4 >= 0) {
|
||||
fNetworkInterface.GetAddressAt(zeroAddrV4, netIntAddr4);
|
||||
fIPv4Addr = netIntAddr4.Address();
|
||||
fIPv4Mask = netIntAddr4.Mask();
|
||||
fAddress[AF_INET] = netIntAddr4.Address();
|
||||
fNetmask[AF_INET] = netIntAddr4.Mask();
|
||||
}
|
||||
|
||||
if (zeroAddrV6 >= 0) {
|
||||
fNetworkInterface.GetAddressAt(zeroAddrV6, netIntAddr6);
|
||||
fIPv6Addr = netIntAddr6.Address();
|
||||
fIPv6Mask = netIntAddr6.Mask();
|
||||
fAddress[AF_INET6] = netIntAddr6.Address();
|
||||
fNetmask[AF_INET6] = netIntAddr6.Mask();
|
||||
}
|
||||
|
||||
// Obtain gateway
|
||||
ifconf config;
|
||||
config.ifc_len = sizeof(config.ifc_value);
|
||||
if (ioctl(fSocket4, SIOCGRTSIZE, &config, sizeof(config)) < 0)
|
||||
if (ioctl(fSocket[AF_INET], SIOCGRTSIZE, &config, sizeof(config)) < 0)
|
||||
return;
|
||||
|
||||
uint32 size = (uint32)config.ifc_value;
|
||||
@ -100,7 +99,7 @@ NetworkSettings::ReadConfiguration()
|
||||
config.ifc_len = size;
|
||||
config.ifc_buf = buffer;
|
||||
|
||||
if (ioctl(fSocket4, SIOCGRTTABLE, &config, sizeof(config)) < 0)
|
||||
if (ioctl(fSocket[AF_INET], SIOCGRTTABLE, &config, sizeof(config)) < 0)
|
||||
return;
|
||||
|
||||
ifreq* interface = (ifreq*)buffer;
|
||||
@ -111,7 +110,7 @@ NetworkSettings::ReadConfiguration()
|
||||
|
||||
if ((route.flags & RTF_GATEWAY) != 0) {
|
||||
sockaddr_in* inetAddress = (sockaddr_in*)route.gateway;
|
||||
fIPv4Gateway = inet_ntoa(inetAddress->sin_addr);
|
||||
fGateway[AF_INET] = inet_ntoa(inetAddress->sin_addr);
|
||||
}
|
||||
|
||||
int32 addressSize = 0;
|
||||
@ -126,20 +125,20 @@ NetworkSettings::ReadConfiguration()
|
||||
+ sizeof(route_entry) + addressSize);
|
||||
}
|
||||
|
||||
fDisabled = (fNetworkInterface.Flags() & IFF_UP) == 0;
|
||||
|
||||
// Obtain selfconfiguration options
|
||||
|
||||
// TODO : This needs to be determined by the protocol flags
|
||||
// instead of the interface flag... protocol flags don't seem
|
||||
// to be complete yet. (netIntAddr4.Flags() and netIntAddr6.Flags())
|
||||
|
||||
fIPv4Auto = (fNetworkInterface.Flags()
|
||||
fAutoConfigure[AF_INET] = (fNetworkInterface.Flags()
|
||||
& (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0;
|
||||
|
||||
fIPv6Auto = (fNetworkInterface.Flags()
|
||||
fAutoConfigure[AF_INET6] = (fNetworkInterface.Flags()
|
||||
& (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0;
|
||||
|
||||
fDisabled = (fNetworkInterface.Flags() & IFF_UP) == 0;
|
||||
|
||||
// Read wireless network from interfaces
|
||||
|
||||
fWirelessNetwork.SetTo(NULL);
|
||||
@ -207,95 +206,3 @@ NetworkSettings::ReadConfiguration()
|
||||
}
|
||||
|
||||
|
||||
BNetworkAddress
|
||||
NetworkSettings::IPAddr(int family)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
return fIPv6Addr;
|
||||
|
||||
return fIPv4Addr;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
NetworkSettings::IP(int family)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
return fIPv6Addr.ToString();
|
||||
|
||||
return fIPv4Addr.ToString();
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
NetworkSettings::Netmask(int family)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
return fIPv6Mask.ToString();
|
||||
|
||||
return fIPv4Mask.ToString();
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
NetworkSettings::Gateway(int family)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
return fIPv6Gateway.ToString();
|
||||
|
||||
return fIPv4Gateway.ToString();
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
NetworkSettings::PrefixLen(int family)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
return fIPv6Mask.PrefixLength();
|
||||
|
||||
return fIPv4Mask.PrefixLength();
|
||||
}
|
||||
|
||||
|
||||
// -- Interface address write code
|
||||
|
||||
|
||||
void
|
||||
NetworkSettings::SetIP(int family, const char* ip)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
fIPv6Addr = ip;
|
||||
else
|
||||
fIPv4Addr = ip;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkSettings::SetNetmask(int family, const char* mask)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
fIPv6Mask = mask;
|
||||
else
|
||||
fIPv4Mask = mask;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkSettings::SetGateway(int family, const char* ip)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
fIPv6Gateway = ip;
|
||||
else
|
||||
fIPv4Gateway = ip;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkSettings::SetAutoConfigure(int family, bool autoConf)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
fIPv6Auto = autoConf;
|
||||
else
|
||||
fIPv4Auto = autoConf;
|
||||
}
|
||||
|
||||
|
@ -16,34 +16,53 @@
|
||||
#include <ObjectList.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
typedef std::map<int, BNetworkAddress> AddressMap;
|
||||
typedef std::map<int, bool> BoolMap;
|
||||
typedef std::map<int, int> SocketMap;
|
||||
|
||||
|
||||
class NetworkSettings {
|
||||
public:
|
||||
NetworkSettings(const char* name);
|
||||
virtual ~NetworkSettings();
|
||||
|
||||
void SetIP(int family, const char* ip);
|
||||
void SetNetmask(int family, const char* mask);
|
||||
void SetGateway(int family, const char* mask);
|
||||
void SetAutoConfigure(int family, bool autoConf);
|
||||
void SetIP(int family, const char* ip)
|
||||
{ fAddress[family].SetTo(ip); }
|
||||
void SetNetmask(int family, const char* mask)
|
||||
{ fNetmask[family].SetTo(mask); }
|
||||
void SetGateway(int family, const char* ip)
|
||||
{ fGateway[family].SetTo(ip); }
|
||||
void SetAutoConfigure(int family, bool autoConf)
|
||||
{ fAutoConfigure[family] = autoConf; }
|
||||
|
||||
void SetDisabled(bool disabled)
|
||||
{ fDisabled = disabled; }
|
||||
|
||||
// void SetWirelessNetwork(const char* name)
|
||||
// { fWirelessNetwork.SetTo(name); }
|
||||
// void SetDomain(const BString& domain)
|
||||
// { fDomain = domain; }
|
||||
|
||||
BNetworkAddress IPAddr(int family);
|
||||
|
||||
const char* IP(int family);
|
||||
const char* Netmask(int family);
|
||||
const char* Gateway(int family);
|
||||
int32 PrefixLen(int family);
|
||||
bool AutoConfigure(int family)
|
||||
{ return fAutoConfigure[family]; }
|
||||
BNetworkAddress IPAddr(int family)
|
||||
{ return fAddress[family]; }
|
||||
const char* IP(int family)
|
||||
{ return fAddress[family].ToString(); }
|
||||
const char* Netmask(int family)
|
||||
{ return fNetmask[family].ToString(); }
|
||||
const char* Gateway(int family)
|
||||
{ return fGateway[family].ToString(); }
|
||||
int32 PrefixLen(int family)
|
||||
{ return fNetmask[family].PrefixLength(); }
|
||||
|
||||
|
||||
const char* Name() { return fName.String(); }
|
||||
const char* Domain() { return fDomain.String(); }
|
||||
bool AutoConfigure() { return fIPv4Auto; }
|
||||
bool IsDisabled() { return fDisabled; }
|
||||
const BString& WirelessNetwork() { return fWirelessNetwork; }
|
||||
|
||||
@ -52,22 +71,14 @@ public:
|
||||
void ReadConfiguration();
|
||||
|
||||
private:
|
||||
int fSocket4;
|
||||
int fSocket6;
|
||||
|
||||
SocketMap fSocket;
|
||||
BNetworkInterface fNetworkInterface;
|
||||
|
||||
// IPv4 address configuration
|
||||
bool fIPv4Auto;
|
||||
BNetworkAddress fIPv4Addr;
|
||||
BNetworkAddress fIPv4Mask;
|
||||
BNetworkAddress fIPv4Gateway;
|
||||
|
||||
// IPv6 address configuration
|
||||
bool fIPv6Auto;
|
||||
BNetworkAddress fIPv6Addr;
|
||||
BNetworkAddress fIPv6Mask;
|
||||
BNetworkAddress fIPv6Gateway;
|
||||
// Stored network addresses and paramaters
|
||||
BoolMap fAutoConfigure;
|
||||
AddressMap fAddress;
|
||||
AddressMap fNetmask;
|
||||
AddressMap fGateway;
|
||||
|
||||
BString fName;
|
||||
BString fDomain;
|
||||
|
Loading…
Reference in New Issue
Block a user