osx - What address families can getaddrinfo return? -


when call getaddrinfo af_unspec, can theoretically return address families likes: af_inet, af_inet6, maybe appletalk, bluetooth, datalink, netlink addresses...

in practice, returns af_inet , af_inet6 on platforms:

  • on freebsd, can return af_inet or af_inet6 (checked in source)
  • on linux, ditto (according glibc manpage)
  • on windows, similarly, "a value of af_unspec ai_family indicates caller accept af_inet , af_inet6 address families." [msdn, getaddrinfo]

what other systems? there platforms might other address structures?

i'm particularly suspicious of macos - source seems missing opensource.apple.com/source/libc , manpage doesn't say. have unreproducible log file mac test run may indicate getaddrinfo returned other address family. other platforms support aix, solaris, hp-ux.

i'm aware can check family in structure returned. can't guess interesting strings , hints might need used non-af_inet(6) results out though.

there no guarantee of kind. when have invented own protocol , assigned number (locally), , protocol can resolve name program gave, permissible return sockaddr address family.

basically, if pass af_unspec, can either of 2 things:

  1. live dangerously, assume pf_* constants map af_* constants, create socket of type , connect it, giving instant support homebrew protocol, or, better,

  2. ignore result has address family not understand , proceed next one.

you need aware quite possible name can looked has no addresses of desired type. when doing lookup af_unspec, positive lookup result , need create error condition yourself.

as ideal behaviour app fall on other results in case first 1 not working (think dns round-robin failed server), can achieved iterating on results until 1 succeeds , adjusting error cause (i.e. start "no addresses of required type", , if find 1 , connection fails, switch "destination unreachable").


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -