Logo Search packages:      
Sourcecode: libnl version File versions  Download package

char* nl_addr2str ( struct nl_addr *  addr,
char *  buf,
size_t  size 
)

Convert abstract address object to character string.

  • addr Abstract address object.
  • buf Destination buffer.
  • size Size of destination buffer.
Converts an abstract address to a character string and stores the result in the specified destination buffer.

Returns:
Address represented in ASCII stored in destination buffer.

Definition at line 785 of file addr.c.

Referenced by nl_addr_info().

{
      int i;
      char tmp[16];

      if (!addr->a_len) {
            snprintf(buf, size, "none");
            goto prefix;
      }

      switch (addr->a_family) {
            case AF_INET:
                  inet_ntop(AF_INET, addr->a_addr, buf, size);
                  break;

            case AF_INET6:
                  inet_ntop(AF_INET6, addr->a_addr, buf, size);
                  break;

            case AF_DECnet:
                  dnet_ntop(addr->a_addr, addr->a_len, buf, size);
                  break;

            case AF_LLC:
            default:
                  snprintf(buf, size, "%02x", addr->a_addr[0]);
                  for (i = 1; i < addr->a_len; i++) {
                        snprintf(tmp, sizeof(tmp), ":%02x",
                               addr->a_addr[i]);
                        strncat(buf, tmp, size - strlen(buf) - 1);
                  }
                  break;
      }

prefix:
      if (addr->a_prefixlen && addr->a_prefixlen != (8 * addr->a_len)) {
            snprintf(tmp, sizeof(tmp), "/%u", addr->a_prefixlen);
            strncat(buf, tmp, size - strlen(buf) - 1);
      }

      return buf;
}


Generated by  Doxygen 1.6.0   Back to index