示例#1
0
/***************************************************************************************************************************
**函数名称:	 	fpt_bind
**函数功能:	 	
**入口参数:
**返回参数:
***************************************************************************************************************************/
void ftp_bind(FTP_INFO *pftpInfo,UINT16 port)
{
	struct tcp_pcb *pcb;
	struct netconn *net_conn;
	if(eRAW == pftpInfo->attri)
	{
		if(eCtr == pftpInfo->ctrOrMsg)
		{
			if(ERR_OK != tcp_bind(pftpInfo->ftpRAWControl,IP_ADDR_ANY,port))//IP_ADDR_ANY
			{
				LIBMCU_DEBUG(ETHERNTE_DEBUG,("\r\n Control tcp_bind fail"));
			}
		}
		else if(eMsg == pftpInfo->ctrOrMsg)
		{
			if(ERR_OK != tcp_bind(pftpInfo->ftpRAWDataMsg,IP_ADDR_ANY,port))//IP_ADDR_ANY
			{
				LIBMCU_DEBUG(ETHERNTE_DEBUG,("\r\n DataMsg tcp_bind fail"));
			}
		}		
	}
	else if(eRAW == pftpInfo->attri)
	{
	
	}
}
示例#2
0
文件: TcpSocket.c 项目: Sasha7b9/Osci
//------------------------------------------------------------------------------------------------------------------------------------------------------
bool TCPSocket_Init(void(*_funcConnect)(void), void(*_funcReciever)(const char *_buffer, uint _length))
{
    struct tcp_pcb *pcb = tcp_new();
    if (pcb != NULL)
    {
        err_t err = tcp_bind(pcb, IP_ADDR_ANY, (u16_t)DEFAULT_PORT);
        if (err == ERR_OK)
        {
            pcb = tcp_listen(pcb);
            SocketFuncReciever = _funcReciever;
            SocketFuncConnect = _funcConnect;
            tcp_accept(pcb, CallbackOnAccept);
        }
        else
        {
            // abort? output diagnostic?
        }
    }
    else
    {
        // abort? output diagonstic?
    }

    pcb = tcp_new();
    if (pcb != NULL)
    {
        err_t err = tcp_bind(pcb, IP_ADDR_ANY, (u16_t)POLICY_PORT);
        if (err == ERR_OK)
        {
            pcb = tcp_listen(pcb);
            SocketFuncReciever = _funcReciever;
            SocketFuncConnect = _funcConnect;
            tcp_accept(pcb, CallbackOnAcceptPolicyPort);
        }
        else
        {

        }
    }
    else
    {

    }

    pcbClient = 0;

    return true;
}
示例#3
0
void httpd_start(void) {
    //struct tcp_pcb *pcb;
    listen_pcb = tcp_new();
    tcp_bind(listen_pcb, IP_ADDR_ANY, 80);
    listen_pcb = tcp_listen(listen_pcb);
    tcp_accept(listen_pcb, http_accept);
}
static BOOL opennap_start(Protocol *p)
{
	char alias[16];
	
	if (!(OPENNAP->cfg = gift_config_new("OpenNap"))) {
		OPN->err(OPN, "Can't load OpenNap configuration!");
		return FALSE;
	}

	if (!(OPENNAP->con = tcp_bind(OPN_DATAPORT, FALSE)))
		return FALSE;
	
	input_add(OPENNAP->con->fd, OPENNAP->con, INPUT_READ,
	          (InputCallback) opn_upload_connect, TIMEOUT_DEF);

	if (OPN_RANDOM_USERNAME) {
		set_username(alias);
		config_set_str(OPENNAP->cfg, "main/alias", alias);
	}

	OPENNAP->nodelist = opn_nodelist_new();
	opn_nodelist_load(OPENNAP->nodelist, OPN_USE_NAPIGATOR);

	return TRUE;
}
示例#5
0
文件: client.c 项目: fanqh/ETH_Mange
/**
  * @brief  This function is called when a datagram is received
   * @param arg user supplied argument (udp_pcb.recv_arg)
   * @param upcb the udp_pcb which received data
   * @param p the packet buffer that was received
   * @param addr the remote IP address from which the packet was received
   * @param port the remote port from which the packet was received
  * @retval None
  */
