source: network-demos/socket/pgmHost/serverUdp.c @ f3b4c5a

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 f3b4c5a was f3b4c5a, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 11, 1998 at 1:31:51 PM

New test from Emmanuel Raguet <raguet@…>.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 * serverUdp.c : generate an executable to test the UDP Sockets.
3 * the RTEMS target must be configured as client.
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.126"
25#define DEFAULT_LISTEN_IP "194.2.81.61"
26
27int main(int argc, char** argv)
28{
29
30  int   sd;
31  struct   sockaddr_in server, from;
32  int fromlen;
33  char *tabChar;
34  int rc;
35  unsigned long msgId;
36  char *server_name= "localhost";
37  unsigned short port;
38
39   port = DEFAULT_PORT_CLIENT;
40   server_name = DEFAULT_IP;
41
42   bzero(&server, sizeof(server));
43   server.sin_family = AF_INET;
44   inet_aton (server_name, (struct in_addr*)&(server.sin_addr.s_addr));
45
46   server.sin_port = htons(port);
47
48   sd = socket(AF_INET,SOCK_DGRAM, 0);
49   if (sd == -1) {
50     printf(" socket failed errno = %d\n", errno);
51     return 0;
52   }
53 
54   rc = bind(sd, (struct sockaddr *)&server, sizeof(server)) ;
55   if (rc == -1) {
56     printf(" bind failed errno = %d\n", errno);
57     return 0;
58   }
59
60   tabChar = AllocBuffer();
61
62   if(!tabChar) {
63     printf("malloc failed ...\n");
64     return 0;
65     }
66           
67   bzero(&from, sizeof(from));
68   from.sin_family = AF_INET;
69   inet_aton (DEFAULT_LISTEN_IP, (struct in_addr*)&(from.sin_addr.s_addr));
70   fromlen = sizeof(from);
71
72   printf("UDP Server : ready to receive messages...\n");
73
74   msgId = 0; 
75   
76   for(;;){
77     rc=recvfrom(sd, tabChar, SIZE_MAX_RCV_BUFFER, 0, (struct sockaddr *)&from, &fromlen);
78
79     if (rc < 0) {
80       printf("\n Recvfrom error %d\n\n",errno);
81     }
82     else{
83       msgId = CheckBuffer(tabChar);
84     }
85     if (msgId == 0)
86       break ;
87   }
88
89   FreeBuffer(tabChar);
90   return 0;
91} 
92
Note: See TracBrowser for help on using the repository browser.