Esempio n. 1
0
int main(void)
{  

	delay_ms(100);
	led_setup();
	adc_init();
	LCD_SETUP(buffer);

	tcp_setup.Gateway = GateWay;//Gateway Address
	tcp_setup.MAC = MAC;
	tcp_setup.Source_IP = IP;//IP Address
	tcp_setup.Source_Port = 80; // Web Port
	tcp_setup.Subnet = SubNet;//SubnetMask Address
	tcp_setup.s = 0;
	tcp_socket_init(&tcp_setup);


	while(1)
	{
		if(check_for_connections(&tcp_setup)) // Wait for connection)
		{
			process_request(&tcp_setup);
			tcp_socket_init(&tcp_setup);
		}

		sprintf(buffer2,"%d",ADCRead(0));
		drawString8x12(10,60,buffer2);
	}

}
static void connect2dst()
{
    int ret;
	if (the_working_paras.src_ip)
        the_working_paras.sockfd = tcp_socket_init(the_working_paras.src_ip, the_working_paras.src_port);
	else
		the_working_paras.sockfd = tcp_socket_init_no_addr();
	
	if (the_working_paras.sockfd<0)
	{
	    ERR_DBG_PRINT_QUIT("create socket on %s:%d failed ", the_working_paras.src_ip, (int)the_working_paras.src_port);
	}

	
    make_sockaddr(&the_working_paras.dst_sock_addr, inet_addr(the_working_paras.dst_ip), htons(the_working_paras.dst_port));
	ret=connect(the_working_paras.sockfd
		,(void *)&the_working_paras.dst_sock_addr
		,sizeof(struct sockaddr_in));
	if (ret<0)
	{
	    ERR_DBG_PRINT_QUIT("connect to %s:%d failed ", the_working_paras.dst_ip, (int)the_working_paras.dst_port);
	}

    set_fd_nonblock(the_working_paras.sockfd);
	DBG_PRINT("connect to %s:%d succeed!", the_working_paras.dst_ip, (int)the_working_paras.dst_port);

}
Esempio n. 3
0
/*---------------------------------------------------------------------------*/
void
tcp_socket_register(struct tcp_socket *s, void *ptr,
		    uint8_t *input_databuf, int input_databuf_len,
		    uint8_t *output_databuf, int output_databuf_len,
		    tcp_socket_input_callback_t input_callback,
		    tcp_socket_event_callback_t event_callback)
{

  tcp_socket_init();

  s->ptr = ptr;
  s->input_data_ptr = input_databuf;
  s->input_data_maxlen = input_databuf_len;
  s->output_data_ptr = output_databuf;
  s->output_data_maxlen = output_databuf_len;
  s->input_callback = input_callback;
  s->event_callback = event_callback;
  list_add(socketlist, s);

  s->listen_port = 0;
  s->flags = TCP_SOCKET_FLAGS_NONE;
}
Esempio n. 4
0
static void *misc_thread_func(void *arg)
{
    fd_set r_fds,w_fds,except_fds;
    struct timeval tv;
    int retval, max_fd, tmp_fd;

    save_ori_io();
    fd_server=tcp_socket_init(NULL, server_port);
    if (fd_server<0)
    {
        ERR_DBG_PRINT_QUIT("create telnetd server socket failed.");
    }
    
    listen(fd_server,0);

    while (1)
    {
        FD_ZERO(&r_fds);
        FD_ZERO(&w_fds);
        FD_ZERO(&except_fds);

        FD_SET(fd_server, &r_fds);
        max_fd=fd_server;



        if (fd_conn>0)
        {
            FD_SET(fd_conn, &r_fds);
            FD_SET(fd_conn, &except_fds);
            max_fd=(fd_conn>max_fd)?fd_conn:max_fd;

            FD_SET(fd_pty_master, &r_fds);
            max_fd=(fd_pty_master>max_fd)?fd_pty_master:max_fd;
        }

        tv.tv_sec = 0;
        tv.tv_usec = 200000;

        retval = select(max_fd + 1, &r_fds, &w_fds, &except_fds, &tv);
        if (retval <= 0)
        {
            continue;
        }

        if (FD_ISSET(fd_server, &r_fds))
        {
            tmp_fd=accept(fd_server, NULL, NULL);
            if (tmp_fd<0)
            {
                continue;
            }

            if (fd_conn>0)
            {
                printf_to_fd(fd_conn, "A new login happens, so we shutdown your session...\r\n");
            }
            
            term_session();

            if (make_new_session(tmp_fd))
            {
                close(tmp_fd);
            }
            continue;

        }

        if (shell_quit_occurred || FD_ISSET(fd_conn, &except_fds))
        {
            term_session();
            continue;
        }

        if (FD_ISSET(fd_conn, &r_fds))
        {
            trans_data_sock2pty();
        }

        if (FD_ISSET(fd_pty_master, &r_fds)|| (pty2sock_cache_len>0))
        {
            if (trans_data_pty2sock())
            {
                    term_session();
                    continue;
            }
        
        }



    }

    return NULL;
}