comparison packet.c @ 568:005530560594

Rearrange getaddrstring() etc
author Matt Johnston <matt@ucc.asn.au>
date Tue, 01 Sep 2009 16:38:26 +0000
parents ccdc4c6183c0
children afb089e70892
comparison
equal deleted inserted replaced
567:893a9dd0b9dd 568:005530560594
155 /* Returns DROPBEAR_SUCCESS if the length is determined, 155 /* Returns DROPBEAR_SUCCESS if the length is determined,
156 * DROPBEAR_FAILURE otherwise */ 156 * DROPBEAR_FAILURE otherwise */
157 static int read_packet_init() { 157 static int read_packet_init() {
158 158
159 unsigned int maxlen; 159 unsigned int maxlen;
160 int len; 160 int slen;
161 unsigned char blocksize; 161 unsigned int len;
162 unsigned char macsize; 162 unsigned int blocksize;
163 unsigned int macsize;
163 164
164 165
165 blocksize = ses.keys->recv.algo_crypt->blocksize; 166 blocksize = ses.keys->recv.algo_crypt->blocksize;
166 macsize = ses.keys->recv.algo_mac->hashsize; 167 macsize = ses.keys->recv.algo_mac->hashsize;
167 168
171 } 172 }
172 173
173 maxlen = blocksize - ses.readbuf->pos; 174 maxlen = blocksize - ses.readbuf->pos;
174 175
175 /* read the rest of the packet if possible */ 176 /* read the rest of the packet if possible */
176 len = read(ses.sock_in, buf_getwriteptr(ses.readbuf, maxlen), 177 slen = read(ses.sock_in, buf_getwriteptr(ses.readbuf, maxlen),
177 maxlen); 178 maxlen);
178 if (len == 0) { 179 if (slen == 0) {
179 ses.remoteclosed(); 180 ses.remoteclosed();
180 } 181 }
181 if (len < 0) { 182 if (slen < 0) {
182 if (errno == EINTR) { 183 if (errno == EINTR) {
183 TRACE(("leave read_packet_init: EINTR")) 184 TRACE(("leave read_packet_init: EINTR"))
184 return DROPBEAR_FAILURE; 185 return DROPBEAR_FAILURE;
185 } 186 }
186 dropbear_exit("error reading: %s", strerror(errno)); 187 dropbear_exit("error reading: %s", strerror(errno));
187 } 188 }
188 189
189 buf_incrwritepos(ses.readbuf, len); 190 buf_incrwritepos(ses.readbuf, slen);
190 191
191 if ((unsigned int)len != maxlen) { 192 if ((unsigned int)slen != maxlen) {
192 /* don't have enough bytes to determine length, get next time */ 193 /* don't have enough bytes to determine length, get next time */
193 return DROPBEAR_FAILURE; 194 return DROPBEAR_FAILURE;
194 } 195 }
195 196
196 /* now we have the first block, need to get packet length, so we decrypt 197 /* now we have the first block, need to get packet length, so we decrypt