Added profile and interface naming support.
Added some small doxygen comments. Minor changes. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6283 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
SubDir OBOS_TOP src add-ons kernel network ppp shared libppp ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libkernelppp ] ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libppp headers ] ;
|
||||
UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libkernelppp headers ] ;
|
||||
@@ -9,6 +7,7 @@ UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libkerne
|
||||
|
||||
|
||||
StaticLibrary ppp :
|
||||
driver_settings.c
|
||||
settings_tools.cpp
|
||||
|
||||
_libppputils.cpp
|
||||
@@ -16,3 +15,6 @@ StaticLibrary ppp :
|
||||
PPPInterfaceListener.cpp
|
||||
PPPManager.cpp
|
||||
;
|
||||
|
||||
SEARCH on [ FGristFiles driver_settings.c ] = [ FDirName $(OBOS_TOP) src kernel libroot os ] ;
|
||||
SEARCH on [ FGristFiles settings_tools.cpp ] = [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libkernelppp ] ;
|
||||
|
||||
@@ -5,11 +5,23 @@
|
||||
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*! \class PPPInterface
|
||||
\brief This class represents a PPP interface living in kernel space.
|
||||
|
||||
Use this class to control PPP interfaces and get the current interface settings.
|
||||
You can also use it to enable/disable report messages.
|
||||
*/
|
||||
|
||||
#include "PPPInterface.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include "_libppputils.h"
|
||||
|
||||
#include <Path.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
|
||||
|
||||
PPPInterface::PPPInterface(ppp_interface_id ID = PPP_UNDEFINED_INTERFACE_ID)
|
||||
{
|
||||
@@ -53,8 +65,10 @@ PPPInterface::SetTo(ppp_interface_id ID)
|
||||
fID = ID;
|
||||
|
||||
status_t error = Control(PPPC_GET_INTERFACE_INFO, &fInfo, sizeof(fInfo));
|
||||
if(error != B_OK)
|
||||
if(error != B_OK) {
|
||||
memset(&fInfo, 0, sizeof(fInfo));
|
||||
fID = PPP_UNDEFINED_INTERFACE_ID;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
@@ -83,6 +97,17 @@ PPPInterface::Control(uint32 op, void *data, size_t length) const
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PPPInterface::GetSettingsEntry(BEntry *entry) const
|
||||
{
|
||||
if(InitCheck() != B_OK || !entry || strlen(Name()) == 0)
|
||||
return B_ERROR;
|
||||
|
||||
BDirectory directory(PPP_INTERFACE_SETTINGS_PATH);
|
||||
return directory.FindEntry(Name(), entry, true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::GetInterfaceInfo(ppp_interface_info_t *info) const
|
||||
{
|
||||
@@ -95,6 +120,20 @@ PPPInterface::GetInterfaceInfo(ppp_interface_info_t *info) const
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::HasSettings(const driver_settings *settings) const
|
||||
{
|
||||
if(InitCheck() != B_OK || !settings)
|
||||
return false;
|
||||
|
||||
if(Control(PPPC_HAS_INTERFACE_SETTINGS, const_cast<driver_settings*>(settings),
|
||||
sizeof(driver_settings)) == B_OK)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::Up() const
|
||||
{
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "PPPManager.h"
|
||||
#include "PPPInterface.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cctype>
|
||||
#include <settings_tools.h>
|
||||
#include <unistd.h>
|
||||
#include "_libppputils.h"
|
||||
@@ -51,11 +54,14 @@ PPPManager::Control(uint32 op, void *data, size_t length) const
|
||||
return ioctl(fFD, NET_STACK_CONTROL_NET_MODULE, &args);
|
||||
}
|
||||
|
||||
|
||||
ppp_interface_id
|
||||
PPPManager::CreateInterface(const driver_settings *settings) const
|
||||
PPPManager::CreateInterface(const driver_settings *settings,
|
||||
const driver_settings *profile = NULL) const
|
||||
{
|
||||
ppp_interface_settings_info info;
|
||||
info.settings = settings;
|
||||
ppp_interface_description_info info;
|
||||
info.u.settings = settings;
|
||||
info.profile = profile;
|
||||
|
||||
if(Control(PPPC_CREATE_INTERFACE, &info, sizeof(info)) != B_OK)
|
||||
return PPP_UNDEFINED_INTERFACE_ID;
|
||||
@@ -64,6 +70,21 @@ PPPManager::CreateInterface(const driver_settings *settings) const
|
||||
}
|
||||
|
||||
|
||||
ppp_interface_id
|
||||
PPPManager::CreateInterfaceWithName(const char *name,
|
||||
const driver_settings *profile = NULL) const
|
||||
{
|
||||
ppp_interface_description_info info;
|
||||
info.u.name = name;
|
||||
info.profile = profile;
|
||||
|
||||
if(Control(PPPC_CREATE_INTERFACE_WITH_NAME, &info, sizeof(info)) != B_OK)
|
||||
return PPP_UNDEFINED_INTERFACE_ID;
|
||||
else
|
||||
return info.interface;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPManager::DeleteInterface(ppp_interface_id ID) const
|
||||
{
|
||||
@@ -125,33 +146,18 @@ PPPManager::GetInterfaces(ppp_interface_id *interfaces, int32 count,
|
||||
ppp_interface_id
|
||||
PPPManager::InterfaceWithSettings(const driver_settings *settings) const
|
||||
{
|
||||
int32 count;
|
||||
ppp_interface_id *interfaces = Interfaces(&count, PPP_ALL_INTERFACES);
|
||||
ppp_interface_description_info info;
|
||||
info.u.settings = settings;
|
||||
info.interface = PPP_UNDEFINED_INTERFACE_ID;
|
||||
|
||||
if(!interfaces)
|
||||
return PPP_UNDEFINED_INTERFACE_ID;
|
||||
Control(PPPC_FIND_INTERFACE_WITH_SETTINGS, &info, sizeof(info));
|
||||
|
||||
ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID;
|
||||
PPPInterface interface;
|
||||
ppp_interface_info_t info;
|
||||
|
||||
for(int32 index = 0; index < count; index++) {
|
||||
interface.SetTo(interfaces[index]);
|
||||
if(interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info)
|
||||
&& equal_driver_settings(settings, info.info.settings)) {
|
||||
id = interface.ID();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete interfaces;
|
||||
|
||||
return id;
|
||||
return info.interface;
|
||||
}
|
||||
|
||||
|
||||
ppp_interface_id
|
||||
PPPManager::InterfaceWithUnit(int32 if_unit)
|
||||
PPPManager::InterfaceWithUnit(int32 if_unit) const
|
||||
{
|
||||
int32 count;
|
||||
ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES);
|
||||
@@ -178,6 +184,44 @@ PPPManager::InterfaceWithUnit(int32 if_unit)
|
||||
}
|
||||
|
||||
|
||||
ppp_interface_id
|
||||
PPPManager::InterfaceWithName(const char *name) const
|
||||
{
|
||||
if(!name)
|
||||
return PPP_UNDEFINED_INTERFACE_ID;
|
||||
|
||||
int32 count;
|
||||
ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES);
|
||||
|
||||
if(!interfaces)
|
||||
return PPP_UNDEFINED_INTERFACE_ID;
|
||||
|
||||
ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID;
|
||||
PPPInterface interface;
|
||||
ppp_interface_info_t info;
|
||||
|
||||
for(int32 index = 0; index < count; index++) {
|
||||
interface.SetTo(interfaces[index]);
|
||||
if(interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info)
|
||||
&& strlen(info.info.name) > 0 && !strcasecmp(info.info.name, name)) {
|
||||
id = interface.ID();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete interfaces;
|
||||
|
||||
if(id != PPP_UNDEFINED_INTERFACE_ID)
|
||||
return id;
|
||||
else if(!strncmp(name, "ppp", 3) && strlen(name) > 3 && isdigit(name[3]))
|
||||
return InterfaceWithUnit(atoi(name + 3));
|
||||
else if(isdigit(name[0]))
|
||||
return atoi(name);
|
||||
else
|
||||
return PPP_UNDEFINED_INTERFACE_ID;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
PPPManager::CountInterfaces(ppp_interface_filter filter =
|
||||
PPP_REGISTERED_INTERFACES) const
|
||||
|
||||
@@ -6,6 +6,38 @@
|
||||
#include <OS.h>
|
||||
#include "_libppputils.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
// R5 only: strlcat is needed by driver_settings API
|
||||
/** Concatenates the source string to the destination, writes
|
||||
* as much as "maxLength" bytes to the dest string.
|
||||
* Always null terminates the string as long as maxLength is
|
||||
* larger than the dest string.
|
||||
* Returns the length of the string that it tried to create
|
||||
* to be able to easily detect string truncation.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char *dest, const char *source, size_t maxLength)
|
||||
{
|
||||
size_t destLength = strnlen(dest, maxLength);
|
||||
|
||||
// This returns the wrong size, but it's all we can do
|
||||
if (maxLength == destLength)
|
||||
return destLength + strlen(source);
|
||||
|
||||
dest += destLength;
|
||||
maxLength -= destLength;
|
||||
|
||||
size_t i = 0;
|
||||
for (; i < maxLength - 1 && source[i]; i++) {
|
||||
dest[i] = source[i];
|
||||
}
|
||||
|
||||
dest[i] = '\0';
|
||||
|
||||
return destLength + i + strlen(source + i);
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include <KPPPManager.h>
|
||||
|
||||
class BEntry;
|
||||
|
||||
|
||||
class PPPInterface {
|
||||
public:
|
||||
@@ -19,13 +21,20 @@ class PPPInterface {
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
//! Returns the name of the interface description file.
|
||||
const char *Name() const
|
||||
{ return fInfo.info.name; }
|
||||
|
||||
status_t SetTo(ppp_interface_id ID);
|
||||
//! Returns the unique id of this interface.
|
||||
ppp_interface_id ID() const
|
||||
{ return fID; }
|
||||
|
||||
status_t Control(uint32 op, void *data, size_t length) const;
|
||||
|
||||
status_t GetSettingsEntry(BEntry *entry) const;
|
||||
bool GetInterfaceInfo(ppp_interface_info_t *info) const;
|
||||
bool HasSettings(const driver_settings *settings) const;
|
||||
|
||||
bool Up() const;
|
||||
bool Down() const;
|
||||
@@ -34,8 +43,10 @@ class PPPInterface {
|
||||
int32 flags = PPP_NO_FLAGS) const;
|
||||
bool DisableReports(ppp_report_type type, thread_id thread) const;
|
||||
|
||||
//! Same as \c SetTo(copy.ID());
|
||||
PPPInterface& operator= (const PPPInterface& copy)
|
||||
{ SetTo(copy.ID()); return *this; }
|
||||
//! Same as \c SetTo(ID);
|
||||
PPPInterface& operator= (ppp_interface_id ID)
|
||||
{ SetTo(ID); return *this; }
|
||||
|
||||
|
||||
@@ -25,7 +25,10 @@ class PPPManager {
|
||||
|
||||
status_t Control(uint32 op, void *data, size_t length) const;
|
||||
|
||||
ppp_interface_id CreateInterface(const driver_settings *settings) const;
|
||||
ppp_interface_id CreateInterface(const driver_settings *settings,
|
||||
const driver_settings *profile = NULL) const;
|
||||
ppp_interface_id CreateInterfaceWithName(const char *name,
|
||||
const driver_settings *profile = NULL) const;
|
||||
bool DeleteInterface(ppp_interface_id ID) const;
|
||||
|
||||
ppp_interface_id *Interfaces(int32 *count,
|
||||
@@ -35,7 +38,8 @@ class PPPManager {
|
||||
ppp_interface_filter filter = PPP_REGISTERED_INTERFACES) const;
|
||||
// make sure interfaces has enough space for count items
|
||||
ppp_interface_id InterfaceWithSettings(const driver_settings *settings) const;
|
||||
ppp_interface_id InterfaceWithUnit(int32 if_unit);
|
||||
ppp_interface_id InterfaceWithUnit(int32 if_unit) const;
|
||||
ppp_interface_id InterfaceWithName(const char *name) const;
|
||||
int32 CountInterfaces(ppp_interface_filter filter =
|
||||
PPP_REGISTERED_INTERFACES) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user