* removed unnecessary whitespaces, small style cleanups
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22365 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -40,7 +40,6 @@ Settings::Settings(const char *name)
|
|||||||
Settings::~Settings()
|
Settings::~Settings()
|
||||||
{
|
{
|
||||||
close(fSocket);
|
close(fSocket);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -48,9 +47,9 @@ Settings::_PrepareRequest(struct ifreq& request)
|
|||||||
{
|
{
|
||||||
//This function is used for talking direct to the stack.
|
//This function is used for talking direct to the stack.
|
||||||
//It´s used by _ShowConfiguration.
|
//It´s used by _ShowConfiguration.
|
||||||
|
|
||||||
const char* name = fName.String();
|
const char* name = fName.String();
|
||||||
|
|
||||||
if (strlen(name) > IF_NAMESIZE)
|
if (strlen(name) > IF_NAMESIZE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -62,82 +61,73 @@ Settings::_PrepareRequest(struct ifreq& request)
|
|||||||
void
|
void
|
||||||
Settings::ReadConfiguration()
|
Settings::ReadConfiguration()
|
||||||
{
|
{
|
||||||
|
|
||||||
ifreq request;
|
ifreq request;
|
||||||
if (!_PrepareRequest(request))
|
if (!_PrepareRequest(request))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BString text = "dummy";
|
BString text = "dummy";
|
||||||
char address[32];
|
char address[32];
|
||||||
sockaddr_in* inetAddress = NULL;
|
sockaddr_in* inetAddress = NULL;
|
||||||
|
|
||||||
// Obtain IP.
|
// Obtain IP.
|
||||||
if (ioctl(fSocket, SIOCGIFADDR, &request,
|
if (ioctl(fSocket, SIOCGIFADDR, &request, sizeof(request)) < 0)
|
||||||
sizeof(request)) < 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
inetAddress = (sockaddr_in*)&request.ifr_addr;
|
inetAddress = (sockaddr_in*)&request.ifr_addr;
|
||||||
if (inet_ntop(AF_INET, &inetAddress->sin_addr, address,
|
if (inet_ntop(AF_INET, &inetAddress->sin_addr, address,
|
||||||
sizeof(address)) == NULL) {
|
sizeof(address)) == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fIP = address;
|
|
||||||
|
|
||||||
|
fIP = address;
|
||||||
|
|
||||||
// Obtain netmask.
|
// Obtain netmask.
|
||||||
if (ioctl(fSocket, SIOCGIFNETMASK, &request,
|
if (ioctl(fSocket, SIOCGIFNETMASK, &request,
|
||||||
sizeof(request)) < 0) {
|
sizeof(request)) < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
inetAddress = (sockaddr_in*)&request.ifr_mask;
|
inetAddress = (sockaddr_in*)&request.ifr_mask;
|
||||||
if (inet_ntop(AF_INET, &inetAddress->sin_addr, address,
|
if (inet_ntop(AF_INET, &inetAddress->sin_addr, address,
|
||||||
sizeof(address)) == NULL) {
|
sizeof(address)) == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fNetmask = address;
|
fNetmask = address;
|
||||||
|
|
||||||
// Obtain gateway
|
// Obtain gateway
|
||||||
|
|
||||||
char* gwAddress;
|
|
||||||
ifconf config;
|
ifconf config;
|
||||||
config.ifc_len = sizeof(config.ifc_value);
|
config.ifc_len = sizeof(config.ifc_value);
|
||||||
if (ioctl(fSocket, SIOCGRTSIZE, &config, sizeof(struct ifconf)) < 0)
|
if (ioctl(fSocket, SIOCGRTSIZE, &config, sizeof(struct ifconf)) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint32 size = (uint32)config.ifc_value;
|
uint32 size = (uint32)config.ifc_value;
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
void *buffer = malloc(size);
|
void *buffer = malloc(size);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MemoryDeleter bufferDeleter(buffer);
|
MemoryDeleter bufferDeleter(buffer);
|
||||||
config.ifc_len = size;
|
config.ifc_len = size;
|
||||||
config.ifc_buf = buffer;
|
config.ifc_buf = buffer;
|
||||||
|
|
||||||
if (ioctl(fSocket, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0)
|
if (ioctl(fSocket, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ifreq *interface = (ifreq *)buffer;
|
ifreq *interface = (ifreq *)buffer;
|
||||||
ifreq *end = (ifreq *)((uint8 *)buffer + size);
|
ifreq *end = (ifreq *)((uint8 *)buffer + size);
|
||||||
|
|
||||||
|
|
||||||
while (interface < end) {
|
while (interface < end) {
|
||||||
route_entry& route = interface->ifr_route;
|
route_entry& route = interface->ifr_route;
|
||||||
|
|
||||||
|
|
||||||
if (route.flags & RTF_GATEWAY) {
|
if (route.flags & RTF_GATEWAY) {
|
||||||
inetAddress = (sockaddr_in *)route.gateway;
|
inetAddress = (sockaddr_in*)route.gateway;
|
||||||
|
fGateway = inet_ntoa(inetAddress->sin_addr);
|
||||||
|
|
||||||
gwAddress = inet_ntoa(inetAddress->sin_addr);
|
|
||||||
fGateway = gwAddress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 addressSize = 0;
|
int32 addressSize = 0;
|
||||||
if (route.destination != NULL)
|
if (route.destination != NULL)
|
||||||
addressSize += route.destination->sa_len;
|
addressSize += route.destination->sa_len;
|
||||||
@@ -145,24 +135,17 @@ Settings::ReadConfiguration()
|
|||||||
addressSize += route.mask->sa_len;
|
addressSize += route.mask->sa_len;
|
||||||
if (route.gateway != NULL)
|
if (route.gateway != NULL)
|
||||||
addressSize += route.gateway->sa_len;
|
addressSize += route.gateway->sa_len;
|
||||||
|
|
||||||
interface = (ifreq *)((addr_t)interface +
|
interface = (ifreq *)((addr_t)interface +
|
||||||
IF_NAMESIZE + sizeof(route_entry) + addressSize);
|
IF_NAMESIZE + sizeof(route_entry) + addressSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferDeleter.Detach();
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
uint32 flags = 0;
|
uint32 flags = 0;
|
||||||
if (ioctl(fSocket, SIOCGIFFLAGS, &request, sizeof(struct ifreq)) == 0)
|
if (ioctl(fSocket, SIOCGIFFLAGS, &request, sizeof(struct ifreq)) == 0)
|
||||||
flags = request.ifr_flags;
|
flags = request.ifr_flags;
|
||||||
|
|
||||||
if ((flags & IFF_AUTO_CONFIGURED) != 0)
|
fAuto = flags & IFF_AUTO_CONFIGURED;
|
||||||
fAuto = true;
|
|
||||||
else
|
|
||||||
fAuto = false;
|
|
||||||
|
|
||||||
// read resolv.conf for the dns.
|
// read resolv.conf for the dns.
|
||||||
fNameservers.MakeEmpty();
|
fNameservers.MakeEmpty();
|
||||||
|
|
||||||
@@ -171,7 +154,7 @@ Settings::ReadConfiguration()
|
|||||||
(line[sizeof(name) - 1] == ' ' || \
|
(line[sizeof(name) - 1] == ' ' || \
|
||||||
line[sizeof(name) - 1] == '\t'))
|
line[sizeof(name) - 1] == '\t'))
|
||||||
|
|
||||||
|
|
||||||
register FILE *fp = fopen("/etc/resolv.conf", "r");
|
register FILE *fp = fopen("/etc/resolv.conf", "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
fprintf(stderr, "failed to open '/etc/resolv.conf' to "
|
fprintf(stderr, "failed to open '/etc/resolv.conf' to "
|
||||||
@@ -184,7 +167,7 @@ Settings::ReadConfiguration()
|
|||||||
register char *cp; //, **pp;
|
register char *cp; //, **pp;
|
||||||
// register int n;
|
// register int n;
|
||||||
int MAXNS = 2;
|
int MAXNS = 2;
|
||||||
|
|
||||||
// read the config file
|
// read the config file
|
||||||
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||||
// skip comments
|
// skip comments
|
||||||
|
|||||||
Reference in New Issue
Block a user