source: network-demos/socket/pgmHost/clientUdp.c @ 7ba2ac5

4.11netdemos-4-5-branchnetwork-demos-4-10-branchnetwork-demos-4-6-branchnetwork-demos-4-7-branchnetwork-demos-4-8-branchnetwork-demos-4-9-branchrtems-4-5-branch
Last change on this file since 7ba2ac5 was 7ba2ac5, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 21, 1998 at 1:26:06 PM

Added CVS Id Strings which were missing

  • Property mode set to 100644
File size: 1.6 KB
Line 
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 *  $Id$
7 */
8
9
10#include <stdio.h>
11#include <string.h>
12#include <errno.h>
13#include <sys/time.h>
14
15#include <sys/param.h>
16#include <sys/socket.h>
17#include <sys/file.h>
18
19#include <netinet/in_systm.h>
20#include <netinet/in.h>
21#include <netinet/ip.h>
22#include <arpa/inet.h>
23
24#include "../buffer.h"
25
26#define DEFAULT_IP "194.2.81.61"
27#define DEFAULT_LISTEN_IP "194.2.81.126"
28
29
30int main(int argc, char** argv)
31{
32  int     sd;
33  struct  sockaddr_in server;
34  int i;
35  char  *tabChar;
36  char *server_name= "localhost";
37  unsigned short port;
38  unsigned long lenChar;
39  struct timespec timeToWait, timeRem;
40
41 
42  printf("main begin...\n");
43  port = DEFAULT_PORT_SERVER;
44  server_name = DEFAULT_IP;
45 
46  bzero(&server, sizeof(server));
47 
48  sd = socket (AF_INET,SOCK_DGRAM,0);
49  if (inet_aton (server_name, (struct in_addr*)&(server.sin_addr.s_addr)) == 0) {
50    printf("%s : IP address: bad format\n",
51           argv[0]);
52  } 
53
54  server.sin_family = AF_INET;
55  server.sin_port = htons(port);
56 
57  printf("server : %X  port : %X\n", server.sin_addr.s_addr, server.sin_port);
58   
59  while(1) {
60     
61    tabChar = BuildBuffer();
62    lenChar = *((unsigned long *)(tabChar));
63    i = sendto(sd, tabChar, lenChar, 0, (struct sockaddr *)&server, sizeof(server));
64               
65    if (i == -1) {
66      fprintf(stderr,"sendto() failed : %d\n", errno);
67      return -1;
68    }
69
70    timeToWait.tv_sec = 1;
71    timeToWait.tv_nsec = 0;
72    nanosleep(&timeToWait, &timeRem);
73     
74    FreeBuffer(tabChar);
75  }
76  return 0;
77}
78
Note: See TracBrowser for help on using the repository browser.