Proxima ASA 7910 Network Card User Manual


 
93
65 /* Establish the TCP connection. Accept() returns a new
66 socket number for the connection, allowing listen() to
67 (if desired) continue to listen on the old socket.
68
69 Parameters to accept() are: the socket that the
70 previous listen() call was using, a sockaddr structure,
71 and the length of the sockaddr structure. The second
72 and third parameters are zero here, but can be used to
73 get the IP address and port number of the remote end of
74 the connection. */
75 msgsock= accept(sock, (struct sockaddr *)0, (int *)0);
76 if (msgsock==-1) {
77 perror(“accept”);
78 }
79 else do {
80 memset(buf, 0, sizeof(buf));
81 if ((rval= read(msgsock, buf, 1024)) < 0)
82 {
83 perror(“reading stream message”);
84 exit(5);
85 }
86 else if (rval==0) {
87 printf(“Read zero bytes. Exiting...\n”);
88 exit(6);
89 }
90 else {
91 /* Print out data on screen and log it to the logfile.
92 Note we are skipping the Serial Adapter header bytes. */
93 printf(“Read %d bytes\n”, rval);
94 buf[rval]= ‘\0’;
95 if (rval > 4)
96 printf(“Data: —> %s\n”, buf+4);
97 for (i= 0; i< rval; i++)
98 fputc(*(buf+i), logfile);
99 fclose(logfile);
100 logfile= fopen(“proxlink.log”, “ab”);
101 }
102 } while (TRUE);
103
104 } while (TRUE);
105 }