Logiciels Libres et Systèmes Embarqués

client_init.c

Aller à la documentation de ce fichier.
00001 #include "global.h"   // client_connected()
00002 #include "lwip/tcp.h" // tcp_new(),tcp_connect()
00003 #include "lwip/pbuf.h"
00004 
00005 #ifdef CLIENT
00006 
00007 static const int client_close = CLIENT_CLOSE;
00008 
00009 int client_init(const unsigned char remote_ip[4], short int remote_port)
00010 {
00011         struct tcp_pcb *pcb = NULL;
00012         err_t ret_code = ERR_OK;
00013         struct ip_addr remote_ipaddr;
00014 
00015         pcb = tcp_new();
00016         if(NULL == pcb) {
00017                 print("tcp_new(): echec.\n\r");
00018                 return -1;
00019         }
00020         
00021         tcp_arg(pcb, (void *)&client_close);
00022         tcp_err(pcb, client_err);
00023 
00024         IP4_ADDR(&remote_ipaddr, remote_ip[0], remote_ip[1], remote_ip[2], remote_ip[3]);
00025 
00026         ret_code = tcp_connect(pcb, &remote_ipaddr, remote_port, client_connected);
00027         if(ERR_OK != ret_code) {
00028                 print("tcp_connect(): echec.\n\r");
00029                 return -1;
00030         }
00031 
00032         return 0;
00033 }
00034 
00035 #endif //CLIENT