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