示例#1
0
/* Send SSDP discovery requests searching for WANIPConnection and
   WANPPPConnection services on the local network. Return OK if we
   can find one. Also set the serviceType parameter of the
   UpnpController structure. */
static int Send_Ssdp_Discover(UpnpController * c, char ** ssdp_response)
{
  int i;
  int ret;
  /* allocate space for our search string */
  char * search_target = (char *)malloc(strlen(SSDP_TARGET) +
                                        strlen(WANPPP_TARGET)+
                                        NULL_TERM_LEN);
  if(NULL == search_target) {
    free(c);
    return BAD_MALLOC;
  }

  for(i=0; i<NUM_SSDP_ATTEMPTS; i++) {
    if(i%2 == 0) {
      (void)sprintf(search_target, SSDP_TARGET, WANIP_TARGET);
    } else {
      (void)sprintf(search_target, SSDP_TARGET, WANPPP_TARGET);
    }
    ret = LNat_Ssdp_Discover(search_target, ssdp_response);

    /* if ret == OK, we need to use i with the val it has, so break out */
    if(ret == OK) {
      break;
    }
  }
  if(i == NUM_SSDP_ATTEMPTS) {
    free(search_target);
    return ret;
  }

  /* store the service type variable */
  if(i%2 == 0) {
    c->service_type = (char *)malloc(strlen(WANIP_TARGET) + 
                                     NULL_TERM_LEN);
    if(NULL == c->service_type) {
      free(search_target);
      return BAD_MALLOC;
    }
    (void)strcpy(c->service_type, WANIP_TARGET);
  } else {
    c->service_type = (char *)malloc(strlen(WANPPP_TARGET) + 
                                     NULL_TERM_LEN);
    if(NULL == c->service_type) {
      free(search_target);
      return BAD_MALLOC;
    }
    (void)strcpy(c->service_type, WANPPP_TARGET);
  }
  free(search_target);

  return OK;
}
示例#2
0
文件: ssdp_test.c 项目: big3k/oneway
int main(int argc, char ** argv)
{
  int ret = 0;
  char * response;

  if((ret = LNat_Ssdp_Discover("urn:schemas-upnp-org:service:WANIPConnection:1", &response)) != OK) {
    LNat_Print_Internal_Error(ret);
    exit(EXIT_FAILURE);
  }
  /*(void)printf("SSDP Response:\n%s\n\n", response);*/
  (void)printf(response);

  exit(EXIT_SUCCESS);
}