void udp_client_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
    struct tcp_pcb *pcb;
    __IO uint8_t iptab[4];
    uint8_t iptxt[20];

    /* Read the Server's IP address */
    iptab[0] = (uint8_t)((uint32_t)(addr->addr) >> 24);
    iptab[1] = (uint8_t)((uint32_t)(addr->addr) >> 16);
    iptab[2] = (uint8_t)((uint32_t)(addr->addr) >> 8);
    iptab[3] = (uint8_t)((uint32_t)(addr->addr));

    sprintf((char*)iptxt, "is: %d.%d.%d.%d     ", iptab[3], iptab[2], iptab[1], iptab[0]);

    LCD_DisplayStringLine(Line3, "The server's IP add.");
    LCD_DisplayStringLine(Line4, iptxt);

    /* Create a new TCP control block  */
    pcb = tcp_new();

    /* Assign to the new pcb a local IP address and a port number */
    tcp_bind(pcb, IP_ADDR_ANY, TCP_PORT);

    /* Connect to the server: send the SYN */
    tcp_connect(pcb, addr, TCP_PORT, tcp_client_connected);


//    tcp_accept(pcb, APP_accept);  //
//   tcp_sent(pcb, App_sent);
    /* Free the p buffer */
    pbuf_free(p);
}
示例#6
0
/**
  * @brief  Initialize the server application.
  * @param  None
  * @retval None
  */
void server_init(void)
{
  struct tcp_pcb *tpcb;    
	struct udp_pcb *upcb;  	 
 
	/* Create a new TCP control block  */
	tpcb = tcp_new();
	
	/* Assign to the new pcb a local IP address and a port number */
	/* Using IP_ADDR_ANY allow the pcb to be used by any local interface */
	tcp_bind(tpcb, IP_ADDR_ANY, TCP_SERVER_PORT);
	
	/* Set the connection to the LISTEN state */
	tpcb = tcp_listen(tpcb);

	/* Specify the function to be called when a connection is established */	
	tcp_accept(tpcb, tcp_server_accept);	
	
  /* Create a new UDP control block  */
  upcb = udp_new();
  
  /* Bind the upcb to the UDP_PORT port */
  /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */
  udp_bind(upcb, IP_ADDR_ANY, UDP_SERVER_PORT);
  
  /* Set a receive callback for the upcb */
  udp_recv(upcb, udp_server_callback, NULL);  
}
示例#7
0
/**
 * Bind a pcb contained in a netconn
 * Called from netconn_bind.
 *
 * @param msg the api_msg_msg pointing to the connection and containing
 *            the IP address and port to bind to
 */
