diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesIcons.rdef b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesIcons.rdef index 574271a2be..f8d799dbfe 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesIcons.rdef +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesIcons.rdef @@ -62,7 +62,7 @@ resource(2, "online") #'VICN' array { $"C96F5B5B555BC96F5BC6CC020A0001001001178800040A02010000" }; -resource(3, "warning") #'VICN' array { +resource(3, "pending") #'VICN' array { $"6E6369660205000200060238DB5A38CCBABACCBA3ADB5A4B8BE14AD7C900FFF3" $"75FFFFA406010A034F4F555B5B4F020A0001001001178802040A01010000" }; diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.cpp index cacb97758b..530e61c936 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.cpp @@ -95,8 +95,8 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete) { BListView* list = dynamic_cast(owner); - BNetworkAddress addrIPv4 = fSettings->GetAddr(AF_INET); - BNetworkAddress addrIPv6 = fSettings->GetAddr(AF_INET6); + BNetworkAddress addrIPv4 = fSettings->IPAddr(AF_INET); + BNetworkAddress addrIPv6 = fSettings->IPAddr(AF_INET6); if (!list) return; diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp index 9d64f0d4e3..82e9301289 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp @@ -35,7 +35,8 @@ NetworkSettings::NetworkSettings(const char* name) : - fAuto(true), + fIPv4Auto(true), + fIPv6Auto(true), fDisabled(false), fNameServers(5, true) { @@ -55,49 +56,26 @@ NetworkSettings::~NetworkSettings() } -bool -NetworkSettings::_PrepareRequest(struct ifreq& request) -{ - // This function is used for talking direct to the stack. - // It´s used by _ShowConfiguration. - - const char* name = fName.String(); - - if (strlen(name) > IF_NAMESIZE) - return false; - - strcpy(request.ifr_name, name); - return true; -} - - void NetworkSettings::ReadConfiguration() { - ifreq request; + BNetworkInterface fNetworkInterface(fName); - if (!_PrepareRequest(request)) - return; + int32 zeroAddrV4 = fNetworkInterface.FindFirstAddress(AF_INET); + int32 zeroAddrV6 = fNetworkInterface.FindFirstAddress(AF_INET6); - // Obtain IPv4 address. - if (ioctl(fSocket4, SIOCGIFADDR, &request, sizeof(request)) < 0) - return; - fIPv4Addr = *(sockaddr_in *)&request.ifr_addr; + BNetworkInterfaceAddress netIntAddr4; + BNetworkInterfaceAddress netIntAddr6; - // Obtain IPv4 netmask - if (ioctl(fSocket4, SIOCGIFNETMASK, &request, sizeof(request)) < 0) - return; - fIPv4Mask = *(sockaddr_in *)&request.ifr_mask; + if (fNetworkInterface.GetAddressAt(zeroAddrV4, netIntAddr4) == B_OK) { + fIPv4Addr = netIntAddr4.Address(); + fIPv4Mask = netIntAddr4.Mask(); + } - // Obtain IPv6 address. - if (ioctl(fSocket6, SIOCGIFADDR, &request, sizeof(request)) < 0) - return; - fIPv6Addr = *(sockaddr_in6 *)&request.ifr_addr; - - // Obtain IPv6 netmask - if (ioctl(fSocket6, SIOCGIFNETMASK, &request, sizeof(request)) < 0) - return; - fIPv6Mask = *(sockaddr_in6 *)&request.ifr_mask; + if (fNetworkInterface.GetAddressAt(zeroAddrV6, netIntAddr6) == B_OK) { + fIPv6Addr = netIntAddr6.Address(); + fIPv6Mask = netIntAddr6.Mask(); + } // Obtain gateway ifconf config; @@ -143,12 +121,19 @@ NetworkSettings::ReadConfiguration() + sizeof(route_entry) + addressSize); } - uint32 flags = 0; - if (ioctl(fSocket4, SIOCGIFFLAGS, &request, sizeof(request)) == 0) - flags = request.ifr_flags; + // Obtain selfconfiguration options - fAuto = (flags & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0; - fDisabled = (flags & IFF_UP) == 0; + // 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() + & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0; + + fIPv6Auto = (fNetworkInterface.Flags() + & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0; + + fDisabled = (fNetworkInterface.Flags() & IFF_UP) == 0; // Read wireless network from interfaces @@ -218,7 +203,7 @@ NetworkSettings::ReadConfiguration() BNetworkAddress -NetworkSettings::GetAddr(int family) +NetworkSettings::IPAddr(int family) { if (family == AF_INET6) return fIPv6Addr; @@ -228,7 +213,7 @@ NetworkSettings::GetAddr(int family) const char* -NetworkSettings::GetIP(int family) +NetworkSettings::IP(int family) { if (family == AF_INET6) return fIPv6Addr.ToString(); @@ -238,7 +223,7 @@ NetworkSettings::GetIP(int family) const char* -NetworkSettings::GetNetmask(int family) +NetworkSettings::Netmask(int family) { if (family == AF_INET6) return fIPv6Mask.ToString(); @@ -248,7 +233,7 @@ NetworkSettings::GetNetmask(int family) int32 -NetworkSettings::GetPrefixLen(int family) +NetworkSettings::PrefixLen(int family) { if (family == AF_INET6) return fIPv6Mask.PrefixLength(); diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h index d8d614dd9b..b083c9bdd5 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h @@ -5,6 +5,7 @@ * Authors: * Andre Alves Garzia, andre@andregarzia.com * Vegard Wærp, vegarwa@online.no + * Alexander von Gluck, kallisti5@unixzen.com */ #ifndef SETTINGS_H #define SETTINGS_H @@ -36,16 +37,16 @@ public: // void SetWirelessNetwork(const char* name) // { fWirelessNetwork.SetTo(name); } - BNetworkAddress GetAddr(int family); + BNetworkAddress IPAddr(int family); - const char* GetIP(int family); - const char* GetNetmask(int family); - int32 GetPrefixLen(int family); + const char* IP(int family); + const char* Netmask(int family); + int32 PrefixLen(int family); const char* Gateway() { return fGateway.String(); } const char* Name() { return fName.String(); } const char* Domain() { return fDomain.String(); } - bool AutoConfigure() { return fAuto; } + bool AutoConfigure() { return fIPv4Auto; } bool IsDisabled() { return fDisabled; } const BString& WirelessNetwork() { return fWirelessNetwork; } @@ -54,11 +55,14 @@ public: void ReadConfiguration(); private: - bool _PrepareRequest(struct ifreq& request); - int fSocket4; int fSocket6; + BNetworkInterface fNetworkInterface; + + bool fIPv4Auto; + bool fIPv6Auto; + BNetworkAddress fIPv4Addr; BNetworkAddress fIPv4Mask; BNetworkAddress fIPv6Addr; @@ -67,7 +71,6 @@ private: BString fGateway; BString fName; BString fDomain; - bool fAuto; bool fDisabled; BObjectList fNameServers; BString fWirelessNetwork;