Logo Search packages:      
Sourcecode: sofia-sip version File versions  Download package

SOFIAPUBFUN int su_getlocalinfo ( su_localinfo_t const *  hints,
su_localinfo_t **  return_localinfo 

Request local address information.

Request local address information

Gather the network interfaces and the addresses corresponding to them, check if they match to the search criteria specifed by hints and return a list of matching local address information in the return_localinfo. The local address information may include IPv4/IPv6 addresses, interface name, interface index, address scope, and domain names corresponding to the local addresses.

[in] hints specifies selection criteria
[out] return_localinfo return list of local addresses
Selection criteria - hints
The selection criteria hints is used to select which addresses are returned and what kind of information is included in the res list.

Selection by flags - hints->li_flags
The hints->li_flags contain flags, which can be combined with bit-wise or. The currently defined flags are as follows:

  • LI_V4MAPPED: when returning IPv4 addresses, map them as IPv6 addresses. If this flag is specified, IPv4 addresses are returned even if hints->li_family is set to AF_INET6.
  • LI_CANONNAME: return the domain name (DNS PTR) corresponding to the local address in li_canonname.
  • LI_NAMEREQD: Do not return addresses not in DNS.
  • LI_NUMERIC: instead of domain name, return the text presentation of the addresss in li_canonname.
  • LI_DOWN: include interfaces and their addresses even if the interfaces are down. New in .
  • LI_IFNAME: return the interface name in li_ifname.

Selection by address family - hints->li_family
The address family can have three values: 0, AF_INET and AF_INET6. If address family hints->li_family, both IPv4 and IPv6 addresses are returned.

Selection by interface index - hints->li_index
If the field hints->li_index is non-zero, only the addresses assigned to the interface with given index are returned. The list of interface indices and names can be obtained by the function su_if_names().

Selection by interface name - hints->li_ifname
If the field hints->li_ifname is not NULL, only the addresses assigned to the named interface are returned. The list of interface names can be obtained by the function su_if_names().

Selection by address scope - hints->li_scope
If the field hints->li_scope is nonzero, only the addresses with matching scope are returned. The different address scopes can be combined with bitwise or. They are defined as follows
  • LI_SCOPE_HOST: host-local address, valid within host (::1,
  • LI_SCOPE_LINK: link-local address, valid within link (IP6 addresses with prefix fe80::/10, IP4 addresses in net
  • LI_SCOPE_SITE: site-local address, addresses valid within organization (IPv6 addresses with prefix fec::/10, private IPv4 addresses in nets,, and as defined in )
  • LI_SCOPE_GLOBAL: global address.

For instance, setting hints->li_scope to LI_SCOPE_GLOBAL | LI_SCOPE_SITE, both the global and site-local addresses are returned.

See also:
, , su_sockaddr_scope()
Selection by domain name - hints->li_canonname
If this field is non-null, the domain name (DNS PTR) corresponding to local IP addresses should match to the name given in this field.

Zero (ELI_NOERROR) when successful, or negative error code when failed.
Use su_gli_strerror() in order to obtain a string describing the error code returned by su_getlocalinfo().

Definition at line 182 of file su_localinfo.c.

References ELI_BADHINTS, ELI_NOADDRESS, LI_CANONNAME, LI_IFNAME, LI_V4MAPPED, su_freelocalinfo(), and su_getlocalinfo().

Referenced by priv_find_matching_localadress(), soa_init_sdp_connection(), stun_determine_ip_address(), su_getlocalinfo(), su_getlocalip(), and test_sockaddr().

  int error = 0, ip4 = 0, ip6 = 0;
  su_localinfo_t *result = NULL, **rr = &result;
  su_localinfo_t hh[1] = {{ 0 }};


  *return_localinfo = NULL;

  if (hints) {
    /* Copy hints so that it can be modified */
    *hh = *hints;
    if (hh->li_canonname)
      hh->li_flags |= LI_CANONNAME;
    if ((hh->li_flags & LI_IFNAME) && hh->li_ifname == NULL)
      return ELI_BADHINTS;

  switch (hh->li_family) {
  case AF_INET6:
    if (hh->li_flags & LI_V4MAPPED)
      ip6 = ip4 = 1, hh->li_family = 0;
      ip6 = 1;

  case AF_INET:
    ip4 = 1;

  case 0:
    ip6 = ip4 = 1;

    return -1;

  error = localinfo0(hh, rr);

#  if SU_HAVE_IN6
  if (ip6) {
    error = localinfo6(hh, rr);
    if (error == ELI_NOADDRESS && ip4)
      error = 0;

    if (!error)
      /* Search end of list */
      for (; *rr; rr = &(*rr)->li_next)
#  endif
  if (ip4 && !error) {
    /* Append IPv4 addresses */
    error = localinfo4(hh, rr);

  if (!result)
    error = ELI_NOADDRESS;

  if (!error)
    li_sort(result, return_localinfo);

  return error;

Generated by  Doxygen 1.6.0   Back to index