169
169
static CURLcode tftp_disconnect(struct connectdata *conn);
170
170
static CURLcode tftp_do(struct connectdata *conn, bool *done);
171
171
static CURLcode tftp_done(struct connectdata *conn,
172
CURLcode, bool premature);
172
CURLcode, bool premature);
173
173
static CURLcode tftp_setup_connection(struct connectdata * conn);
174
174
static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done);
175
175
static CURLcode tftp_doing(struct connectdata *conn, bool *dophase_done);
375
375
else if(blksize > TFTP_BLKSIZE_MAX) {
376
376
failf(data, "%s (%d)", "blksize is larger than max supported",
378
378
return CURLE_TFTP_ILLEGAL;
380
380
else if(blksize < TFTP_BLKSIZE_MIN) {
381
381
failf(data, "%s (%d)", "blksize is smaller than min supported",
383
383
return CURLE_TFTP_ILLEGAL;
385
385
else if (blksize > state->requested_blksize) {
387
387
* support for the server requesting a bigger blksize than the client
389
389
failf(data, "%s (%ld)",
390
"server requested blksize larger than allocated", blksize);
390
"server requested blksize larger than allocated", blksize);
391
391
return CURLE_TFTP_ILLEGAL;
394
394
state->blksize = (int)blksize;
395
395
infof(data, "%s (%d) %s (%d)\n", "blksize parsed from OACK",
396
state->blksize, "requested", state->requested_blksize);
396
state->blksize, "requested", state->requested_blksize);
398
398
else if(checkprefix(option, TFTP_OPTION_TSIZE)) {
716
716
case TFTP_EVENT_ACK:
717
717
case TFTP_EVENT_OACK:
718
718
if (event == TFTP_EVENT_ACK) {
720
rblock = getrpacketblock(&state->rpacket);
722
if(rblock != state->block) {
723
/* This isn't the expected block. Log it and up the retry counter */
724
infof(data, "Received ACK for block %d, expecting %d\n",
725
rblock, state->block);
727
/* Bail out if over the maximum */
728
if(state->retries>state->retry_max) {
729
failf(data, "tftp_tx: giving up waiting for block %d ack",
731
res = CURLE_SEND_ERROR;
734
/* Re-send the data packet */
735
sbytes = sendto(state->sockfd, (void *)&state->spacket,
736
4+state->sbytes, SEND_4TH_ARG,
737
(struct sockaddr *)&state->remote_addr,
738
state->remote_addrlen);
739
/* Check all sbytes were sent */
741
failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
742
res = CURLE_SEND_ERROR;
747
/* This is the expected packet. Reset the counters and send the next
749
time(&state->rx_time);
753
state->block = 1; /* first data block is 1 when using OACK */
720
rblock = getrpacketblock(&state->rpacket);
722
if(rblock != state->block &&
723
/* There's a bug in tftpd-hpa that causes it to send us an ack for
724
* 65535 when the block number wraps to 0. So when we're expecting
725
* 0, also accept 65535. See
726
* http://syslinux.zytor.com/archives/2010-September/015253.html
728
!(state->block == 0 && rblock == 65535)) {
729
/* This isn't the expected block. Log it and up the retry counter */
730
infof(data, "Received ACK for block %d, expecting %d\n",
731
rblock, state->block);
733
/* Bail out if over the maximum */
734
if(state->retries>state->retry_max) {
735
failf(data, "tftp_tx: giving up waiting for block %d ack",
737
res = CURLE_SEND_ERROR;
740
/* Re-send the data packet */
741
sbytes = sendto(state->sockfd, (void *)&state->spacket,
742
4+state->sbytes, SEND_4TH_ARG,
743
(struct sockaddr *)&state->remote_addr,
744
state->remote_addrlen);
745
/* Check all sbytes were sent */
747
failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
748
res = CURLE_SEND_ERROR;
753
/* This is the expected packet. Reset the counters and send the next
755
time(&state->rx_time);
759
state->block = 1; /* first data block is 1 when using OACK */
755
761
state->retries = 0;
756
762
setpacketevent(&state->spacket, TFTP_EVENT_DATA);
757
763
setpacketblock(&state->spacket, state->block);
1085
1091
/* Receive the packet */
1086
1092
fromlen = sizeof(fromaddr);
1087
1093
state->rbytes = (int)recvfrom(state->sockfd,
1088
(void *)state->rpacket.data,
1091
(struct sockaddr *)&fromaddr,
1094
(void *)state->rpacket.data,
1097
(struct sockaddr *)&fromaddr,
1093
1099
if(state->remote_addrlen==0) {
1094
1100
memcpy(&state->remote_addr, &fromaddr, fromlen);
1095
1101
state->remote_addrlen = fromlen;
1253
1259
/* Force a progress callback if it's been too long */
1254
1260
if (Curl_tvdiff(k->now, k->start) >= data->set.timeout) {
1255
if(Curl_pgrsUpdate(conn)) {
1256
tftp_state_machine(state, TFTP_EVENT_ERROR);
1257
return CURLE_ABORTED_BY_CALLBACK;
1261
if(Curl_pgrsUpdate(conn)) {
1262
tftp_state_machine(state, TFTP_EVENT_ERROR);
1263
return CURLE_ABORTED_BY_CALLBACK;