* 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:
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Axel Dörfler, [email protected]
|
* 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 "datalink.h"
|
||||||
#include "domains.h"
|
#include "domains.h"
|
||||||
@@ -43,19 +43,19 @@ public:
|
|||||||
LinkProtocol(net_socket* socket);
|
LinkProtocol(net_socket* socket);
|
||||||
~LinkProtocol();
|
~LinkProtocol();
|
||||||
|
|
||||||
status_t StartMonitoring(const char *);
|
status_t StartMonitoring(const char* deviceName);
|
||||||
status_t StopMonitoring();
|
status_t StopMonitoring();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _SocketStatus() const;
|
status_t _SocketStatus() const;
|
||||||
status_t _Unregister();
|
status_t _Unregister();
|
||||||
|
|
||||||
net_device_monitor fMonitor;
|
|
||||||
net_device_interface *fMonitoredDevice;
|
|
||||||
|
|
||||||
static status_t _MonitorData(net_device_monitor* monitor,
|
static status_t _MonitorData(net_device_monitor* monitor,
|
||||||
net_buffer* buffer);
|
net_buffer* buffer);
|
||||||
static void _MonitorEvent(net_device_monitor* monitor, int32 event);
|
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 -
|
// #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*
|
net_protocol*
|
||||||
link_init_protocol(net_socket* socket)
|
link_init_protocol(net_socket* socket)
|
||||||
{
|
{
|
||||||
LinkProtocol* protocol = new (std::nothrow) LinkProtocol(socket);
|
LinkProtocol* protocol = new (std::nothrow) LinkProtocol(socket);
|
||||||
if (protocol && protocol->InitCheck() < B_OK) {
|
if (protocol != NULL && protocol->InitCheck() < B_OK) {
|
||||||
delete protocol;
|
delete protocol;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -230,12 +245,11 @@ link_control(net_protocol *_protocol, int level, int option, void *value,
|
|||||||
case SIOCGIFINDEX:
|
case SIOCGIFINDEX:
|
||||||
{
|
{
|
||||||
// get index of interface
|
// get index of interface
|
||||||
|
net_device_interface* interface;
|
||||||
struct ifreq request;
|
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;
|
return B_BAD_ADDRESS;
|
||||||
|
|
||||||
net_device_interface *interface
|
|
||||||
= get_device_interface(request.ifr_name);
|
|
||||||
if (interface != NULL) {
|
if (interface != NULL) {
|
||||||
request.ifr_index = interface->device->index;
|
request.ifr_index = interface->device->index;
|
||||||
put_device_interface(interface);
|
put_device_interface(interface);
|
||||||
@@ -253,11 +267,11 @@ link_control(net_protocol *_protocol, int level, int option, void *value,
|
|||||||
|
|
||||||
net_device_interface* interface
|
net_device_interface* interface
|
||||||
= get_device_interface(request.ifr_index);
|
= get_device_interface(request.ifr_index);
|
||||||
if (interface != NULL) {
|
if (interface == NULL)
|
||||||
|
return ENODEV;
|
||||||
|
|
||||||
strlcpy(request.ifr_name, interface->device->name, IF_NAMESIZE);
|
strlcpy(request.ifr_name, interface->device->name, IF_NAMESIZE);
|
||||||
put_device_interface(interface);
|
put_device_interface(interface);
|
||||||
} else
|
|
||||||
return ENODEV;
|
|
||||||
|
|
||||||
return user_memcpy(value, &request, sizeof(struct ifreq));
|
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:
|
case SIOCGIFADDR:
|
||||||
{
|
{
|
||||||
// get address of interface
|
// get address of interface
|
||||||
|
net_device_interface* interface;
|
||||||
struct ifreq request;
|
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;
|
return B_BAD_ADDRESS;
|
||||||
|
|
||||||
net_device_interface *interface
|
if (interface == NULL)
|
||||||
= get_device_interface(request.ifr_name);
|
return ENODEV;
|
||||||
if (interface != NULL) {
|
|
||||||
get_device_interface_address(interface, &request.ifr_addr);
|
get_device_interface_address(interface, &request.ifr_addr);
|
||||||
put_device_interface(interface);
|
put_device_interface(interface);
|
||||||
} else
|
|
||||||
return ENODEV;
|
|
||||||
|
|
||||||
return user_memcpy(&((struct ifreq*)value)->ifr_addr,
|
return user_memcpy(&((struct ifreq*)value)->ifr_addr,
|
||||||
&request.ifr_addr, request.ifr_addr.sa_len);
|
&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:
|
case SIOCSPACKETCAP:
|
||||||
{
|
{
|
||||||
struct ifreq request;
|
struct ifreq request;
|
||||||
|
|||||||
Reference in New Issue
Block a user