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

sock_tcp_client.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/sockets.h"
00014 #include "lwip/inet.h"
00015 
00016 //#define htons HTONS
00017 //#define htonl HTONL
00018 
00019 #define LOCAL_PORT 10
00020 #define REMOTE_PORT 7
00021 #define REMOTE_SERVER "158.42.58.139"
00022 #define SEND_PHRASE "MOOOOLA"
00023 
00024 /*-----------------------------------------------------------------------------------*/
00025 static void sock_udpclient(void *arg){
00026   int s, error;
00027   struct sockaddr_in localAddr, servAddr;
00028   struct in_addr addr;
00029 
00030   inet_aton(REMOTE_SERVER,&addr);
00031 
00032   s = socket(AF_INET, SOCK_STREAM, 0);
00033 
00034   /* bind any port number */
00035   localAddr.sin_family = AF_INET;
00036   localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
00037   localAddr.sin_port = htons(LOCAL_PORT);
00038 
00039   error = bind(s, (struct sockaddr *) &localAddr, sizeof(localAddr));
00040   if(error<0)
00041     rtl_printf("ERROR: cannot bind port TCP %u\n",LOCAL_PORT);
00042 
00043   servAddr.sin_family = AF_INET;
00044   servAddr.sin_addr.s_addr = addr.s_addr;
00045   servAddr.sin_port = htons(REMOTE_PORT);
00046 
00047   /* connect to server */
00048   error = connect(s, (struct sockaddr *) &servAddr, sizeof(servAddr));
00049   if(error<0)
00050     rtl_printf("cannot connect ");
00051 
00052   rtl_printf("Socket TCP echo client sending: %s\n",SEND_PHRASE); 
00053   error = send(s,SEND_PHRASE , sizeof(SEND_PHRASE), 0);
00054     
00055   if(error<0) {
00056     rtl_printf("cannot send data ");
00057   }
00058 
00059   close(s);
00060 
00061   sys_thread_exit();
00062 }
00063 /*-----------------------------------------------------------------------------------*/
00064 int init_module(void){
00065   printk("\n\n Socket TCP echo client module inserted\n\n"); 
00066   sys_thread_new(sock_udpclient, NULL, 1000);
00067  return 0;
00068 }
00069 
00070 /*-----------------------------------------------------------------------------------*/
00071 void cleanup_module(void){
00072   printk("\n Socket TCP echo client module removed\n");
00073 }

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