summaryrefslogtreecommitdiff
path: root/packet.c
diff options
context:
space:
mode:
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 3e2d1249d..17673f920 100644
--- a/packet.c
+++ b/packet.c
@@ -77,6 +77,8 @@ RCSID("$OpenBSD: packet.c,v 1.102 2002/12/10 19:47:14 markus 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,7 +133,7 @@ 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 139
@@ -139,6 +141,7 @@ packet_set_connection(int fd_in, int fd_out)
139 fatal("packet_set_connection: cannot load cipher 'none'"); 141 fatal("packet_set_connection: cannot load cipher 'none'");
140 connection_in = fd_in; 142 connection_in = fd_in;
141 connection_out = fd_out; 143 connection_out = fd_out;
144 setup_timeout = new_setup_timeout;
142 cipher_init(&send_context, none, "", 0, NULL, 0, CIPHER_ENCRYPT); 145 cipher_init(&send_context, none, "", 0, NULL, 0, CIPHER_ENCRYPT);
143 cipher_init(&receive_context, none, "", 0, NULL, 0, CIPHER_DECRYPT); 146 cipher_init(&receive_context, none, "", 0, NULL, 0, CIPHER_DECRYPT);
144 newkeys[MODE_IN] = newkeys[MODE_OUT] = NULL; 147 newkeys[MODE_IN] = newkeys[MODE_OUT] = NULL;
@@ -745,6 +748,7 @@ packet_read_seqnr(u_int32_t *seqnr_p)
745 int type, len; 748 int type, len;
746 fd_set *setp; 749 fd_set *setp;
747 char buf[8192]; 750 char buf[8192];
751 struct timeval tv, *tvp;
748 DBG(debug("packet_read()")); 752 DBG(debug("packet_read()"));
749 753
750 setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) * 754 setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) *
@@ -776,11 +780,21 @@ packet_read_seqnr(u_int32_t *seqnr_p)
776 sizeof(fd_mask)); 780 sizeof(fd_mask));
777 FD_SET(connection_in, setp); 781 FD_SET(connection_in, setp);
778 782
783 if (setup_timeout > 0) {
784 tvp = &tv;
785 tv.tv_sec = setup_timeout;
786 tv.tv_usec = 0;
787 } else
788 tvp = 0;
789
779 /* Wait for some data to arrive. */ 790 /* Wait for some data to arrive. */
780 while (select(connection_in + 1, setp, NULL, NULL, NULL) == -1 && 791 while (select(connection_in + 1, setp, NULL, NULL, tvp) == -1 &&
781 (errno == EAGAIN || errno == EINTR)) 792 (errno == EAGAIN || errno == EINTR))
782 ; 793 ;
783 794
795 if (!FD_ISSET(connection_in, setp))
796 fatal("packet_read: Setup timeout expired, giving up");
797
784 /* Read data from the socket. */ 798 /* Read data from the socket. */
785 len = read(connection_in, buf, sizeof(buf)); 799 len = read(connection_in, buf, sizeof(buf));
786 if (len == 0) { 800 if (len == 0) {