Proxima ASA 7911 User Manual
Page 98
92
23
24
25 /* Open the log file */
26 logfile= fopen(“proxlink.log”, “wb”);
27 if (!logfile) {
28
printf(“Error: Couldn’t open log file\n”);
29
exit(1);
30 }
31
32 /* Create socket */
33 sock= socket(AF_INET, SOCK_STREAM, 0);
34 if (sock < 0) {
35
perror(“opening stream socket”);
36
exit(2);
37 }
38
39 /* Create a name with wildcards */
40 server.sin_family= AF_INET;
41 server.sin_addr.s_addr= INADDR_ANY;
42 server.sin_port= 0;
43 if (bind(sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
44
perror(“binding stream socket”);
45
exit(3);
46 }
47
48 /* Find assigned port number and print it out */
49 length= sizeof(server);
50 if (getsockname(sock, (struct sockaddr *)&server, &length) < 0) {
51
perror(“getting socket name”);
52
exit(4);
53 }
54
55 printf(“Socket port #%d\n”, ntohs(server.sin_port));
56
57 /* Start accepting connections. Listen() will return when it
58 determines that a remote machine is trying to open a
59 connection. The second parameter to listen() is a queue
60 length, which is the maximum number of pending connections
61 allowed on that socket at any given time.
62 */
63 do {
64
listen(sock, 5);