ip_addr_t的相关问题,无法进行tcp_conncet

kavinkun
Posts: 1
Joined: Wed May 30, 2018 1:50 am

ip_addr_t的相关问题,无法进行tcp_conncet

Postby kavinkun » Tue Jul 31, 2018 2:39 am

Thanks for your previous reply in the past period of time

Code: Select all

static err_t ftp_data_open(ftp_session_t *s, struct pbuf *p)
{
  err_t error;
  char *ptr;
  ip4_addr_t data_server;
  u16_t data_port;

  // Find server connection parameter
  ptr = strchr(p->payload, '(');
  if (!ptr) return ERR_BUF;
  do {
	unsigned int a = strtoul(ptr+1,&ptr,10);
	unsigned int b = strtoul(ptr+1,&ptr,10);
	unsigned int c = strtoul(ptr+1,&ptr,10);
	unsigned int d = strtoul(ptr+1,&ptr,10);
	IP4_ADDR(&data_server,a,b,c,d);
  } while(0);
  data_port  = strtoul(ptr+1,&ptr,10) << 8;
  data_port |= strtoul(ptr+1,&ptr,10) & 255;
  if (*ptr!=')') return ERR_BUF;

  // Open data session
  tcp_arg(s->data_pcb, s);
  tcp_err(s->data_pcb, ftp_data_err);
  tcp_recv(s->data_pcb, ftp_data_recv);
  tcp_sent(s->data_pcb, ftp_data_sent);
  error = tcp_connect(s->data_pcb, (const ip_addr_t *)&data_server, data_port, ftp_data_connected);
  return error;
}
In this code, the tcp_connect function always returns the value of ERR_VAL, using the function in lwip, and the following rules are found to check the error during the viewing process. in IP_ADDR_PCB_VERSION_MATCH_EXACT

Code: Select all

if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr)) {
    return ERR_VAL;
  }
In the past, I encountered such a problem is that ip_addr_t {aka struct _ip_addr}' has no member named 'addr',I changed it to ip4_addr_t to solve this problem,But in the tcp_connect function, the parameter I passed in should be ip_addr_t type, so I made a mandatory type conversion.Then I met the mistake of returning to ERR_VAL.
I use ESP32 to build an ftpclient for OTA upgrade, and use PASV anonymous mode. In my code, I can connect the control link, but there is a mistake on the connection of the data link. By the way, my control link is also applicable to this function. There is no problem. It is very strange.
This is the code about controls link

Code: Select all

err_t ftp_connect(ftp_session_t *s)
{
  err_t error;
  enum ftp_results retval = FTP_RESULT_ERR_UNKNOWN;

  // Check user supplied data
  if ( (s->control_state!=FTP_CLOSED) ||
	   s->control_pcb ||
	   s->data_pcb ||
	   !s->user ||
	   !s->pass )
  {
	ESP_LOGI(TAG, "ftp:invalid control session\n");
	retval = FTP_RESULT_ERR_ARGUMENT;
	goto exit;
  }
  // Get sessions pcb
  s->control_pcb = tcp_new();
  if (!s->control_pcb) {
	ESP_LOGI(TAG, "ftp:cannot alloc control_pcb (low memory?)\n");
	retval = FTP_RESULT_ERR_MEMORY;
	goto exit;
  }
  // Open control session
  tcp_arg(s->control_pcb, s);
  tcp_err(s->control_pcb, ftp_control_err);
  tcp_recv(s->control_pcb, ftp_control_recv);
  tcp_sent(s->control_pcb, ftp_control_sent);
  error = tcp_connect(s->control_pcb, (const ip_addr_t *)&s->server_ip, s->server_port, ftp_control_connected);
  if ( error == ERR_OK ) {
	retval = FTP_RESULT_INPROGRESS;
	return retval;
  }

  // Release pcbs in case of failure
  ESP_LOGI(TAG, "ftp:cannot connect control_pcb (%s)\n", lwip_strerr(error));
  ftp_control_close(s, -1);

exit:
  if (s->done_fn) s->done_fn(s->handle, retval);
  return retval;
}
How should I do for this problem wanna solved? I will appreciate very much with your any opinions

Who is online

Users browsing this forum: No registered users and 87 guests