use UserBuffer in list_{device,domain}_interfaces
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20503 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5333836f71
commit
409b1fc051
@ -9,6 +9,7 @@
|
||||
|
||||
#include "domains.h"
|
||||
#include "interfaces.h"
|
||||
#include "utility.h"
|
||||
|
||||
#include <KernelExport.h>
|
||||
|
||||
@ -99,12 +100,11 @@ count_domain_interfaces()
|
||||
returned.
|
||||
*/
|
||||
status_t
|
||||
list_domain_interfaces(void *buffer, size_t *_bufferSize)
|
||||
list_domain_interfaces(void *_buffer, size_t *bufferSize)
|
||||
{
|
||||
BenaphoreLocker locker(sDomainLock);
|
||||
|
||||
uint8 *current = (uint8 *)buffer;
|
||||
const uint8 *bufferEnd = current + (*_bufferSize);
|
||||
UserBuffer buffer(_buffer, *bufferSize);
|
||||
net_domain_private *domain = NULL;
|
||||
|
||||
while (true) {
|
||||
@ -119,10 +119,6 @@ list_domain_interfaces(void *buffer, size_t *_bufferSize)
|
||||
if (interface == NULL)
|
||||
break;
|
||||
|
||||
size_t size = IF_NAMESIZE + (interface->address ? interface->address->sa_len : 2);
|
||||
if ((current + size) > bufferEnd)
|
||||
return ENOBUFS;
|
||||
|
||||
ifreq request;
|
||||
strlcpy(request.ifr_name, interface->name, IF_NAMESIZE);
|
||||
if (interface->address != NULL)
|
||||
@ -133,14 +129,13 @@ list_domain_interfaces(void *buffer, size_t *_bufferSize)
|
||||
request.ifr_addr.sa_family = AF_UNSPEC;
|
||||
}
|
||||
|
||||
if (user_memcpy(current, &request, size) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
current += size;
|
||||
if (buffer.Copy(&request, IF_NAMESIZE
|
||||
+ request.ifr_addr.sa_len) == NULL)
|
||||
return buffer.Status();
|
||||
}
|
||||
}
|
||||
|
||||
*_bufferSize = current - (uint8 *)buffer;
|
||||
*bufferSize = buffer.ConsumedAmount();
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "domains.h"
|
||||
#include "interfaces.h"
|
||||
#include "stack_private.h"
|
||||
#include "utility.h"
|
||||
|
||||
#include <net_device.h>
|
||||
|
||||
@ -258,12 +259,11 @@ count_device_interfaces()
|
||||
returned.
|
||||
*/
|
||||
status_t
|
||||
list_device_interfaces(void *buffer, size_t *_bufferSize)
|
||||
list_device_interfaces(void *_buffer, size_t *bufferSize)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
|
||||
uint8 *current = (uint8 *)buffer;
|
||||
const uint8 *bufferEnd = current + (*_bufferSize);
|
||||
UserBuffer buffer(_buffer, *bufferSize);
|
||||
net_device_interface *interface = NULL;
|
||||
|
||||
while (true) {
|
||||
@ -276,17 +276,12 @@ list_device_interfaces(void *buffer, size_t *_bufferSize)
|
||||
strlcpy(request.ifr_name, interface->name, IF_NAMESIZE);
|
||||
get_device_interface_address(interface, &request.ifr_addr);
|
||||
|
||||
size_t size = IF_NAMESIZE + request.ifr_addr.sa_len;
|
||||
if ((current + size) > bufferEnd)
|
||||
return ENOBUFS;
|
||||
|
||||
if (user_memcpy(current, &request, size) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
current += size;
|
||||
if (buffer.Copy(&request, IF_NAMESIZE
|
||||
+ request.ifr_addr.sa_len) == NULL)
|
||||
return buffer.Status();
|
||||
}
|
||||
|
||||
*_bufferSize = current - (uint8 *)buffer;;
|
||||
*bufferSize = buffer.ConsumedAmount();
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user