Lines Matching refs:transfer
22 static void free_transfer(struct tftp_transfer *transfer);
25 static ssize_t get_block(char *packet, struct tftp_transfer *transfer);
52 struct tftp_transfer *transfer; in tftp_request() local
144 if (!(transfer = whine_malloc(sizeof(struct tftp_transfer)))) in tftp_request()
147 if ((transfer->sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) in tftp_request()
149 free(transfer); in tftp_request()
153 transfer->peer = peer; in tftp_request()
154 transfer->timeout = now + 2; in tftp_request()
155 transfer->backoff = 1; in tftp_request()
156 transfer->block = 1; in tftp_request()
157 transfer->blocksize = 512; in tftp_request()
158 transfer->offset = 0; in tftp_request()
159 transfer->file = NULL; in tftp_request()
160 transfer->opt_blocksize = transfer->opt_transize = 0; in tftp_request()
161 transfer->netascii = transfer->carrylf = 0; in tftp_request()
166 if (bind(transfer->sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1 || in tftp_request()
168 setsockopt(transfer->sockfd, SOL_IP, IP_MTU_DISCOVER, &mtuflag, sizeof(mtuflag)) == -1 || in tftp_request()
170 !fix_fd(transfer->sockfd)) in tftp_request()
181 free_transfer(transfer); in tftp_request()
198 transfer->netascii = 1; in tftp_request()
207 transfer->blocksize = atoi(opt); in tftp_request()
208 if (transfer->blocksize < 1) in tftp_request()
209 transfer->blocksize = 1; in tftp_request()
210 if (transfer->blocksize > (unsigned)daemon->packet_buff_sz - 4) in tftp_request()
211 transfer->blocksize = (unsigned)daemon->packet_buff_sz - 4; in tftp_request()
213 if (mtu != 0 && transfer->blocksize > (unsigned)mtu - 32) in tftp_request()
214 transfer->blocksize = (unsigned)mtu - 32; in tftp_request()
215 transfer->opt_blocksize = 1; in tftp_request()
216 transfer->block = 0; in tftp_request()
219 else if (strcasecmp(opt, "tsize") == 0 && next(&p, end) && !transfer->netascii) in tftp_request()
221 transfer->opt_transize = 1; in tftp_request()
222 transfer->block = 0; in tftp_request()
266 if ((transfer->file = check_tftp_fileperm(&len))) in tftp_request()
268 if ((len = get_block(packet, transfer)) == -1) in tftp_request()
275 while (sendto(transfer->sockfd, packet, len, 0, in tftp_request()
279 free_transfer(transfer); in tftp_request()
283 transfer->next = daemon->tftp_trans; in tftp_request()
284 daemon->tftp_trans = transfer; in tftp_request()
373 struct tftp_transfer *transfer, *tmp, **up; in check_tftp_listeners() local
381 for (transfer = daemon->tftp_trans, up = &daemon->tftp_trans; transfer; transfer = tmp) in check_tftp_listeners()
383 tmp = transfer->next; in check_tftp_listeners()
385 if (FD_ISSET(transfer->sockfd, rset)) in check_tftp_listeners()
390 …if ((len = recv(transfer->sockfd, daemon->packet, daemon->packet_buff_sz, 0)) >= (ssize_t)sizeof(s… in check_tftp_listeners()
392 if (ntohs(mess->op) == OP_ACK && ntohs(mess->block) == (unsigned short)transfer->block) in check_tftp_listeners()
395 transfer->timeout = now; in check_tftp_listeners()
396 transfer->backoff = 0; in check_tftp_listeners()
397 if (transfer->block++ != 0) in check_tftp_listeners()
398 transfer->offset += transfer->blocksize - transfer->expansion; in check_tftp_listeners()
418 inet_ntoa(transfer->peer.sin_addr)); in check_tftp_listeners()
421 transfer->timeout = now; in check_tftp_listeners()
422 transfer->backoff = 100; in check_tftp_listeners()
427 if (difftime(now, transfer->timeout) >= 0.0) in check_tftp_listeners()
432 transfer->timeout += 1 + (1<<transfer->backoff); in check_tftp_listeners()
437 if ((len = get_block(daemon->packet, transfer)) == -1) in check_tftp_listeners()
439 len = tftp_err_oops(daemon->packet, transfer->file->filename); in check_tftp_listeners()
442 else if (++transfer->backoff > 5) in check_tftp_listeners()
448 transfer->file->filename, inet_ntoa(transfer->peer.sin_addr)); in check_tftp_listeners()
453 while(sendto(transfer->sockfd, daemon->packet, len, 0, in check_tftp_listeners()
454 (struct sockaddr *)&transfer->peer, sizeof(transfer->peer)) == -1 && errno == EINTR); in check_tftp_listeners()
460 free_transfer(transfer); in check_tftp_listeners()
465 up = &transfer->next; in check_tftp_listeners()
469 static void free_transfer(struct tftp_transfer *transfer) in free_transfer() argument
471 close(transfer->sockfd); in free_transfer()
472 if (transfer->file && (--transfer->file->refcount) == 0) in free_transfer()
474 close(transfer->file->fd); in free_transfer()
475 free(transfer->file); in free_transfer()
477 free(transfer); in free_transfer()
517 static ssize_t get_block(char *packet, struct tftp_transfer *transfer) in get_block() argument
519 if (transfer->block == 0) in get_block()
530 if (transfer->opt_blocksize) in get_block()
533 p += (sprintf(p, "%d", transfer->blocksize) + 1); in get_block()
535 if (transfer->opt_transize) in get_block()
538 p += (sprintf(p, "%u", (unsigned int)transfer->file->size) + 1); in get_block()
551 size_t size = transfer->file->size - transfer->offset; in get_block()
553 if (transfer->offset > transfer->file->size) in get_block()
556 if (size > transfer->blocksize) in get_block()
557 size = transfer->blocksize; in get_block()
560 mess->block = htons((unsigned short)(transfer->block)); in get_block()
562 if (lseek(transfer->file->fd, transfer->offset, SEEK_SET) == (off_t)-1 || in get_block()
563 !read_write(transfer->file->fd, mess->data, size, 1)) in get_block()
566 transfer->expansion = 0; in get_block()
569 if (transfer->netascii) in get_block()
575 if (mess->data[i] == '\n' && ( i != 0 || !transfer->carrylf)) in get_block()
577 if (size == transfer->blocksize) in get_block()
579 transfer->expansion++; in get_block()
592 transfer->carrylf = newcarrylf; in get_block()