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 ).

댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