Advertisement
nucLeaRsc2

Untitled

Jul 29th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <lwip/api.h>
  5. #include <lwip/netif.h>
  6.  
  7. #define DIE(assertion, call_description)                \
  8.     do {                                \
  9.         if (assertion) {                    \
  10.             fprintf(stderr, "(%s, %d): %s\n",           \
  11.                     __FILE__, __LINE__, call_description);  \
  12.             return;               \
  13.         }                           \
  14.     } while(0)
  15.  
  16.  
  17.  
  18. void my_app(void *args){
  19.     struct netconn *netConn;
  20.     struct ip_addr local_ip, remote_ip;
  21.     int rc;
  22.    
  23.     netConn = netconn_new(NETCONN_TCP);
  24.     DIE(!netConn, "netconn_new");
  25.  
  26.     local_ip.addr = htonl(0x0a00020f);
  27.     rc = netconn_bind(netConn, &local_ip, 0);
  28.     DIE(rc != ERR_OK, "netconn_bind");
  29.  
  30.     remote_ip.addr = htonl(0x0a00020a);
  31.     rc = netconn_connect(netConn, &remote_ip, 13);
  32.     DIE(rc != ERR_OK, "netconn_connect");
  33.  
  34.     printf("Conectare cu succes!\n");    
  35.    
  36. }
  37.  
  38. int main(int argc, char *argv[]){
  39.     sys_thread_new("client", my_app, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  40.  
  41.     pause();
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement