forked from unpbook/unpv13e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prdefaults.c
59 lines (46 loc) · 1.45 KB
/
prdefaults.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "unp.h"
static doit(int, const char *);
void
main()
{
int tcpsock, udpsock;
struct sockaddr_in servaddr;
if ( (tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
err_sys("TCP socket error");
#ifdef notdef
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(9);
if (ascii2addr(AF_INET, "127.0.0.1", &servaddr.sin_addr) != 4)
err_quit("ascii2addr error");
if (connect(tcpsock, (SA *) &servaddr, sizeof(servaddr)) < 0)
err_sys("connect error");
#endif
doit(tcpsock, "tcp");
if ( (udpsock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
err_sys("UDP socket error");
doit(udpsock, "udp");
exit(0);
}
static
doit(int fd, const char *name)
{
int val;
socklen_t optlen;
optlen = sizeof(val);
if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &optlen) < 0)
err_sys("SO_SNDBUF getsockopt error");
printf("%s send buffer size = %d\n", name, val);
optlen = sizeof(val);
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &optlen) < 0)
err_sys("SO_RCVBUF getsockopt error");
printf("%s recv buffer size = %d\n", name, val);
optlen = sizeof(val);
if (getsockopt(fd, SOL_SOCKET, SO_SNDLOWAT, &val, &optlen) < 0)
err_sys("SO_SNDLOWAT getsockopt error");
printf("%s send low-water mark = %d\n", name, val);
optlen = sizeof(val);
if (getsockopt(fd, SOL_SOCKET, SO_RCVLOWAT, &val, &optlen) < 0)
err_sys("SO_RCVLOWAT getsockopt error");
printf("%s receive low-water mark size = %d\n", name, val);
}