Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / inet_windowsize.c
blob21f7db6a05e2fbf895abb1d5163051d6d4148788
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* inet_windowsize 3
6 /* SUMMARY
7 /* TCP window scaling control
8 /* SYNOPSIS
9 /* #include <iostuff.h>
11 /* int inet_windowsize;
13 /* void set_inet_windowsize(sock, windowsize)
14 /* int sock;
15 /* int windowsize;
16 /* DESCRIPTION
17 /* set_inet_windowsize() overrides the default TCP window size
18 /* with the specified value. When called before listen() or
19 /* accept(), this works around broken infrastructure that
20 /* mis-handles TCP window scaling options.
22 /* The global inet_windowsize variable is available for other
23 /* routines to remember that they wish to override the default
24 /* TCP window size. The variable is not accessed by the
25 /* set_inet_windowsize() function itself.
27 /* Arguments:
28 /* .IP sock
29 /* TCP communication endpoint, before the connect(2) or listen(2) call.
30 /* .IP windowsize
31 /* The preferred TCP window size. This must be > 0.
32 /* DIAGNOSTICS
33 /* Panic: interface violation.
34 /* Warnings: some error return from setsockopt().
35 /* LICENSE
36 /* .ad
37 /* .fi
38 /* The Secure Mailer license must be distributed with this software.
39 /* AUTHOR(S)
40 /* Wietse Venema
41 /* IBM T.J. Watson Research
42 /* P.O. Box 704
43 /* Yorktown Heights, NY 10598, USA
44 /*--*/
46 /* System libraries. */
48 #include <sys_defs.h>
49 #include <sys/socket.h>
51 /* Utility library. */
53 #include <msg.h>
54 #include <iostuff.h>
56 /* Application storage. */
59 * Tunable to work around broken routers.
61 int inet_windowsize = 0;
63 /* set_inet_windowsize - set TCP send/receive window size */
65 void set_inet_windowsize(int sock, int windowsize)
69 * Sanity check.
71 if (windowsize <= 0)
72 msg_panic("inet_windowsize: bad window size %d", windowsize);
75 * Generic implementation: set the send and receive buffer size before
76 * listen() or connect().
78 if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *) &windowsize,
79 sizeof(windowsize)) < 0)
80 msg_warn("setsockopt SO_SNDBUF %d: %m", windowsize);
81 if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *) &windowsize,
82 sizeof(windowsize)) < 0)
83 msg_warn("setsockopt SO_RCVBUF %d: %m", windowsize);