adjust function names as per axel; begin using BNetworkInterface; correct a misnamed resource id

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40396 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexander von Gluck IV 2011-02-08 22:20:13 +00:00
parent e9aa1e0581
commit f9ac5fc8f5
4 changed files with 45 additions and 57 deletions

View File

@ -62,7 +62,7 @@ resource(2, "online") #'VICN' array {
$"C96F5B5B555BC96F5BC6CC020A0001001001178800040A02010000" $"C96F5B5B555BC96F5BC6CC020A0001001001178800040A02010000"
}; };
resource(3, "warning") #'VICN' array { resource(3, "pending") #'VICN' array {
$"6E6369660205000200060238DB5A38CCBABACCBA3ADB5A4B8BE14AD7C900FFF3" $"6E6369660205000200060238DB5A38CCBABACCBA3ADB5A4B8BE14AD7C900FFF3"
$"75FFFFA406010A034F4F555B5B4F020A0001001001178802040A01010000" $"75FFFFA406010A034F4F555B5B4F020A0001001001178802040A01010000"
}; };

View File

@ -95,8 +95,8 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
{ {
BListView* list = dynamic_cast<BListView*>(owner); BListView* list = dynamic_cast<BListView*>(owner);
BNetworkAddress addrIPv4 = fSettings->GetAddr(AF_INET); BNetworkAddress addrIPv4 = fSettings->IPAddr(AF_INET);
BNetworkAddress addrIPv6 = fSettings->GetAddr(AF_INET6); BNetworkAddress addrIPv6 = fSettings->IPAddr(AF_INET6);
if (!list) if (!list)
return; return;

View File

@ -35,7 +35,8 @@
NetworkSettings::NetworkSettings(const char* name) NetworkSettings::NetworkSettings(const char* name)
: :
fAuto(true), fIPv4Auto(true),
fIPv6Auto(true),
fDisabled(false), fDisabled(false),
fNameServers(5, true) 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 void
NetworkSettings::ReadConfiguration() NetworkSettings::ReadConfiguration()
{ {
ifreq request; BNetworkInterface fNetworkInterface(fName);
if (!_PrepareRequest(request)) int32 zeroAddrV4 = fNetworkInterface.FindFirstAddress(AF_INET);
return; int32 zeroAddrV6 = fNetworkInterface.FindFirstAddress(AF_INET6);
// Obtain IPv4 address. BNetworkInterfaceAddress netIntAddr4;
if (ioctl(fSocket4, SIOCGIFADDR, &request, sizeof(request)) < 0) BNetworkInterfaceAddress netIntAddr6;
return;
fIPv4Addr = *(sockaddr_in *)&request.ifr_addr;
// Obtain IPv4 netmask if (fNetworkInterface.GetAddressAt(zeroAddrV4, netIntAddr4) == B_OK) {
if (ioctl(fSocket4, SIOCGIFNETMASK, &request, sizeof(request)) < 0) fIPv4Addr = netIntAddr4.Address();
return; fIPv4Mask = netIntAddr4.Mask();
fIPv4Mask = *(sockaddr_in *)&request.ifr_mask; }
// Obtain IPv6 address. if (fNetworkInterface.GetAddressAt(zeroAddrV6, netIntAddr6) == B_OK) {
if (ioctl(fSocket6, SIOCGIFADDR, &request, sizeof(request)) < 0) fIPv6Addr = netIntAddr6.Address();
return; fIPv6Mask = netIntAddr6.Mask();
fIPv6Addr = *(sockaddr_in6 *)&request.ifr_addr; }
// Obtain IPv6 netmask
if (ioctl(fSocket6, SIOCGIFNETMASK, &request, sizeof(request)) < 0)
return;
fIPv6Mask = *(sockaddr_in6 *)&request.ifr_mask;
// Obtain gateway // Obtain gateway
ifconf config; ifconf config;
@ -143,12 +121,19 @@ NetworkSettings::ReadConfiguration()
+ sizeof(route_entry) + addressSize); + sizeof(route_entry) + addressSize);
} }
uint32 flags = 0; // Obtain selfconfiguration options
if (ioctl(fSocket4, SIOCGIFFLAGS, &request, sizeof(request)) == 0)
flags = request.ifr_flags;
fAuto = (flags & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0; // TODO : This needs to be determined by the protocol flags
fDisabled = (flags & IFF_UP) == 0; // 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 // Read wireless network from interfaces
@ -218,7 +203,7 @@ NetworkSettings::ReadConfiguration()
BNetworkAddress BNetworkAddress
NetworkSettings::GetAddr(int family) NetworkSettings::IPAddr(int family)
{ {
if (family == AF_INET6) if (family == AF_INET6)
return fIPv6Addr; return fIPv6Addr;
@ -228,7 +213,7 @@ NetworkSettings::GetAddr(int family)
const char* const char*
NetworkSettings::GetIP(int family) NetworkSettings::IP(int family)
{ {
if (family == AF_INET6) if (family == AF_INET6)
return fIPv6Addr.ToString(); return fIPv6Addr.ToString();
@ -238,7 +223,7 @@ NetworkSettings::GetIP(int family)
const char* const char*
NetworkSettings::GetNetmask(int family) NetworkSettings::Netmask(int family)
{ {
if (family == AF_INET6) if (family == AF_INET6)
return fIPv6Mask.ToString(); return fIPv6Mask.ToString();
@ -248,7 +233,7 @@ NetworkSettings::GetNetmask(int family)
int32 int32
NetworkSettings::GetPrefixLen(int family) NetworkSettings::PrefixLen(int family)
{ {
if (family == AF_INET6) if (family == AF_INET6)
return fIPv6Mask.PrefixLength(); return fIPv6Mask.PrefixLength();

View File

@ -5,6 +5,7 @@
* Authors: * Authors:
* Andre Alves Garzia, andre@andregarzia.com * Andre Alves Garzia, andre@andregarzia.com
* Vegard Wærp, vegarwa@online.no * Vegard Wærp, vegarwa@online.no
* Alexander von Gluck, kallisti5@unixzen.com
*/ */
#ifndef SETTINGS_H #ifndef SETTINGS_H
#define SETTINGS_H #define SETTINGS_H
@ -36,16 +37,16 @@ public:
// void SetWirelessNetwork(const char* name) // void SetWirelessNetwork(const char* name)
// { fWirelessNetwork.SetTo(name); } // { fWirelessNetwork.SetTo(name); }
BNetworkAddress GetAddr(int family); BNetworkAddress IPAddr(int family);
const char* GetIP(int family); const char* IP(int family);
const char* GetNetmask(int family); const char* Netmask(int family);
int32 GetPrefixLen(int family); int32 PrefixLen(int family);
const char* Gateway() { return fGateway.String(); } const char* Gateway() { return fGateway.String(); }
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 fAuto; } bool AutoConfigure() { return fIPv4Auto; }
bool IsDisabled() { return fDisabled; } bool IsDisabled() { return fDisabled; }
const BString& WirelessNetwork() { return fWirelessNetwork; } const BString& WirelessNetwork() { return fWirelessNetwork; }
@ -54,11 +55,14 @@ public:
void ReadConfiguration(); void ReadConfiguration();
private: private:
bool _PrepareRequest(struct ifreq& request);
int fSocket4; int fSocket4;
int fSocket6; int fSocket6;
BNetworkInterface fNetworkInterface;
bool fIPv4Auto;
bool fIPv6Auto;
BNetworkAddress fIPv4Addr; BNetworkAddress fIPv4Addr;
BNetworkAddress fIPv4Mask; BNetworkAddress fIPv4Mask;
BNetworkAddress fIPv6Addr; BNetworkAddress fIPv6Addr;
@ -67,7 +71,6 @@ private:
BString fGateway; BString fGateway;
BString fName; BString fName;
BString fDomain; BString fDomain;
bool fAuto;
bool fDisabled; bool fDisabled;
BObjectList<BString> fNameServers; BObjectList<BString> fNameServers;
BString fWirelessNetwork; BString fWirelessNetwork;