Exemplo n.º 1
0
int ooSocketGetIpAndPort(OOSOCKET socket, char *ip, int len, int *port)
{
   int ret=ASN_OK;
   socklen_t size;
   struct sockaddr_in addr;
   const char *host=NULL;

   size = sizeof(addr);

   ret = ooSocketGetSockName(socket, &addr, &size);
   if(ret != 0)
      return ASN_E_INVSOCKET;

   host = ast_inet_ntoa(addr.sin_addr);

   if(host && strlen(host) < (unsigned)len)
      strcpy(ip, host);   
   else{
     OOTRACEERR1("Error:Insufficient buffer for ip address - "
                 "ooSocketGetIpAndPort\n");
      return -1;
   }
   
   *port = addr.sin_port;

   return ASN_OK;
}
Exemplo n.º 2
0
int ooBindOSAllocatedPort(OOSOCKET socket, char *ip)
{
   OOIPADDR ipAddrs;
   int size, ret;
   struct sockaddr_in name;
   size = sizeof(struct sockaddr_in);
   ret= ooSocketStrToAddr (ip, &ipAddrs);
   if((ret=ooSocketBind(socket, ipAddrs, 
                     0))==ASN_OK)
   {
      ret = ooSocketGetSockName(socket, &name, &size);
      if(ret == ASN_OK)
      {
         return name.sin_port;
         
      }
   }

   return OO_FAILED;
}