-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaytimetcpcli.c
More file actions
33 lines (26 loc) · 788 Bytes
/
Copy pathdaytimetcpcli.c
File metadata and controls
33 lines (26 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "unp.h"
#include <stdio.h>
int
main(int argc, char **argv)
{
int sockfd, n, npend;
char recvline[MAXLINE + 1];
socklen_t len;
struct sockaddr_storage ss;
if (argc != 3)
err_quit("usage: a.out <hostname or IPaddress> <service or port#>");
sockfd = Tcp_connect(argv[1], argv[2]);
len = sizeof(ss);
Getpeername(sockfd, (SA *)&ss, &len);
printf("connected to %s\n", Sock_ntop_host((SA *)&ss, len));
for ( ; ; ) {
if ( (n = Recv(sockfd, recvline, MAXLINE, MSG_PEEK)) == 0)
break; /* server closed connection */
Ioctl(sockfd, FIONREAD, &npend); /* check FIONREAD support */
printf("%d bytes from PEEK, %d bytes pending\n", n, npend);
n = Read(sockfd, recvline, MAXLINE);
recvline[n] = 0; /* null terminate */
Fputs(recvline, stdout);
}
exit(0);
}