Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

tcpclient.c

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /* This file has been written by Sergio Perez Alcañiz <serpeal@disca.upv.es>  */
00003 /*            Departamento de Informática de Sistemas y Computadores          */
00004 /*            Universidad Politécnica de Valencia                             */
00005 /*            Valencia (Spain)                                                */
00006 /*            Date: April 2003                                                */
00007 /******************************************************************************/
00008 
00009 #include <linux/module.h>
00010 #include <linux/kernel.h>
00011 #include "lwip/ip_addr.h"
00012 #include "lwip/sys.h"
00013 #include "lwip/api.h"
00014 #include <rtl_sched.h>
00015 
00016 pthread_t rtl_lwip_tcpclient;
00017 
00018 /*-----------------------------------------------------------------------------------*/
00019 static void * tcp_client(void *arg){
00020   static struct netconn *conn;
00021   struct ip_addr ipaddr;
00022   char data[6];
00023 
00024   sys_thread_register((void *) pthread_self());
00025  
00026   rtl_printf("TCP Client thread : 0x%x\n",pthread_self());
00027   
00028   conn = netconn_new(NETCONN_TCP);
00029 
00030   IP4_ADDR(&ipaddr, 158,42,58,141);
00031 
00032   netconn_bind(conn, &ipaddr, 7);
00033 
00034   IP4_ADDR(&ipaddr, 158,42,58,139);
00035 
00036   rtl_printf("Netconn_connect\n");
00037   netconn_connect(conn, &ipaddr, 10);
00038 
00039   data[0] = 'h';
00040   data[1] = 'e';
00041   data[2] = 'l';
00042   data[3] = 'l';
00043   data[4] = 'o';
00044   data[5] = '\0';
00045   
00046   rtl_printf("Echo TCP client sending: %s\n",data);
00047   
00048   netconn_write(conn,data,6,NETCONN_COPY);
00049   
00050   netconn_delete(conn);
00051   
00052   return sys_thread_exit();
00053 }
00054 
00055 
00056 /*-----------------------------------------------------------------------------------*/
00057 int init_module(void){
00058   pthread_attr_t attr;
00059 
00060   printk("\n\nEcho TCP client module inserted.\n\n"); 
00061 
00062   pthread_attr_init(&attr);
00063   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
00064   if(pthread_create(&(rtl_lwip_tcpclient),&attr, tcp_client, NULL)) {
00065     rtl_printf("ERROR: cannot create pthread!\n");
00066     return -1;
00067   }
00068 
00069  return 0;
00070 }
00071 
00072 /*-----------------------------------------------------------------------------------*/
00073 void cleanup_module(void){
00074   pthread_delete_np(rtl_lwip_tcpclient);
00075   printk("\n\nEcho TCP client module removed.\n\n"); 
00076 }

Generated on Wed Jan 14 12:58:57 2004 for RTL-lwIP-0.4 by doxygen 1.3.4