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

TPORT_DLL int tport_convert_addr ( su_home_t home,
tp_name_t tpn,
char const *  protoname,
char const *  canon,
su_sockaddr_t const *  su 
)

Convert a socket address to a transport name.

Convert sockaddr_t to a transport name.

Return values:
0 when successful
-1 upon an error

Definition at line 2160 of file tport.c.

References name, su_sockaddr_u::su_family, tp_name_t::tpn_canon, tp_name_t::tpn_host, tp_name_t::tpn_port, tp_name_t::tpn_proto, tport_convert_addr(), tport_hostport(), TPORT_HOSTPORTSIZE, and tport_name_dup().

Referenced by tport_convert_addr().

{
  tp_name_t name[1] = {{ NULL }};
  char const *host;
  char buf[TPORT_HOSTPORTSIZE];
  char port[8];
  size_t canonlen = canon ? strlen(canon) : 0;

  if (su == NULL)
    host = "*";
  else if (!SU_SOCKADDR_INADDR_ANY(su))
    host = tport_hostport(buf, sizeof(buf), su, 0);
  else if (canonlen && su->su_family == AF_INET && 
         strspn(canon, "0123456789.") == canonlen)
    host = canon;
#if SU_HAVE_IN6
  else if (canonlen && su->su_family == AF_INET6 && 
         strspn(canon, "0123456789abcdefABCDEF:.") == canonlen)
    host = canon;
#endif
  else
    host = localipname(su->su_family, buf, sizeof(buf));

  if (host == NULL)
    return -1;

  if (su == NULL)
    strcpy(port, "*");
  else
    snprintf(port, sizeof(port), "%u", ntohs(su->su_port));
  
  name->tpn_proto = protoname;
  name->tpn_host = host;
  name->tpn_canon = canon ? canon : host;
  name->tpn_port = port;

  return tport_name_dup(home, tpn, name);
}


Generated by  Doxygen 1.6.0   Back to index