void
do_bind(struct api_msg_msg *msg)
{
    if (ERR_IS_FATAL(msg->conn->last_err)) {
        msg->err = msg->conn->last_err;
    } else {
        msg->err = ERR_VAL;
        if (msg->conn->pcb.tcp != NULL) {
            switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
            case NETCONN_RAW:
                msg->err = raw_bind(msg->conn->pcb.raw, msg->msg.bc.ipaddr);
                break;
#endif /* LWIP_RAW */
#if LWIP_UDP
            case NETCONN_UDP:
                msg->err = udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);
                break;
#endif /* LWIP_UDP */
#if LWIP_TCP
            case NETCONN_TCP:
                msg->err = tcp_bind(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port);
                break;
#endif /* LWIP_TCP */
            default:
                break;
            }
        }
    }
    TCPIP_APIMSG_ACK(msg);
}
示例#8
0
文件: common.c 项目: yangxks/Model
int tcp_listen(const char *ip, unsigned short port)
{
	int fd;

	if ((fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
		perror("socket");
		goto out;
	}

	if (tcp_bind(fd, ip, port) != 0) {
		goto err;
	}

	if (set_nonblock(fd) < 0) {
		perror("set_nonblock");
		goto err;
	}

	if (listen(fd, 8192) == -1) {
		perror("listen");
		goto err;
	}

	return fd;
err:
	close(fd);
out:
	return -1;
}
示例#9
0
文件: httpd.c 项目: gstroe/Arm
/**
 * The initialization function.
 */
err_t
httpd_init(void)
{
	struct tcp_pcb *pcb;
	err_t  err;
	/* Create a new TCP PCB. */
	pcb = tcp_new();

	if (pcb == NULL) {
		printf("F: Fail to create PCB\n\r");
		return ERR_BUF;
	}

	/* Bind the PCB to TCP port 80. */
	err = tcp_bind(pcb, NULL, 80);

	if (err != ERR_OK) {
		printf("E: tcp_bind %x\n\r", err);
		return err;
	}

	/* Change TCP state to LISTEN. */
	pcb = tcp_listen(pcb);

	if (pcb == NULL) {
		printf("E: tcp_listen\n\r");
		return ERR_BUF;
	}

	/* Set up httpd_accet() function to be called
	when a new connection arrives. */
	tcp_accept(pcb, httpd_accept);

	return ERR_OK;
}
示例#10
0
文件: ftpd.c 项目: zeldin/dc-ftpd
static int open_dataconnection(struct tcp_pcb *pcb, struct ftpd_msgstate *fsm)
{
	if (fsm->passive)
		return 0;

	/* Allocate memory for the structure that holds the state of the
	   connection. */
	fsm->datafs = malloc(sizeof(struct ftpd_datastate));

	if (fsm->datafs == NULL) {
		send_msg(pcb, fsm, msg451);
		return 1;
	}
	memset(fsm->datafs, 0, sizeof(struct ftpd_datastate));
	fsm->datafs->msgfs = fsm;
	fsm->datafs->msgpcb = pcb;
	sfifo_init(&fsm->datafs->fifo, 2000);

	fsm->datapcb = tcp_new();
	tcp_bind(fsm->datapcb, &pcb->local_ip, 20);
	/* Tell TCP that this is the structure we wish to be passed for our
	   callbacks. */
	tcp_arg(fsm->datapcb, fsm->datafs);
	tcp_connect(fsm->datapcb, &fsm->dataip, fsm->dataport, ftpd_dataconnected);

	return 0;
}
示例#11
0
STATIC mp_obj_t lwip_socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
    lwip_socket_obj_t *socket = self_in;

    uint8_t ip[NETUTILS_IPV4ADDR_BUFSIZE];
    mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG);

    ip_addr_t bind_addr;
    IP4_ADDR(&bind_addr, ip[0], ip[1], ip[2], ip[3]);

    err_t err = ERR_ARG;
    switch (socket->type) {
        case MOD_NETWORK_SOCK_STREAM: {
            err = tcp_bind((struct tcp_pcb*)socket->pcb, &bind_addr, port);
            break;
        }
        case MOD_NETWORK_SOCK_DGRAM: {
            err = udp_bind((struct udp_pcb*)socket->pcb, &bind_addr, port);
            break;
        }
    }

    if (err != ERR_OK) {
        nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error_lookup_table[-err])));
    }

    return mp_const_none;
}
示例#12
0
struct telnet_svc * telnet_svc_init(int port)
{  
	struct telnet_svc * tn = &telnet_svc;
	int th;

	if (port == 0)
		port = 23; /* use default TELNET srvice port */

	tn->svc = tcp_alloc();
	tn->tp = NULL;
	tcp_bind(tn->svc, INADDR_ANY, htons(port));

	if (tcp_listen(tn->svc, 1) != 0) {
		INF("Can't register the TCP listner!");
		return NULL;
	}

	tn->rx.nonempty_flag = thinkos_flag_alloc();
	tn->rx.nonfull_flag = thinkos_flag_alloc();
	tn->rx.head = 0;
	tn->rx.tail = 0;

	th = thinkos_thread_create_inf((void *)telnet_input_task, (void *)tn, 
								   &telnet_srv_inf);
	(void)th;
								
	INF("TELNET TCP input thread=%d", th);

