[BACK]Return to tftp.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tftp

Diff for /src/usr.bin/tftp/tftp.c between version 1.23 and 1.24

version 1.23, 2012/05/01 04:23:21 version 1.24, 2014/10/21 06:15:16
Line 132 
Line 132 
         unsigned long            amount;          unsigned long            amount;
         socklen_t                fromlen;          socklen_t                fromlen;
         int                      convert; /* true if converting crlf -> lf */          int                      convert; /* true if converting crlf -> lf */
         int                      n, nfds, error, timeouts, block, size;          int                      n, nfds, error, timeouts, size;
           uint16_t                 block = 0;
           int                      firsttrip = 1;
   
         startclock();           /* start stat's clock */          startclock();           /* start stat's clock */
         dp = r_init();          /* reset fillbuf/read-ahead code */          dp = r_init();          /* reset fillbuf/read-ahead code */
         ap = (struct tftphdr *)ackbuf;          ap = (struct tftphdr *)ackbuf;
         file = fdopen(fd, "r");          file = fdopen(fd, "r");
         convert = !strcmp(mode, "netascii");          convert = !strcmp(mode, "netascii");
         block = 0;  
         amount = 0;          amount = 0;
         memcpy(&peer, &peeraddr, peeraddr.ss_len);          memcpy(&peer, &peeraddr, peeraddr.ss_len);
         memset(&serv, 0, sizeof(serv));          memset(&serv, 0, sizeof(serv));
   
         do {          do {
                 /* read data from file */                  /* read data from file */
                 if (!block)                  if (firsttrip)
                         size = makerequest(WRQ, name, dp, mode) - 4;                          size = makerequest(WRQ, name, dp, mode) - 4;
                 else {                  else {
                         size = readit(file, &dp, convert, segment_size);                          size = readit(file, &dp, convert, segment_size);
Line 155 
Line 156 
                                 break;                                  break;
                         }                          }
                         dp->th_opcode = htons((u_short)DATA);                          dp->th_opcode = htons((u_short)DATA);
                         dp->th_block = htons((u_short)block);                          dp->th_block = htons(block);
                 }                  }
   
                 /* send data to server and wait for server ACK */                  /* send data to server and wait for server ACK */
Line 174 
Line 175 
                                         warn("sendto");                                          warn("sendto");
                                         goto abort;                                          goto abort;
                                 }                                  }
                                 if (block > 0)                                  if (!firsttrip)
                                         read_ahead(file, convert, segment_size);                                          read_ahead(file, convert, segment_size);
                         }                          }
                         error = 0;                          error = 0;
Line 246 
Line 247 
                         error = 1;      /* received packet does not match */                          error = 1;      /* received packet does not match */
                 }                  }
   
                 if (block > 0)                  if (firsttrip) {
                           size = segment_size;
                           firsttrip = 0;
                   } else
                         amount += size;                          amount += size;
                 block++;                  block++;
         } while ((size == segment_size || block == 1) && !intrflag);          } while ((size == segment_size) && !intrflag);
   
 abort:  abort:
         fclose(file);          fclose(file);
Line 274 
Line 278 
         unsigned long            amount;          unsigned long            amount;
         socklen_t                fromlen;          socklen_t                fromlen;
         int                      convert; /* true if converting crlf -> lf */          int                      convert; /* true if converting crlf -> lf */
         int                      n, nfds, error, timeouts, block, size;          int                      n, nfds, error, timeouts, size;
         int                      firsttrip;          int                      firsttrip;
           uint16_t                 block;
   
         startclock();           /* start stat's clock */          startclock();           /* start stat's clock */
         dp = w_init();          /* reset fillbuf/read-ahead code */          dp = w_init();          /* reset fillbuf/read-ahead code */
Line 297 
Line 302 
                         firsttrip = 0;                          firsttrip = 0;
                 } else {                  } else {
                         ap->th_opcode = htons((u_short)ACK);                          ap->th_opcode = htons((u_short)ACK);
                         ap->th_block = htons((u_short)(block));                          ap->th_block = htons(block);
                         size = 4;                          size = 4;
                         block++;                          block++;
                 }                  }
Line 402 
Line 407 
 abort:  abort:
         /* ok to ack, since user has seen err msg */          /* ok to ack, since user has seen err msg */
         ap->th_opcode = htons((u_short)ACK);          ap->th_opcode = htons((u_short)ACK);
         ap->th_block = htons((u_short)block);          ap->th_block = htons(block);
         (void)sendto(f, ackbuf, 4, 0, (struct sockaddr *)&peer,          (void)sendto(f, ackbuf, 4, 0, (struct sockaddr *)&peer,
             peer.ss_len);              peer.ss_len);
         write_behind(file, convert);    /* flush last buffer */          write_behind(file, convert);    /* flush last buffer */

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24