Sample udp receive program – Proxima ASA 7911 User Manual

Page 102

Advertising
background image

96

Sample UDP Receive Program

1 /********************************************************
2 * udprecv.c
3 * Receives a series of messages from a Serial Adapter using UDP.
4 *
5 *******************************************************/
6
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <stdio.h>
11
12 main()
13 {
14 int sock, length, nbytes;
15 struct sockaddr_in name;
16 char buf[1024];
17 FILE *logfile;
18
19 /* Open the log file */
20 logfile= fopen(“proxlink.log”, “wb”);
21 if (!logfile) {
22

printf(“Error: Couldn’t open log file\n”);

23

exit(4);

24 }
25
26 /* Create socket from which to read */
27 sock= socket(AF_INET, SOCK_DGRAM, 0);
28 if (sock < 0) {
29

perror(“opening datagram socket”);

30

exit(1);

31 }
32
33 /* Create a name with “wildcards”: The machine will assign its
34 IP address and a port number. */
35 name.sin_family= AF_INET;
36 name.sin_addr.s_addr= INADDR_ANY;
37 name.sin_port= 0;
38
39 /* The bind() call associates a local IP address and port number
40 with the socket */

Advertising
This manual is related to the following products: