Miscellaneous details.
Linux supports if_nameindex which is in
POSIX net/if.h
and returns an array
of if_nameindex with fields if_index
and if_name (at least). Indices are positive integers, names are
stuff like lo
and eth0
as displayed
by /sbin/ifconfig; this isn't actually useful for our needs, as it
doesn't connect to IP addresses.
Ulrich
Drepper said that SIOCGIFCONF only returns active interfaces
(but this is apparently actually a bug), while SIOCGIF{NAME,INDEX}
can query all defined interfaces, even ones that are currently down. A reply to
that pointed to netlink facilities, for which socket(AF_NETLINK,
SOCK_DGRAM, NETLINK_ROUTE) sounds like it may give us something to select
on to discover when interface changes happen. The disussion also
mentions rtnetlink, which is a sub-set of the netlink messages.
Elsewhere
I find reference to sysctl() for BSD and Sun—my
Linux man pages only mention sysctl as a system
command (section 8) and its config file (section
5, /etc/sysctl.conf). This also discusses struct
ifreq, as used on Linux, except that it doesn't have
a .ifr_flags, so it's a different structure; the one on Linux has
far more details (see net/if.h
, near its end).
RFC 2553 specifies lots of details about IPv6 and integration with existing networking infrastructure. Details include:
struct sockaddr: older BSD variants have
an initial 16-bit sa_family member which later variants replace
with two 8-bit members, sa_len and sa_family; those
using the latter form are required to #define SIN6_LEN if applying
the same to the IPv6 data-structure (so they probably define a similar symbol,
likely SIN_LEN, anyway). This distinction is not contemplated in
the code of this module, although it might not matter. INADDR_* constants are defined in native byte-order but the
corresponding IN6ADDR_* constants are defined in network
byte-order. Likewise for the associated global variables, when defined. Note
that INADDR_LOOPBACK is defined for the loop-back address
(presumably 127.0.0.1). if_nameindex() gets the names and indices for all interfaces
(and its return value must be released using if_freenameindex);
every interface, indeed, has a unique name and index. Conversion
between these two is mediated by if_nametoindex()
and if_indextoname(). However, this family of functions gives no
way to map an interface name or index to a network address. getipnodebyname() is a thread-safe IPv6-aware replacement
for gethostbyname(). However, it forces separate calls for IPv4
and IPv6. Android's
C library has limitations, notably a lack of condition variables in
its pthread implementation, which I'll need to work round. It also
mentions some interesting-sounding timer
functions: timer_create(), timer_gettime(), timer_settime()
and timer_getoverrun(), which appear to be POSIX.
Experiment with python's netifaces module reveals interfaces in
family AF_PACKET = 17 = AF_LINK may exist, as well as the more
familiar AF_INET = 2 and AF_INET6 = 10.
#includes of
system header files; wherever such a #include is only needed by
this module, it would be sensible to remove it from sys/ and specify
it in exactly only the compilation units of this module that need it. OpNetworkInterfaceManager (see comments
in ../posix_network_interface.h), it would make sense to provide
implementations suitable for use on Linux and FreeBSD (hence Mac). #include "platforms/posix/posix_selector.h" to
access the definitions it needs; plugix could then even go so far as
to clean up the way it goes about managing these socket-callbacks. PosixTimeZone, see CORE-26307)
or reworked to be based on cross-platform base-classes that core could define
(e.g. PosixAsyncManager). PosixIrregular entirely.