Logo Search packages:      
Sourcecode: likewise-open version File versions

static char* ipstr_list_add ( char **  ipstr_list,
const struct ip_service *  service 
) [static]

Add ip string representation to ipstr list. Used also as part of ipstr_list_make

Parameters:
ipstr_list pointer to string containing ip list; MUST BE already allocated and IS reallocated if necessary
ipstr_size pointer to current size of ipstr_list (might be changed as a result of reallocation)
ip IP address which is to be added to list
Returns:
pointer to string appended with new ip and possibly reallocated to new length

Definition at line 2172 of file util_str.c.

Referenced by ipstr_list_make().

{
      char *new_ipstr = NULL;
      char addr_buf[INET6_ADDRSTRLEN];

      /* arguments checking */
      if (!ipstr_list || !service) {
            return NULL;
      }

      print_sockaddr(addr_buf,
                  sizeof(addr_buf),
                  &service->ss);

      /* attempt to convert ip to a string and append colon separator to it */
      if (*ipstr_list) {
            if (service->ss.ss_family == AF_INET) {
                  /* IPv4 */
                  asprintf(&new_ipstr, "%s%s%s:%d",
                              *ipstr_list,
                              IPSTR_LIST_SEP,
                              addr_buf,
                              service->port);
            } else {
                  /* IPv6 */
                  asprintf(&new_ipstr, "%s%s[%s]:%d",
                              *ipstr_list,
                              IPSTR_LIST_SEP,
                              addr_buf,
                              service->port);
            }
            SAFE_FREE(*ipstr_list);
      } else {
            if (service->ss.ss_family == AF_INET) {
                  /* IPv4 */
                  asprintf(&new_ipstr, "%s:%d",
                        addr_buf,
                        service->port);
            } else {
                  /* IPv6 */
                  asprintf(&new_ipstr, "[%s]:%d",
                        addr_buf,
                        service->port);
            }
      }
      *ipstr_list = new_ipstr;
      return *ipstr_list;
}


Generated by  Doxygen 1.6.0   Back to index