Porting to OS/2: Case #23 if_nameindex() family
if_nameindex() is used to retrive all network interface names and indexes. if_freenameindex() is used to free internal storages allocated by if_nameindex(). And there is a family which maps a network inteface name to its corresponding index, and vice versa. They are if_nametoindex() and if_indextoname().
OS/2 has no them. Fortunately, however, OS/2 provides socket calls to implement them.
First, you can use os2_ioctl( SIOSTATIF42 ). This call provides interface statistics for all interfaces up to 42 via struct ifmib which includes a index and a description of a network interface.
A index is 0-based. However, if_nameindex() family accepts 0-index as the last entry of network interfaces or an invalid index. So it's needed to increase the index by 1.
A description is a long description not a short description. For example, Ethernet-Csmacd not lan0. So you should generate a canonical name from a description and an index. For details, see the following ODIN source.
Second, you can use ioctl( SIOCGIFCONF ). This call provides network interface configurations via struct ifconf. Since TCP/IP v4.21, it provides AF_LINK type address which includes an index which is from 1 and a name such as lan0 for a network interface. This call is equivalent to if_nameindex() directly. You can get sources implementing if_nameindex() family with ioctl( SIOCGIFCONF ) here.
If you want to support 16 bits TCP/IP stack, that is TCP/IP prior to v4.21, then use os2_ioctl( SIOSTATIF42 ). Otherwise use ioctl( SIOCGIFCONF ).
OS/2 has no them. Fortunately, however, OS/2 provides socket calls to implement them.
First, you can use os2_ioctl( SIOSTATIF42 ). This call provides interface statistics for all interfaces up to 42 via struct ifmib which includes a index and a description of a network interface.
A index is 0-based. However, if_nameindex() family accepts 0-index as the last entry of network interfaces or an invalid index. So it's needed to increase the index by 1.
A description is a long description not a short description. For example, Ethernet-Csmacd not lan0. So you should generate a canonical name from a description and an index. For details, see the following ODIN source.
Second, you can use ioctl( SIOCGIFCONF ). This call provides network interface configurations via struct ifconf. Since TCP/IP v4.21, it provides AF_LINK type address which includes an index which is from 1 and a name such as lan0 for a network interface. This call is equivalent to if_nameindex() directly. You can get sources implementing if_nameindex() family with ioctl( SIOCGIFCONF ) here.
- if_nameindex() family source: https://github.com/komh/os2compat/blob/master/network/if_nameindex.c
- if_nameindex() family header: https://github.com/komh/os2compat/blob/master/network/if_nameindex.h
- test: https://github.com/komh/os2compat/blob/master/testcase/if_nameindex-1.c
If you want to support 16 bits TCP/IP stack, that is TCP/IP prior to v4.21, then use os2_ioctl( SIOSTATIF42 ). Otherwise use ioctl( SIOCGIFCONF ).
댓글
댓글 쓰기