	return tn;
}
示例#13
0
STATIC mp_obj_t lwip_socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
    lwip_socket_obj_t *socket = self_in;

    uint8_t ip[NETUTILS_IPV4ADDR_BUFSIZE];
    mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG);

    ip_addr_t bind_addr;
    IP4_ADDR(&bind_addr, ip[0], ip[1], ip[2], ip[3]);

    err_t err = ERR_ARG;
    switch (socket->type) {
        case MOD_NETWORK_SOCK_STREAM: {
            err = tcp_bind(socket->pcb.tcp, &bind_addr, port);
            break;
        }
        case MOD_NETWORK_SOCK_DGRAM: {
            err = udp_bind(socket->pcb.udp, &bind_addr, port);
            break;
        }
    }

    if (err != ERR_OK) {
        mp_raise_OSError(error_lookup_table[-err]);
    }

    return mp_const_none;
}
示例#14
0
void lwHTTPDispatcher_Init(
		struct lwHTTPDispatcher* dispatcher,
		int port,
		struct lwhttpSite* site
){
	err_t err;
	dispatcher->caps.clientValidator = 0;
	memset(
		&dispatcher->caps.wsProtocolsList,
		0,
		sizeof(dispatcher->caps.wsProtocolsList)
	);
	memset(
		&dispatcher->conns,
		0,
		sizeof(dispatcher->conns	)
	);
	dispatcher->pcb = tcp_new();
	dispatcher->port = port;
	dispatcher->nextConnectionToTry = 0;
	dispatcher->site = site;
	/* bind to specified @port */
	err = tcp_bind(dispatcher->pcb, IP_ADDR_ANY, port);
	if (err != ERR_OK) {
		LWHTTPDebug("Unable to bind to port %d: err = %d\n\r", port, err);
	}
	tcp_arg(dispatcher->pcb, dispatcher);
	dispatcher->pcb = tcp_listen(dispatcher->pcb);
	tcp_accept(dispatcher->pcb, lwHTTPDispatcher_AcceptCallback);

}
示例#15
0
int start_connection(void)
{
	struct tcp_pcb *_pcb;
	err_t err;

	/* create new TCP PCB structure */
	_pcb = tcp_new();
	if (!_pcb) {
		xil_printf("Error creating PCB. Out of Memory\n\r");
		return -1;
	}

	/* bind to specified @port */
	err = tcp_bind(_pcb, IP_ADDR_ANY, (unsigned short)PORT);
	if (err != ERR_OK) {
		xil_printf("Unable to bind to port %d: err = %d\n\r", PORT, err);
		return -2;
	}

	/* we do not need any arguments to callback functions */
	tcp_arg(_pcb, NULL);

	/* listen for connections */
	_pcb = tcp_listen(_pcb);
	if (!_pcb) {
		xil_printf("Out of memory while tcp_listen\n\r");
		return -3;
	}

	/* specify callback to use for incoming connections */
	tcp_accept(_pcb, accept_callback);

	return 0;
}
示例#16
0
文件: socks.c 项目: stxh/tunsocks
int
socks_tcp_bind(struct socks_data *data)
{
	struct tcp_pcb *pcb;
	err_t ret;

	pcb = tcp_new();
	if (!pcb)
		return -1;

	pcb->flags |= TF_NODELAY;
	ip_set_option(pcb, SOF_REUSEADDR);

	ret = tcp_bind(pcb, IP_ADDR_ANY, data->port);
	if (ret < 0) {
		tcp_abort(pcb);
		return -1;
	}

	data->pcb = tcp_listen(pcb);
	if (!data->pcb) {
		tcp_abort(pcb);
		return -1;
	}

	tcp_arg(data->pcb, data);
	tcp_accept(data->pcb, socks_tcp_accept);

	return 0;
}
void AsyncServer::begin(){
  if(_pcb)
    return;

  int8_t err;
  tcp_pcb* pcb = tcp_new();
  if (!pcb)
    return;

  ip_addr_t local_addr;
  local_addr.addr = (uint32_t) _addr;
  err = tcp_bind(pcb, &local_addr, _port);

  if (err != ERR_OK) {
    tcp_close(pcb);
    return;
  }

  tcp_pcb* listen_pcb = tcp_listen(pcb);
  if (!listen_pcb) {
    tcp_close(pcb);
    return;
  }
  _pcb = listen_pcb;
  tcp_arg(_pcb, (void*) this);
  tcp_accept(_pcb, _s_accept);
}
示例#18
0
int tcp_server_bm_init(uint16_t bind_port)
{
    err_t r;

    //don't use htons() (don't know why...)

    struct tcp_pcb *pcb = tcp_new();
    if (pcb == NULL) {
        return ERR_MEM;
    }

    r = tcp_bind(pcb, IP_ADDR_ANY, bind_port);
    if(r != ERR_OK) {
        return(r);
    }

    struct tcp_pcb *pcb2 = tcp_listen(pcb);
    assert(pcb2 != NULL);
    tcp_accept(pcb2, tcp_server_bm_accept);

    printf("TCP tcp_server_bm_init(): bound.\n");
    printf("TCP installed receive callback.\n");
    printf("TCP benchmark server started\n");
    return (0);
}
示例#19
0
文件: telnet.c 项目: hkwi/ZodiacFX
void telnet_init(void)
{
	telnet_pcb = tcp_new();
	tcp_bind(telnet_pcb, IP_ADDR_ANY, 23);
	telnet_pcb = tcp_listen(telnet_pcb);
	tcp_accept(telnet_pcb, telnet_accept);
}
示例#20
0
/**
  * @brief  Initializes the tcp echo server
  * @param  None
  * @retval None
  */
