* You can now use SIOCGIFFLAGS on the AF_LINK level as well.

* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29231 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-02-16 11:05:25 +00:00
parent 1a905a762a
commit 86a0cf15e4
+50 -19
View File
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, [email protected]
*/
//! The net_protocol you talk to when using the AF_LINK protocol
//! The net_protocol one talks to when using the AF_LINK protocol
#include "datalink.h"
#include "domains.h"
@@ -43,19 +43,19 @@ public:
LinkProtocol(net_socket* socket);
~LinkProtocol();
status_t StartMonitoring(const char *);
status_t StartMonitoring(const char* deviceName);
status_t StopMonitoring();
private:
status_t _SocketStatus() const;
status_t _Unregister();
net_device_monitor fMonitor;
net_device_interface *fMonitoredDevice;
static status_t _MonitorData(net_device_monitor* monitor,
net_buffer* buffer);
static void _MonitorEvent(net_device_monitor* monitor, int32 event);
net_device_monitor fMonitor;
net_device_interface* fMonitoredDevice;
};
@@ -164,11 +164,26 @@ LinkProtocol::_MonitorEvent(net_device_monitor *monitor, int32 event)
// #pragma mark -
static bool
user_request_get_device_interface(void* value, struct ifreq& request,
net_device_interface*& interface)
{
if (user_memcpy(&request, value, IF_NAMESIZE) < B_OK)
return false;
interface = get_device_interface(request.ifr_name);
return true;
}
// #pragma mark -
net_protocol*
link_init_protocol(net_socket* socket)
{
LinkProtocol* protocol = new (std::nothrow) LinkProtocol(socket);
if (protocol && protocol->InitCheck() < B_OK) {
if (protocol != NULL && protocol->InitCheck() < B_OK) {
delete protocol;
return NULL;
}
@@ -230,12 +245,11 @@ link_control(net_protocol *_protocol, int level, int option, void *value,
case SIOCGIFINDEX:
{
// get index of interface
net_device_interface* interface;
struct ifreq request;
if (user_memcpy(&request, value, IF_NAMESIZE) < B_OK)
if (!user_request_get_device_interface(value, request, interface))
return B_BAD_ADDRESS;
net_device_interface *interface
= get_device_interface(request.ifr_name);
if (interface != NULL) {
request.ifr_index = interface->device->index;
put_device_interface(interface);
@@ -253,11 +267,11 @@ link_control(net_protocol *_protocol, int level, int option, void *value,
net_device_interface* interface
= get_device_interface(request.ifr_index);
if (interface != NULL) {
if (interface == NULL)
return ENODEV;
strlcpy(request.ifr_name, interface->device->name, IF_NAMESIZE);
put_device_interface(interface);
} else
return ENODEV;
return user_memcpy(value, &request, sizeof(struct ifreq));
}
@@ -289,22 +303,39 @@ link_control(net_protocol *_protocol, int level, int option, void *value,
case SIOCGIFADDR:
{
// get address of interface
net_device_interface* interface;
struct ifreq request;
if (user_memcpy(&request, value, IF_NAMESIZE) < B_OK)
if (!user_request_get_device_interface(value, request, interface))
return B_BAD_ADDRESS;
net_device_interface *interface
= get_device_interface(request.ifr_name);
if (interface != NULL) {
if (interface == NULL)
return ENODEV;
get_device_interface_address(interface, &request.ifr_addr);
put_device_interface(interface);
} else
return ENODEV;
return user_memcpy(&((struct ifreq*)value)->ifr_addr,
&request.ifr_addr, request.ifr_addr.sa_len);
}
case SIOCGIFFLAGS:
{
// get flags of interface
net_device_interface* interface;
struct ifreq request;
if (!user_request_get_device_interface(value, request, interface))
return B_BAD_ADDRESS;
if (interface == NULL)
return ENODEV;
request.ifr_flags = interface->device->flags;
put_device_interface(interface);
return user_memcpy(&((struct ifreq*)value)->ifr_flags,
&request.ifr_flags, sizeof(request.ifr_flags));
}
case SIOCSPACKETCAP:
{
struct ifreq request;