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