Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <os.h>
- #include <xmalloc.h>
- #include <console.h>
- #include <netfront.h>
- #include <lwip/api.h>
- #define DIE(assertion, call_description) \
- do { \
- if (assertion) { \
- tprintk("(%s, %d): %s\n", \
- __FILE__, __LINE__, call_description); \
- return; \
- } \
- } while(0)
- void client_thread(void *p)
- {
- struct netconn *netConn;
- struct ip_addr remote_ip;
- int rc;
- start_networking();
- struct ip_addr local_ip = { htonl(0x0a00020b) };
- struct ip_addr netmask = { htonl(0xffffff00) };
- struct ip_addr gw = { 0 };
- networking_set_addr(&local_ip, &netmask, &gw);
- netConn = netconn_new(NETCONN_TCP);
- DIE(!netConn, "netconn_new");
- remote_ip.addr = htonl(0x0a00020a);
- rc = netconn_connect(netConn, &remote_ip, 13);
- DIE(rc != ERR_OK, "netconn_connect");
- tprintk("Connected successfully!\n");
- struct netbuf *recvBuf;
- recvBuf = netconn_recv(netConn);
- DIE(!recvBuf, "netconn_recv");
- char *buf;
- int sz;
- rc = netbuf_data(recvBuf, (void**)&buf, (u16_t*)&sz);
- DIE(rc != ERR_OK, "ntebuf_data");
- tprintk( "Received: %s\n", buf);
- free(recvBuf);
- netconn_disconnect(netConn);
- netconn_delete(netConn);
- }
- int app_main(start_info_t *si)
- {
- create_thread("client", client_thread, NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement