summaryrefslogtreecommitdiff
path: root/packet.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2003-09-01 00:51:03 +0000
committerColin Watson <cjwatson@debian.org>2003-09-01 00:51:03 +0000
commit79cf0b3654d7b597de323153eb57015cdfbd90a4 (patch)
tree274e78bc3369e218e59aa1fcc9b7e90697f424f1 /packet.c
parentd984a3c6658e950881edcfb2aae464add93f68d4 (diff)
Debian release 3.4p1-1.
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/packet.c b/packet.c
index a5b2ab61a..273ffea58 100644
--- a/packet.c
+++ b/packet.c
@@ -77,6 +77,8 @@ RCSID("$OpenBSD: packet.c,v 1.96 2002/06/23 21:10:02 deraadt Exp $");
77static int connection_in = -1; 77static int connection_in = -1;
78static int connection_out = -1; 78static int connection_out = -1;
79 79
80static int setup_timeout = -1;
81
80/* Protocol flags for the remote side. */ 82/* Protocol flags for the remote side. */
81static u_int remote_protocol_flags = 0; 83static u_int remote_protocol_flags = 0;
82 84
@@ -131,13 +133,14 @@ static u_char extra_pad = 0;
131 * packet_set_encryption_key is called. 133 * packet_set_encryption_key is called.
132 */ 134 */
133void 135void
134packet_set_connection(int fd_in, int fd_out) 136packet_set_connection(int fd_in, int fd_out, int new_setup_timeout)
135{ 137{
136 Cipher *none = cipher_by_name("none"); 138 Cipher *none = cipher_by_name("none");
137 if (none == NULL) 139 if (none == NULL)
138 fatal("packet_set_connection: cannot load cipher 'none'"); 140 fatal("packet_set_connection: cannot load cipher 'none'");
139 connection_in = fd_in; 141 connection_in = fd_in;
140 connection_out = fd_out; 142 connection_out = fd_out;
143 setup_timeout = new_setup_timeout;
141 cipher_init(&send_context, none, "", 0, NULL, 0, CIPHER_ENCRYPT); 144 cipher_init(&send_context, none, "", 0, NULL, 0, CIPHER_ENCRYPT);
142 cipher_init(&receive_context, none, "", 0, NULL, 0, CIPHER_DECRYPT); 145 cipher_init(&receive_context, none, "", 0, NULL, 0, CIPHER_DECRYPT);
143 newkeys[MODE_IN] = newkeys[MODE_OUT] = NULL; 146 newkeys[MODE_IN] = newkeys[MODE_OUT] = NULL;
@@ -742,6 +745,7 @@ packet_read_seqnr(u_int32_t *seqnr_p)
742 int type, len; 745 int type, len;
743 fd_set *setp; 746 fd_set *setp;
744 char buf[8192]; 747 char buf[8192];
748 struct timeval tv, *tvp;
745 DBG(debug("packet_read()")); 749 DBG(debug("packet_read()"));
746 750
747 setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) * 751 setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) *
@@ -773,11 +777,21 @@ packet_read_seqnr(u_int32_t *seqnr_p)
773 sizeof(fd_mask)); 777 sizeof(fd_mask));
774 FD_SET(connection_in, setp); 778 FD_SET(connection_in, setp);
775 779
780 if (setup_timeout > 0) {
781 tvp = &tv;
782 tv.tv_sec = setup_timeout;
783 tv.tv_usec = 0;
784 } else
785 tvp = 0;
786
776 /* Wait for some data to arrive. */ 787 /* Wait for some data to arrive. */
777 while (select(connection_in + 1, setp, NULL, NULL, NULL) == -1 && 788 while (select(connection_in + 1, setp, NULL, NULL, tvp) == -1 &&
778 (errno == EAGAIN || errno == EINTR)) 789 (errno == EAGAIN || errno == EINTR))
779 ; 790 ;
780 791
792 if (!FD_ISSET(connection_in, setp))
793 fatal("packet_read: Setup timeout expired, giving up");
794
781 /* Read data from the socket. */ 795 /* Read data from the socket. */
782 len = read(connection_in, buf, sizeof(buf)); 796 len = read(connection_in, buf, sizeof(buf));
783 if (len == 0) { 797 if (len == 0) {