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"
};
resource(3, "warning") #'VICN' array {
resource(3, "pending") #'VICN' array {
$"6E6369660205000200060238DB5A38CCBABACCBA3ADB5A4B8BE14AD7C900FFF3"
$"75FFFFA406010A034F4F555B5B4F020A0001001001178802040A01010000"
};

View File

@ -95,8 +95,8 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
{
BListView* list = dynamic_cast<BListView*>(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;

View File

@ -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();

View File

@ -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<BString> fNameServers;
BString fWirelessNetwork;