Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#9770 closed bug (fixed)

if_nameindex() returns multiple elements with same if_index

Reported by: akira Owned by: phoudoin
Priority: normal Milestone: R1
Component: Kits/Network Kit Version: R1/alpha4.1
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

I found that if_nameindex() returns multile elements with same if_index.

~/n> uname -srvm
Haiku 1 hrevr1alpha4-44702 Nov 14 2012  BePC
~/n> cat tst.c
#include <stdlib.h>
#include <stdio.h>
#include <net/if.h>

int main(int argc, char *argv[])
{
  struct if_nameindex *ifs;
  int i;

  ifs = if_nameindex();
  if (ifs == NULL) { perror("if_nameindex"); exit(EXIT_FAILURE); }

  for (i = 0; ifs[i].if_index != 0 || ifs[i].if_name != NULL; i++) {
    printf("%d %s\n", ifs[i].if_index, ifs[i].if_name);
  }
  return EXIT_SUCCESS;
}
~/n> gcc tst.c -lnetwork
~/n> ./a.out
288 loop
288 /dev/net/rtl81xx/0

I think 288 is not a valid if_index.

Change History (6)

comment:1 by phoudoin, 7 years ago

Component: - GeneralNetwork & Internet/Stack
Owner: changed from nobody to phoudoin
Status: newassigned

I will look into, at it seems indeed a bug.

comment:2 by phoudoin, 7 years ago

Issue is that it's assumed that SIOCGIFCONF returns a list of ifreq of ifr_name + ifr_index flavor: http://cgit.haiku-os.org/haiku/tree/src/kits/network/interfaces.cpp#n110

While in fact it's ifr_name + ifr_addr flavor: http://cgit.haiku-os.org/haiku/tree/src/add-ons/kernel/network/stack/device_interfaces.cpp#n343

Will do a SIOCGIFINDEX request to retrieve that interface name's index. Stay tuned.

comment:3 by phoudoin, 7 years ago

Status: assignedin-progress

comment:4 by phoudoin, 7 years ago

Resolution: fixed
Status: in-progressclosed

Fixed in hrev45687.

Thanks for report and testcase.

comment:5 by phoudoin, 7 years ago

Component: Network & Internet/StackKits/Network Kit

comment:6 by phoudoin, 7 years ago

Oh, for the curious ones: 288 is 0x0120, which match "AF_INET" address family and a "32 bytes sockaddr lenght".

Note: See TracTickets for help on using tickets.