#991 closed bug (fixed)
ifconfig gets incorrect interface list from SIOCGIFCONF or uses it incorrectly
Reported by: | mmu_man | Owned by: | axeld |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Network & Internet/Stack | Version: | |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
There seems to be an off-by-1 error somewhere in either ifconfig or handling of SIOCGIFCONF by datalink, as the 3rd interface here is listed as "dev/net/tulip/0", without the first slash. (I have 2 cards in that box, the sis900 which fried from a storm, and a tulip for which I've put a tulip binary driver from zeta). Using the NIC name as argument to ifconfig works as expected though, the card does work, just getting the list is broken. I'll have a look at that today.
~>ifconfig loop Hardware Type: Local Loopback, Address: none
inet addr: 127.0.0.1, Mask: 255.0.0.0 MTU: 16384, Metric: 0, up loopback Receive: 0 packets, 0 errors, 0 bytes, 0 mcasts, 0 dropped Transmit: 0 packets, 0 errors, 0 bytes, 0 mcasts, 0 dropped Collisions: 0
/dev/net/sis900/0
Hardware Type: Ethernet, Address: 00:0b:6a:6f:9f:61 inet addr: MTU: 1500, Metric: 0, up broadcast Receive: 0 packets, 0 errors, 0 bytes, 0 mcasts, 0 dropped Transmit: 0 packets, 0 errors, 0 bytes, 0 mcasts, 0 dropped Collisions: 0
ifconfig: Interface "dev/net/tulip/0" does not exist.
Change History (4)
comment:1 by , 18 years ago
follow-up: 4 comment:2 by , 18 years ago
Ok, seems I found it: in src/add-ons/kernel/network/stack/domains.cpp:list_domain_interfaces(): ... size = IF_NAMESIZE + (interface->address ? interface->address->sa_len : 1); ... empty address request.ifr_addr.sa_len = 2; request.ifr_addr.sa_family = AF_UNSPEC;
When no address, it skips 1 byte but tells 2 to add the AF_UNSPEC...
Should be fixed in hrev19961.
I also wondered about ifreq being able to hold any addr (it only has a sockaddr), but the union with ifr_parameter seems to enforce that.
comment:4 by , 18 years ago
Replying to mmu_man:
Should be fixed in hrev19961.
Thanks!
I also wondered about ifreq being able to hold any addr (it only has a sockaddr), but the union with ifr_parameter seems to enforce that.
sockaddr is usually a bit more handy than sockaddr_storage, and since the storage size is determined by ifr_parameter anyway, it doesn't matter.
Here is what ifconfig gets from SIOCGIFCONF: [revol@Zeta /Data/haiku/trunk]# hd /haiku/home/ifconfig.dump 00000000 6c 6f 6f 70 00 c8 65 93 46 02 00 00 d4 37 7b 80 loop..e.F....7{. 00000010 52 74 02 80 01 00 00 00 45 00 00 00 20 90 b9 90 Rt......E... ... 00000020 20 01 00 00 7f 00 00 01 00 00 00 00 00 00 00 00 ............... 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000040 2f 64 65 76 2f 6e 65 74 2f 73 69 73 39 30 30 2f /dev/net/sis900/ 00000050 30 00 02 80 01 00 00 00 45 00 00 00 20 90 b9 90 0.......E... ... 00000060 02 2f 64 65 76 2f 6e 65 74 2f 74 75 6c 69 70 2f ./dev/net/tulip/ 00000070 30 00 00 02 80 01 00 00 00 45 00 00 00 20 90 b9 0........E... .. 00000080 90 20 01 00 00 c0 a8 00 02 00 00 00 00 00 00 00 . .............. 00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ ... 000000b0 00 00 00 00 00 00 00 00 48 a0 01 18 d0 83 01 18 ........H....... 000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ ... 00000160 00 00 00 00 00 00 00 00 f8 a0 01 18 d0 83 01 18 ................ 00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ ... 00000210 00 00 00 00 00 00 00 00 a8 a1 01 18 d0 83 01 18 ................ 00000220 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ ...
It seems The 2nd interface has a ifr_addr.sa_len = 2 while it only has the sa_len member whih is 8bit. So the error is on the datalink side.