--- openssh-hpn.orig/sshconnect.c	2005-08-04 22:37:10.000000000 +1000
+++ openssh-hpn/sshconnect.c	2005-08-04 21:59:37.000000000 +1000
@@ -145,6 +145,27 @@
 }
 
 /*
+ * Set TCP receive buffer if requested.
+ * Note: tuning needs to happen after the socket is
+ * created but before the connection happens
+ * so winscale is negotiated properly -cjr
+ */
+static void
+ssh_set_socket_recvbuf(int sock)
+{
+	void *buf = (void *)&options.tcp_rcv_buf;
+	int sz = sizeof(options.tcp_rcv_buf);
+
+	if (options.tcp_rcv_buf == 0)
+		return;
+	if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, buf, sz) >= 0)
+		debug("setsockopt SO_RCVBUF set to %d", options.tcp_rcv_buf);
+	else
+		error("Couldn't set socket receive buffer to %d: %.100s",
+		    options.tcp_rcv_buf, strerror(errno));
+}
+
+/*
  * Creates a (possibly privileged) socket for use as the ssh connection.
  */
 static int
@@ -167,58 +188,16 @@
 			    strerror(errno));
 		else
 			debug("Allocated local port %d.", p);
-
-		
-		/* tuning needs to happen after the socket is */
-		/* created but before the connection happens */
-		/* so winscale is negotiated properly -cjr */
-		
-		/* Set tcp receive buffer if requested */
-		if (options.tcp_rcv_buf) 
-		  {
-		    if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, 
-				   (void *)&options.tcp_rcv_buf, 
-				   sizeof(options.tcp_rcv_buf)) >= 0)
-		      {             
-			debug("setsockopt SO_RCVBUF: %.100s", strerror(errno));
-		      } 
-		    else 
-		      {
-			/* coudln't set the socket size to use spec. */
-			/* should default to system param and continue */
-			/* warn the user though - cjr */
-			error("Couldn't set socket receive buffer as requested. Continuing anyway.");
-		      }
-		  }
+		ssh_set_socket_recvbuf(sock);
 		return sock;
 	}
 	sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
 	if (sock < 0)
 		error("socket: %.100s", strerror(errno));
-	
-	/* tuning needs to happen after the socket is */
-	/* created but before the connection happens */
-	/* so winscale is negotiated properly -cjr */
-	
-	/* Set tcp receive buffer if requested */
-	if (options.tcp_rcv_buf) 
-	  {
-	    if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, 
-			   (void *)&options.tcp_rcv_buf, 
-			   sizeof(options.tcp_rcv_buf)) >= 0)
-	      {             
-		debug("setsockopt SO_RCVBUF: %.100s", strerror(errno));
-	      }
-	    else 
-	      {
-		/* coudln't set the socket size to use spec. */
-		/* should default to system param and continue */
-		/* warn the user though - cjr */
-		error("Couldn't set socket receive buffer as requested. Continuing anyway.");
-	      }
-	  }
-	
-       	/* Bind the socket to an alternative local IP address */
+
+	ssh_set_socket_recvbuf(sock);
+
+	/* Bind the socket to an alternative local IP address */
 	if (options.bind_address == NULL)
 		return sock;
 
--- openssh-hpn.orig/buffer.h	2005-08-04 22:37:10.000000000 +1000
+++ openssh-hpn/buffer.h	2005-08-04 21:08:22.000000000 +1000
@@ -25,7 +25,7 @@
 
 #define	BUFFER_MAX_CHUNK	0x100000
 #define	BUFFER_MAX_LEN		0xa00000
-#define BUFFER_MAX_HPN_LEN	(2>>29)-1
+#define BUFFER_MAX_HPN_LEN	((2U>>29)-1)
 
 void	 buffer_init(Buffer *);
 void	 buffer_clear(Buffer *);
--- openssh-hpn.orig/channels.h	2005-08-04 22:37:10.000000000 +1000
+++ openssh-hpn/channels.h	2005-08-04 23:10:08.000000000 +1000
@@ -120,11 +120,11 @@
 
 /* default window/packet sizes for tcp/x11-fwd-channel */
 #define CHAN_SES_PACKET_DEFAULT	(32*1024)
-#define CHAN_SES_WINDOW_DEFAULT	(0xa00000/2)
+#define CHAN_SES_WINDOW_DEFAULT	(BUFFER_MAX_LEN/2)
 #define CHAN_TCP_PACKET_DEFAULT	(32*1024)
-#define CHAN_TCP_WINDOW_DEFAULT	(0xa00000/2)
+#define CHAN_TCP_WINDOW_DEFAULT	(BUFFER_MAX_LEN/2)
 #define CHAN_X11_PACKET_DEFAULT	(16*1024)
-#define CHAN_X11_WINDOW_DEFAULT	(0xa00000/2)
+#define CHAN_X11_WINDOW_DEFAULT	(BUFFER_MAX_LEN/2)
 
 /* possible input states */
 #define CHAN_INPUT_OPEN			0