void tcp_echoserver_init(void)
{
  /* create new tcp pcb */
  tcp_echoserver_pcb = tcp_new();

  if (tcp_echoserver_pcb != NULL)
  {
    err_t err;
    
    /* bind echo_pcb to port 7 (ECHO protocol) */
    err = tcp_bind(tcp_echoserver_pcb, IP_ADDR_ANY, 7);
    
    if (err == ERR_OK)
    {
      /* start tcp listening for echo_pcb */
      tcp_echoserver_pcb = tcp_listen(tcp_echoserver_pcb);
      
      /* initialize LwIP tcp_accept callback function */
      tcp_accept(tcp_echoserver_pcb, tcp_echoserver_accept);
    }
    else 
    {
      /* deallocate the pcb */
      memp_free(MEMP_TCP_PCB, tcp_echoserver_pcb);
      printf("Can not bind pcb\n");
    }
  }
  else
  {
    printf("Can not create new pcb\n");
  }
}
示例#21
0
int lwip_bind(int s, struct sockaddr *name, socklen_t namelen) {
	sockfd_t	* fd;
	struct ip_addr	ip;
	int		port, rv = 0;

	s = sock_for_fd(s);
	if (s < 0) {
		errno = EBADF;
		return -1;
	}
	fd = fds + s;

	// Make sure it's an internet address we understand.
	if (namelen != sizeof(struct sockaddr_in)) {
		errno = ENAMETOOLONG;
		return -1;
	}

	// Get access
	mutex_lock(fd->mutex);

	// Copy it over
	memcpy(&fd->name, name, namelen);

	// Convert this to an lwIP-happy format
	ip.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
	port = ((struct sockaddr_in *)name)->sin_port;

	// Are we TCP or UDP?
	switch (fd->type) {
	case SOCK_STREAM:
		fd->tcppcb = tcp_new();
		tcp_arg(fd->tcppcb, (void *)s);
		tcp_recv(fd->tcppcb, recv_tcp);
		tcp_sent(fd->tcppcb, sent_tcp);
		tcp_poll(fd->tcppcb, poll_tcp, 4);	// 4 == 4 TCP timer intervals
		tcp_err(fd->tcppcb, err_tcp);
		if (tcp_bind(fd->tcppcb, &ip, ntohs(port)) != ERR_OK) {
			if (tcp_close(fd->tcppcb) != ERR_OK)
				tcp_abort(fd->tcppcb);
			fd->tcppcb = NULL;
			errno = EINVAL;
			rv = -1; goto out;
		}
		break;
	case SOCK_DGRAM:
		fd->udppcb = udp_new();
		udp_recv(fd->udppcb, recv_udp, (void *)s);
		udp_bind(fd->udppcb, &ip, ntohs(port));
		break;
	default:
		assert( 0 );
		errno = EINVAL;
		rv = -1; goto out;
	}

out:
	mutex_unlock(fd->mutex);
	return rv;
}
示例#22
0
文件: rostcp.c 项目: RareHare/reactos
static
void
LibTCPBindCallback(void *arg)
{
    struct lwip_callback_msg *msg = arg;
    PTCP_PCB pcb = msg->Input.Bind.Connection->SocketContext;

    ASSERT(msg);

    if (!msg->Input.Bind.Connection->SocketContext)
    {
        msg->Output.Bind.Error = ERR_CLSD;
        goto done;
    }

    /* We're guaranteed that the local address is valid to bind at this point */
    pcb->so_options |= SOF_REUSEADDR;

    msg->Output.Bind.Error = tcp_bind(pcb,
                                      msg->Input.Bind.IpAddress,
                                      ntohs(msg->Input.Bind.Port));

done:
    KeSetEvent(&msg->Event, IO_NO_INCREMENT, FALSE);
}
示例#23
0
void WiFiServer::begin()
{
    err_t err;

    tcp_pcb* pcb = tcp_new();
    if (!pcb)
        return;

    err = tcp_bind(pcb, INADDR_ANY, _port);

    if (err != ERR_OK)
    {
        tcp_close(pcb);
        return;
    }

    tcp_pcb* listen_pcb = tcp_listen(pcb);
    if (!listen_pcb)
    {
        tcp_close(pcb);
        return;
    }
    _pcb = listen_pcb;
    tcp_accept(listen_pcb, &WiFiServer::_s_accept);
    tcp_arg(listen_pcb, (void*) this);
}
示例#24
0
文件: syscall.c 项目: rasco/armnet
int syscall_handler(int num, struct syscall_arguments *args)
{
    interrupt_unmask();
    
    switch (num)
    {
        case ADDPROCESS:
            interrupt_mask();
                process_add((void (*)())args->arg1);
            interrupt_unmask();
        break;
        case YIELD:
            interrupt_sleepinsyscall();
        break;
        
        case UDPSEND:
            return udp_output(args->arg1, (struct sockaddr*)args->arg2, 
                (char *)args->arg3, args->arg4);
        break;
        case UDPRECV:
            return udp_recvfrom(args->arg1, (struct sockaddr*)args->arg2, 
                (char *)args->arg3, args->arg4);
        break;
        case UDPSOCKET: 
            return udp_socket();
        break;
        case UDPBIND:
            return udp_bind(args->arg1, (struct sockaddr*)args->arg2);
        break;
        case UDPCLOSE:
            return udp_close(args->arg1);
        break;
        
        case TCPCONNECT:
            return tcp_connect(args->arg1, (struct sockaddr*)args->arg2);
        break;
        
        case TCPSEND:
            return tcp_send(args->arg1, (char *)args->arg2, args->arg3);
        break;
        case TCPRECV:
            return tcp_recv(args->arg1, (char *)args->arg2, args->arg3);
        break;
        case TCPSOCKET: 
            return tcp_socket();
        break;
        case TCPBIND:
            return tcp_bind(args->arg1, (struct sockaddr*)args->arg2);
        break;
        case TCPCLOSE:
            return tcp_close(args->arg1);
        break;
        case TCPLISTEN:
            return tcp_listen(args->arg1);
        break;
    }
    
    return 0;
}
示例#25
0
文件: test_tcp.c 项目: tansinan/lwIP
END_TEST

