00001
00002
00003
00004
00005
00006
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
00017
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
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
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 }