Proxima ASA 7910, 7911 manual Sample UDP Receive Program

Models: 7911 7910

1 127
Download 127 pages 54.08 Kb
Page 102
Image 102
Sample UDP Receive Program

Sample UDP Receive Program

1/********************************************************

2* udprecv.c

3* Receives a series of messages from a Serial Adapter using UDP.

4*

5*******************************************************/

7#include <sys/types.h>

8#include <sys/socket.h>

9#include <netinet/in.h>

10#include <stdio.h>

12main()

13{

14int sock, length, nbytes;

15struct sockaddr_in name;

16char buf[1024];

17FILE *logfile;

19/* Open the log file */

20logfile= fopen(“proxlink.log”, “wb”);

21if (!logfile) {

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

23exit(4);

24}

25

26/* Create socket from which to read */

27sock= socket(AF_INET, SOCK_DGRAM, 0);

28if (sock < 0) {

29perror(“opening datagram socket”);

30exit(1);

31}

32

33/* Create a name with “wildcards”: The machine will assign its

34IP address and a port number. */

35name.sin_family= AF_INET;

36name.sin_addr.s_addr= INADDR_ANY;

37name.sin_port= 0;

38

39/* The bind() call associates a local IP address and port number

40with the socket */

96

Page 102
Image 102
Proxima ASA 7910, 7911 manual Sample UDP Receive Program