[f3b4c5a] | 1 | /* |
---|
| 2 | * clientUdp.c : generate an executable to test the UDP Sockets. |
---|
| 3 | * the RTEMS target must be configured as server. |
---|
| 4 | * Don't forget to change the IP address. |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | #include <stdio.h> |
---|
| 9 | #include <string.h> |
---|
| 10 | #include <errno.h> |
---|
| 11 | #include <sys/time.h> |
---|
| 12 | |
---|
| 13 | #include <sys/param.h> |
---|
| 14 | #include <sys/socket.h> |
---|
| 15 | #include <sys/file.h> |
---|
| 16 | |
---|
| 17 | #include <netinet/in_systm.h> |
---|
| 18 | #include <netinet/in.h> |
---|
| 19 | #include <netinet/ip.h> |
---|
| 20 | #include <arpa/inet.h> |
---|
| 21 | |
---|
| 22 | #include "../buffer.h" |
---|
| 23 | |
---|
| 24 | #define DEFAULT_IP "194.2.81.61" |
---|
| 25 | #define DEFAULT_LISTEN_IP "194.2.81.126" |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | int main(int argc, char** argv) |
---|
| 29 | { |
---|
| 30 | int sd; |
---|
| 31 | struct sockaddr_in server; |
---|
| 32 | int i; |
---|
| 33 | char *tabChar; |
---|
| 34 | char *server_name= "localhost"; |
---|
| 35 | unsigned short port; |
---|
| 36 | unsigned long lenChar; |
---|
| 37 | struct timespec timeToWait, timeRem; |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | printf("main begin...\n"); |
---|
| 41 | port = DEFAULT_PORT_SERVER; |
---|
| 42 | server_name = DEFAULT_IP; |
---|
| 43 | |
---|
| 44 | bzero(&server, sizeof(server)); |
---|
| 45 | |
---|
| 46 | sd = socket (AF_INET,SOCK_DGRAM,0); |
---|
| 47 | if (inet_aton (server_name, (struct in_addr*)&(server.sin_addr.s_addr)) == 0) { |
---|
| 48 | printf("%s : IP address: bad format\n", |
---|
| 49 | argv[0]); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | server.sin_family = AF_INET; |
---|
| 53 | server.sin_port = htons(port); |
---|
| 54 | |
---|
| 55 | printf("server : %X port : %X\n", server.sin_addr.s_addr, server.sin_port); |
---|
| 56 | |
---|
| 57 | while(1) { |
---|
| 58 | |
---|
| 59 | tabChar = BuildBuffer(); |
---|
| 60 | lenChar = *((unsigned long *)(tabChar)); |
---|
| 61 | i = sendto(sd, tabChar, lenChar, 0, (struct sockaddr *)&server, sizeof(server)); |
---|
| 62 | |
---|
| 63 | if (i == -1) { |
---|
| 64 | fprintf(stderr,"sendto() failed : %d\n", errno); |
---|
| 65 | return -1; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | timeToWait.tv_sec = 1; |
---|
| 69 | timeToWait.tv_nsec = 0; |
---|
| 70 | nanosleep(&timeToWait, &timeRem); |
---|
| 71 | |
---|
| 72 | FreeBuffer(tabChar); |
---|
| 73 | } |
---|
| 74 | return 0; |
---|
| 75 | } |
---|
| 76 | |
---|