Skip to content

Commit

Permalink
BNetworkAddressResolver: fix getting address of given family
Browse files Browse the repository at this point in the history
* Fix wrong nesting of loops which are supposed to skip the first
  (*cookie) number of elements and those with the wrong address
  family

* With a start value of first = 0 (the usual case), the old code
  would always just return the first element of the addrinfo list, no
  matter which address family was actually requested
  • Loading branch information
juafromspace committed Jun 30, 2015
1 parent a8438bc commit 0fc8084
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/kits/network/libnetapi/NetworkAddressResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,11 @@ BNetworkAddressResolver::GetNextAddress(int family, uint32* cookie,

addrinfo* info = fInfo;
int32 first = *cookie;
for (int32 index = 0; index < first && info != NULL; index++) {
while (info != NULL && info->ai_family != family)
info = info->ai_next;
}
for (int32 index = 0; index < first && info != NULL; index++)
info = info->ai_next;

while (info != NULL && info->ai_family != family)
info = info->ai_next;

if (info == NULL)
return B_BAD_VALUE;
Expand Down

0 comments on commit 0fc8084

Please sign in to comment.