* Make sure the SIOCGIFCONF never returns an address with an address length
smaller than sizeof(sockaddr). This fixes a compatibility issue with other platforms - portable software often assumes that the amount of bytes to add to an ifreq structure is the larger amount between sizeof(ifreq), and basically what the _SIZEOF_ADDR_IFREQ() macro returns, instead of always relying on that macro. * Renamed UserBuffer::Copy() to Push, ConsumedAmount() to BytesConsumed(), added Pad() method. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37927 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1385,27 +1385,38 @@ list_interfaces(int family, void* _buffer, size_t* bufferSize)
|
||||
|
||||
InterfaceList::Iterator iterator = sInterfaces.GetIterator();
|
||||
while (Interface* interface = iterator.Next()) {
|
||||
ifreq request;
|
||||
strlcpy(request.ifr_name, interface->name, IF_NAMESIZE);
|
||||
// Copy name
|
||||
buffer.Push(interface->name, IF_NAMESIZE);
|
||||
|
||||
// Copy address
|
||||
InterfaceAddress* address = interface->FirstForFamily(family);
|
||||
sockaddr_storage storage;
|
||||
|
||||
if (address != NULL && address->local != NULL) {
|
||||
// copy actual address
|
||||
memcpy(&request.ifr_addr, address->local, address->local->sa_len);
|
||||
// Actual address
|
||||
memcpy(&storage, address->local, address->local->sa_len);
|
||||
} else {
|
||||
// empty address
|
||||
request.ifr_addr.sa_len = 2;
|
||||
request.ifr_addr.sa_family = AF_UNSPEC;
|
||||
// Empty address
|
||||
storage.ss_len = 2;
|
||||
storage.ss_family = AF_UNSPEC;
|
||||
}
|
||||
|
||||
if (storage.ss_len < sizeof(sockaddr)) {
|
||||
// Make sure at least sizeof(sockaddr) bytes are written for
|
||||
// compatibility with other platforms
|
||||
memset((uint8*)&storage + storage.ss_len, 0,
|
||||
sizeof(sockaddr) - storage.ss_len);
|
||||
storage.ss_len = sizeof(sockaddr);
|
||||
}
|
||||
|
||||
if (address != NULL)
|
||||
address->ReleaseReference();
|
||||
|
||||
if (buffer.Copy(&request, IF_NAMESIZE
|
||||
+ request.ifr_addr.sa_len) == NULL)
|
||||
if (buffer.Push(&storage, storage.ss_len) == NULL)
|
||||
return buffer.Status();
|
||||
}
|
||||
|
||||
*bufferSize = buffer.ConsumedAmount();
|
||||
*bufferSize = buffer.BytesConsumed();
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user