/** Call tcp_new() and tcp_abort() and test memp stats */
START_TEST(test_tcp_listen_passive_open)
{
  struct tcp_pcb *pcb, *pcbl;
  struct tcp_pcb_listen *lpcb;
  struct netif netif;
  struct test_tcp_txcounters txcounters;
  struct test_tcp_counters counters;
  struct pbuf *p;
  ip_addr_t src_addr;
  err_t err;
  LWIP_UNUSED_ARG(_i);

  fail_unless(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);

  test_tcp_init_netif(&netif, &txcounters, &test_local_ip, &test_netmask);
  /* initialize counter struct */
  memset(&counters, 0, sizeof(counters));

  pcb = tcp_new();
  EXPECT_RET(pcb != NULL);
  err = tcp_bind(pcb, &netif.ip_addr, 1234);
  EXPECT(err == ERR_OK);
  pcbl = tcp_listen(pcb);
  EXPECT_RET(pcbl != NULL);
  EXPECT_RET(pcbl != pcb);
  lpcb = (struct tcp_pcb_listen *)pcbl;

  ip_addr_set_ip4_u32_val(src_addr, lwip_htonl(lwip_ntohl(ip_addr_get_ip4_u32(&lpcb->local_ip)) + 1));

  /* check correct syn packet */
  p = tcp_create_segment(&src_addr, &lpcb->local_ip, 12345,
    lpcb->local_port, NULL, 0, 12345, 54321, TCP_SYN);
  EXPECT(p != NULL);
  if (p != NULL) {
    /* pass the segment to tcp_input */
    test_tcp_input(p, &netif);
    /* check if counters are as expected */
    EXPECT(txcounters.num_tx_calls == 1);
  }

  /* check syn packet with short length */
  p = tcp_create_segment(&src_addr, &lpcb->local_ip, 12345,
    lpcb->local_port, NULL, 0, 12345, 54321, TCP_SYN);
  EXPECT(p != NULL);
  EXPECT(p->next == NULL);
  if ((p != NULL) && (p->next == NULL)) {
    p->len -= 2;
    p->tot_len -= 2;
    /* pass the segment to tcp_input */
    test_tcp_input(p, &netif);
    /* check if counters are as expected */
    EXPECT(txcounters.num_tx_calls == 1);
  }

  tcp_close(pcbl);
}
示例#26
0
文件: ard_tcp.c 项目: 4bcat/Arduino
/**
 * Start TCP transfer.
 */
