Example #1
0
/* This function makes an HTTP request to the specified IP address
   and port. This function will return OK on success, or some error
   on failure. It will return an allocated buffer in response. The
   caller must free this buffer when it is through.
*/
static int LNat_Http_Request(const char * resource,
                             const char * host,
                             short int port,
                             const char * message,
                             char ** response)
{
  OsSocket * s;
  int ret;

  /* make the connection to the host and port */
  if((ret = LNat_Os_Socket_Connect(&s, host, port, 
                                    HTTP_CONNECT_TIMEOUT)) != OK ) {
    return ret;
  }

  /* send an HTTP request */
  if((ret = Send_Http_Request(s, message)) != OK) {
    LNat_Os_Socket_Close(&s);
    return ret;
  }

  /* get an HTTP response */
  if((ret = Get_Http_Response(s, response)) != OK) {
    LNat_Os_Socket_Close(&s);
    return ret;
  }

  /* close the connection s is connected to */
  if((ret = LNat_Os_Socket_Close(&s)) != OK) {
    return ret;
  }

  return OK;
}
Example #2
0
static int Get_Local_Ip(const UpnpController * c, char ** ip_map)
{
  int ret;
  OsSocket * s;
  char host[MAX_HOST_LEN];
  char resource[MAX_RESOURCE_LEN];
  short int port;

  /* parse the host, resource, and port out of the url */
  ret = Parse_Url(c->control_url, host, resource, &port);
  if(OK != ret) {
    return ret;
  }

  if((ret = LNat_Os_Socket_Connect(&s, host, port, 2)) != OK) {
    return ret;
  }

  if((ret = LNat_Os_Get_Local_Ip(s, ip_map)) != OK) {
    return ret;
  }

  (void)LNat_Os_Socket_Close(&s);
  return OK;
}