diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.cpp index 0603218616..6ed6cbb6d8 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.cpp @@ -15,8 +15,8 @@ #include -InterfaceAddressView::InterfaceAddressView(BRect frame, const char* name, - int family, NetworkSettings* settings) +InterfaceAddressView::InterfaceAddressView(BRect frame, int family, + NetworkSettings* settings) : BGroupView(B_VERTICAL), fSettings(settings), diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.h index 21c43d73dd..5fbf274659 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.h @@ -28,8 +28,7 @@ enum { class InterfaceAddressView : public BGroupView { public: InterfaceAddressView(BRect frame, - const char* name, int family, - NetworkSettings* settings); + int family, NetworkSettings* settings); virtual ~InterfaceAddressView(); virtual void MessageReceived(BMessage* message); virtual void AttachedToWindow(); diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp index b0e66c3e68..8098100a89 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp @@ -60,16 +60,25 @@ InterfaceWindow::~InterfaceWindow() void InterfaceWindow::MessageReceived(BMessage* message) { + int* supportedFamilies = fNetworkSettings->ProtocolVersions(); + unsigned int index; + switch (message->what) { case MSG_IP_REVERT: - // RFC : we could check fTabView for Selection - // here and only revert the selected tab. - fIPv4TabView->RevertFields(); - fIPv6TabView->RevertFields(); + for (index = 0; index < sizeof(supportedFamilies); index++) + { + int protocol = supportedFamilies[index]; + if (protocol > 0) + fTabIPView[protocol]->RevertFields(); + } break; case MSG_IP_SAVE: - fIPv4TabView->SaveFields(); - fIPv6TabView->SaveFields(); + for (index = 0; index < sizeof(supportedFamilies); index++) + { + int protocol = supportedFamilies[index]; + if (protocol > 0) + fTabIPView[protocol]->SaveFields(); + } this->Quit(); break; default: @@ -83,19 +92,22 @@ status_t InterfaceWindow::_PopulateTabs() { BRect frame = fTabView->Bounds(); - fIPv4TabView = new InterfaceAddressView(frame, "net_settings_ipv4", - AF_INET, fNetworkSettings); - fIPv6TabView = new InterfaceAddressView(frame, "net_settings_ipv6", - AF_INET6, fNetworkSettings); + int* supportedFamilies = fNetworkSettings->ProtocolVersions(); - BTab* tab4 = new BTab; - BTab* tab6 = new BTab; - - fTabView->AddTab(fIPv4TabView, tab4); - tab4->SetLabel("IPv4"); - - fTabView->AddTab(fIPv6TabView, tab6); - tab6->SetLabel("IPv6"); + unsigned int index; + for (index = 0; index < sizeof(supportedFamilies); index++) + { + int protocol = supportedFamilies[index]; + if (protocol > 0) + { + fTabIPView[protocol] = new InterfaceAddressView(frame, + protocol, fNetworkSettings); + BTab* tab = new BTab; + fTabView->AddTab(fTabIPView[protocol], tab); + tab->SetLabel((protocol == AF_INET) ? "IPv4" : "IPv6"); + // TODO : find a better way + } + } return B_OK; } diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.h index 9f19555d6b..0bc8b984ef 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.h @@ -19,6 +19,8 @@ #include #include +#include + enum { MSG_IP_SAVE = 'ipap', @@ -26,6 +28,9 @@ enum { }; +typedef std::map IPViewMap; + + class InterfaceWindow : public BWindow { public: InterfaceWindow(NetworkSettings* settings); @@ -41,8 +46,7 @@ private: BButton* fRevertButton; BTabView* fTabView; - InterfaceAddressView* fIPv4TabView; - InterfaceAddressView* fIPv6TabView; + IPViewMap fTabIPView; }; diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp index eb53d09e64..b233db144a 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp @@ -38,19 +38,35 @@ NetworkSettings::NetworkSettings(const char* name) fDisabled(false), fNameServers(5, true) { - fSocket[AF_INET] = socket(AF_INET, SOCK_DGRAM, 0); - fSocket[AF_INET6] = socket(AF_INET6, SOCK_DGRAM, 0); + // TODO : Detect supported IP protocol versions + memset(fProtocolVersions, 0, sizeof(fProtocolVersions)); + fProtocolVersions[0] = AF_INET; + fProtocolVersions[1] = AF_INET6; + + unsigned int index; + for (index = 0; index < sizeof(fProtocolVersions); index++) + { + int protocol = fProtocolVersions[index]; + if (protocol > 0) + fSocket[protocol] = socket(protocol, SOCK_DGRAM, 0); + } fName = name; + ReadConfiguration(); } NetworkSettings::~NetworkSettings() { - close(fSocket[AF_INET]); - close(fSocket[AF_INET6]); + unsigned int index; + for (index = 0; index < sizeof(fProtocolVersions); index++) + { + int protocol = fProtocolVersions[index]; + if (protocol > 0) + close(fSocket[protocol]); + } } @@ -62,23 +78,22 @@ NetworkSettings::ReadConfiguration() { BNetworkInterface fNetworkInterface(fName); - // Obtain possible IPv4 and IPv6 addresses - int32 zeroAddrV4 = fNetworkInterface.FindFirstAddress(AF_INET); - int32 zeroAddrV6 = fNetworkInterface.FindFirstAddress(AF_INET6); + unsigned int index; + for (index = 0; index < sizeof(fProtocolVersions); index++) + { + int protocol = fProtocolVersions[index]; - BNetworkInterfaceAddress netIntAddr4; - BNetworkInterfaceAddress netIntAddr6; - - if (zeroAddrV4 >= 0) { - fNetworkInterface.GetAddressAt(zeroAddrV4, netIntAddr4); - fAddress[AF_INET] = netIntAddr4.Address(); - fNetmask[AF_INET] = netIntAddr4.Mask(); - } - - if (zeroAddrV6 >= 0) { - fNetworkInterface.GetAddressAt(zeroAddrV6, netIntAddr6); - fAddress[AF_INET6] = netIntAddr6.Address(); - fNetmask[AF_INET6] = netIntAddr6.Mask(); + if (protocol > 0) { + int32 zeroAddr = fNetworkInterface.FindFirstAddress(protocol); + if (zeroAddr >= 0) { + fNetworkInterface.GetAddressAt(zeroAddr, + fInterfaceAddressMap[protocol]); + fAddress[protocol] + = fInterfaceAddressMap[protocol].Address(); + fNetmask[protocol] + = fInterfaceAddressMap[protocol].Mask(); + } + } } // Obtain gateway @@ -206,3 +221,10 @@ NetworkSettings::ReadConfiguration() } +void +NetworkSettings::WriteConfiguration() +{ + + +} + diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h index c1e5dc8439..45418b572d 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h @@ -20,6 +20,7 @@ typedef std::map AddressMap; +typedef std::map InterfaceAddressMap; typedef std::map BoolMap; typedef std::map SocketMap; @@ -29,6 +30,9 @@ public: NetworkSettings(const char* name); virtual ~NetworkSettings(); + int* ProtocolVersions() + { return fProtocolVersions; } + void SetIP(int family, const char* ip) { fAddress[family].SetTo(ip); } void SetNetmask(int family, const char* mask) @@ -69,10 +73,15 @@ public: BObjectList& NameServers() { return fNameServers; } void ReadConfiguration(); + void WriteConfiguration(); private: SocketMap fSocket; BNetworkInterface fNetworkInterface; + InterfaceAddressMap fInterfaceAddressMap; + + int fProtocolVersions[3]; + // OS Supported protocol versions // Stored network addresses and paramaters BoolMap fAutoConfigure;