static int atcp_start(struct ttcp* ttcp) {
	err_t err = ERR_OK;

	ttcp->tpcb = tcp_new();
	if (ttcp->tpcb == NULL) {
		WARN("TTCP [%p]: could not allocate pcb\n", ttcp);
		return -1;
	}

	ttcp->payload = malloc(ttcp->buflen);
	if (ttcp->payload == NULL) {
		WARN("TTCP [%p]: could not allocate payload\n", ttcp);
		return -1;
	}

	tcp_arg(ttcp->tpcb, ttcp);
	atcp_init_pend_flags();

	if (ttcp->mode == TTCP_MODE_TRANSMIT) {
		tcp_err(ttcp->tpcb, atcp_conn_cli_err_cb);
		tcp_recv(ttcp->tpcb, atcp_recv_cb);
		tcp_sent(ttcp->tpcb, tcp_data_sent);
		tcp_poll(ttcp->tpcb, atcp_poll_conn, 4);
		_connected = false;
		INFO_TCP("[tpcb]-%p payload:%p\n", ttcp->tpcb, ttcp->payload);
		DUMP_TCP_STATE(ttcp);
		if (tcp_connect(ttcp->tpcb, &ttcp->addr, ttcp->port, tcp_connect_cb)
				!= ERR_OK) {
			WARN("TTCP [%p]: tcp connect failed\n", ttcp);
			return -1;
		}

	} else {
		INFO_TCP("BEFORE BIND ttcp:%p lpcb:%p pcb:%p\n", ttcp, ttcp->lpcb, ttcp->tpcb);
		INFO_TCP("[tpcb]-local:%d remote:%d state:%d\n", ttcp->tpcb->local_port,
				ttcp->tpcb->remote_port, ttcp->tpcb->state);

		err = tcp_bind(ttcp->tpcb, IP_ADDR_ANY, ttcp->port);
		if (err != ERR_OK){
			WARN("TTCP [%p]: bind failed err=%d Port already used\n", ttcp, err);
			return -1;
		}

		ttcp->lpcb = tcp_listen(ttcp->tpcb);
		if (ttcp->lpcb == NULL) {
			WARN("TTCP [%p]: listen failed\n", ttcp);
			return -1;
		}
		if (ttcp->lpcb == ttcp->tpcb ) {
			WARN("TTCP [%p]: listen failed tpcb [%p] in listen mode\n", ttcp, ttcp->tpcb);
			return -1;
		}

		DUMP_TCP_STATE(ttcp);
		tcp_accept(ttcp->lpcb, atcp_accept_cb);
	}

	return 0;
}
示例#27
0
void my_tcp_server_init(void)
{
	struct tcp_pcb *pcb ;
	pcb = tcp_new();
	tcp_bind(pcb,IP_ADDR_ANY,2000);
	pcb = tcp_listen(pcb);
	tcp_accept(pcb,my_accept);
}
示例#28
0
void ps_init(void) {
	struct tcp_pcb *pcb;

	pcb = tcp_new();
	tcp_bind(pcb, IP_ADDR_ANY, 7765);
	pcb = tcp_listen(pcb);
	tcp_accept(pcb, ps_accept_FPV_tcp_accept);
}
示例#29
0
void Network::OpenDataPort(uint16_t port)
{
	closingDataPort = false;
	tcp_pcb* pcb = tcp_new();
	tcp_bind(pcb, IP_ADDR_ANY, port);
	ftp_pasv_pcb = tcp_listen(pcb);
	tcp_accept(ftp_pasv_pcb, conn_accept);
}
示例#30
0
文件: sink.c 项目: DanMills/j4cDAC
void sink_init(void) {
	struct tcp_pcb *pcb;

	pcb = tcp_new();
	tcp_bind(pcb, IP_ADDR_ANY, 9);
	pcb = tcp_listen(pcb);
	tcp_accept(pcb, sink_accept);
}