current = !current; /* "incr" current */
b = &bfs[current]; /* look at new buffer */
- if (b->counter == BF_FREE) /* if it's empty */
+ if(b->counter == BF_FREE) /* if it's empty */
read_ahead(test, convert); /* fill it */
*dpp = &b->buf.hdr; /* set caller's ptr */
/*
* fill the input buffer, doing ascii conversions if requested
- * conversions are lf -> cr,lf and cr -> cr, nul
+ * conversions are lf -> cr, lf and cr -> cr, nul
*/
static void read_ahead(struct testcase *test,
int convert /* if true, convert to ascii */)
struct tftphdr *dp;
b = &bfs[nextone]; /* look at "next" buffer */
- if (b->counter != BF_FREE) /* nop if not free */
+ if(b->counter != BF_FREE) /* nop if not free */
return;
nextone = !nextone; /* "incr" next buffer ptr */
dp = &b->buf.hdr;
- if (convert == 0) {
+ if(convert == 0) {
/* The former file reading code did this:
b->counter = read(fileno(file), dp->th_data, SEGSIZE); */
size_t copy_n = MIN(SEGSIZE, test->rcount);
}
p = dp->th_data;
- for (i = 0 ; i < SEGSIZE; i++) {
- if (newline) {
- if (prevchar == '\n')
+ for(i = 0 ; i < SEGSIZE; i++) {
+ if(newline) {
+ if(prevchar == '\n')
c = '\n'; /* lf to cr,lf */
else
c = '\0'; /* cr to cr,nul */
}
else
break;
- if (c == '\n' || c == '\r') {
+ if(c == '\n' || c == '\r') {
prevchar = c;
c = '\r';
newline = 1;
{
bfs[current].counter = ct; /* set size of data to write */
current = !current; /* switch to other buffer */
- if (bfs[current].counter != BF_FREE) /* if not free */
+ if(bfs[current].counter != BF_FREE) /* if not free */
write_behind(test, convert); /* flush it */
bfs[current].counter = BF_ALLOC; /* mark as alloc'd */
*dpp = &bfs[current].buf.hdr;
/*
* Output a buffer to a file, converting from netascii if requested.
- * CR,NUL -> CR and CR,LF => LF.
+ * CR, NUL -> CR and CR, LF => LF.
* Note spec is undefined if we get CR as last byte of file or a
* CR followed by anything else. In this case we leave it alone.
*/
struct tftphdr *dp;
b = &bfs[nextone];
- if (b->counter < -1) /* anything to flush? */
+ if(b->counter < -1) /* anything to flush? */
return 0; /* just nop if nothing to do */
if(!test->ofile) {
nextone = !nextone; /* incr for next time */
writebuf = dp->th_data;
- if (count <= 0)
+ if(count <= 0)
return -1; /* nak logic? */
- if (convert == 0)
+ if(convert == 0)
return write(test->ofile, writebuf, count);
p = writebuf;
ct = count;
- while (ct--) { /* loop over the buffer */
+ while(ct--) { /* loop over the buffer */
c = *p++; /* pick up a character */
- if (prevchar == '\r') { /* if prev char was cr */
- if (c == '\n') /* if have cr,lf then just */
+ if(prevchar == '\r') { /* if prev char was cr */
+ if(c == '\n') /* if have cr,lf then just */
lseek(test->ofile, -1, SEEK_CUR); /* smash lf on top of the cr */
else
- if (c == '\0') /* if have cr,nul then */
+ if(c == '\0') /* if have cr,nul then */
goto skipit; /* just skip over the putc */
/* else just fall through and allow it */
}
srvr_sockaddr_union_t fromaddr;
curl_socklen_t fromaddrlen;
- for (;;) {
+ for(;;) {
#if defined(HAVE_IOCTLSOCKET)
(void) ioctlsocket(f, FIONREAD, &i);
#else
(void) ioctl(f, FIONREAD, &i);
#endif
- if (i) {
+ if(i) {
j++;
#ifdef ENABLE_IPV6
if(!use_ipv6)
}
flag = 1;
- if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(void *)&flag, sizeof(flag))) {
error = SOCKERRNO;
logmsg("setsockopt(SO_REUSEADDR) failed with error: (%d) %s",
logmsg("Running %s version on port UDP/%d", ipv_inuse, (int)port);
- for (;;) {
+ for(;;) {
fromlen = sizeof(from);
#ifdef ENABLE_IPV6
if(!use_ipv6)
&from.sa, &fromlen);
if(got_exit_signal)
break;
- if (n < 0) {
+ if(n < 0) {
logmsg("recvfrom");
result = 3;
break;
tp = &buf.hdr;
tp->th_opcode = ntohs(tp->th_opcode);
- if (tp->th_opcode == opcode_RRQ || tp->th_opcode == opcode_WRQ) {
+ if(tp->th_opcode == opcode_RRQ || tp->th_opcode == opcode_WRQ) {
memset(&test, 0, sizeof(test));
- if (do_tftp(&test, tp, n) < 0)
+ if(do_tftp(&test, tp, n) < 0)
break;
free(test.buffer);
}
filename = cp;
do {
bool endofit = true;
- while (cp < &buf.storage[size]) {
- if (*cp == '\0') {
+ while(cp < &buf.storage[size]) {
+ if(*cp == '\0') {
endofit = false;
break;
}
break;
} while(1);
- if (*cp) {
+ if(*cp) {
nak(EBADOP);
fclose(server);
return 3;
/* store input protocol */
fprintf(server, "filename: %s\n", filename);
- for (cp = mode; cp && *cp; cp++)
+ for(cp = mode; cp && *cp; cp++)
if(ISUPPER(*cp))
*cp = (char)tolower((int)*cp);
/* store input protocol */
fclose(server);
- for (pf = formata; pf->f_mode; pf++)
- if (strcmp(pf->f_mode, mode) == 0)
+ for(pf = formata; pf->f_mode; pf++)
+ if(strcmp(pf->f_mode, mode) == 0)
break;
- if (!pf->f_mode) {
+ if(!pf->f_mode) {
nak(EBADOP);
return 2;
}
ecode = validate_access(test, filename, tp->th_opcode);
- if (ecode) {
+ if(ecode) {
nak(ecode);
return 1;
}
(const char*)&recvtimeout, sizeof(recvtimeout));
#endif
- if (tp->th_opcode == opcode_WRQ)
+ if(tp->th_opcode == opcode_WRQ)
recvtftp(test, pf);
else
sendtftp(test, pf);
if(!strncmp("verifiedserver", filename, 14)) {
char weare[128];
- size_t count = sprintf(weare, "WE ROOLZ: %ld\r\n", (long)getpid());
+ size_t count = snprintf(weare, sizeof(weare),
+ "WE ROOLZ: %ld\r\n", (long)getpid());
logmsg("Are-we-friendly question received");
test->buffer = strdup(weare);
file = test2file(testno);
if(0 != partno)
- sprintf(partbuf, "data%ld", partno);
+ snprintf(partbuf, sizeof(partbuf), "data%ld", partno);
if(file) {
FILE *stream=fopen(file, "rb");
sap = &ackbuf.hdr;
do {
size = readit(test, &sdp, pf->f_convert);
- if (size < 0) {
+ if(size < 0) {
nak(errno + 100);
return;
}
}
send_data:
- if (swrite(peer, sdp, size + 4) != size + 4) {
+ if(swrite(peer, sdp, size + 4) != size + 4) {
logmsg("write");
return;
}
read_ahead(test, pf->f_convert);
- for ( ; ; ) {
+ for(;;) {
#ifdef HAVE_ALARM
alarm(rexmtval); /* read the ack */
#endif
#endif
if(got_exit_signal)
return;
- if (n < 0) {
+ if(n < 0) {
logmsg("read: fail");
return;
}
sap->th_opcode = ntohs((unsigned short)sap->th_opcode);
sap->th_block = ntohs(sap->th_block);
- if (sap->th_opcode == opcode_ERROR) {
+ if(sap->th_opcode == opcode_ERROR) {
logmsg("got ERROR");
return;
}
- if (sap->th_opcode == opcode_ACK) {
- if (sap->th_block == sendblock) {
+ if(sap->th_opcode == opcode_ACK) {
+ if(sap->th_block == sendblock) {
break;
}
/* Re-synchronize with the other side */
(void) synchnet(peer);
- if (sap->th_block == (sendblock-1)) {
+ if(sap->th_block == (sendblock-1)) {
goto send_data;
}
}
}
sendblock++;
- } while (size == SEGSIZE);
+ } while(size == SEGSIZE);
}
/*
(void) sigsetjmp(timeoutbuf, 1);
#endif
send_ack:
- if (swrite(peer, &ackbuf.storage[0], 4) != 4) {
+ if(swrite(peer, &ackbuf.storage[0], 4) != 4) {
logmsg("write: fail\n");
goto abort;
}
write_behind(test, pf->f_convert);
- for ( ; ; ) {
+ for(;;) {
#ifdef HAVE_ALARM
alarm(rexmtval);
#endif
#endif
if(got_exit_signal)
goto abort;
- if (n < 0) { /* really? */
+ if(n < 0) { /* really? */
logmsg("read: fail\n");
goto abort;
}
rdp->th_opcode = ntohs((unsigned short)rdp->th_opcode);
rdp->th_block = ntohs(rdp->th_block);
- if (rdp->th_opcode == opcode_ERROR)
+ if(rdp->th_opcode == opcode_ERROR)
goto abort;
- if (rdp->th_opcode == opcode_DATA) {
- if (rdp->th_block == recvblock) {
+ if(rdp->th_opcode == opcode_DATA) {
+ if(rdp->th_block == recvblock) {
break; /* normal */
}
/* Re-synchronize with the other side */
(void) synchnet(peer);
- if (rdp->th_block == (recvblock-1))
+ if(rdp->th_block == (recvblock-1))
goto send_ack; /* rexmit */
}
}
size = writeit(test, &rdp, (int)(n - 4), pf->f_convert);
- if (size != (n-4)) { /* ahem */
- if (size < 0)
+ if(size != (n-4)) { /* ahem */
+ if(size < 0)
nak(errno + 100);
else
nak(ENOSPACE);
goto abort;
}
- } while (size == SEGSIZE);
+ } while(size == SEGSIZE);
write_behind(test, pf->f_convert);
- rap->th_opcode = htons((unsigned short)opcode_ACK); /* send the "final" ack */
+ rap->th_opcode = htons((unsigned short)opcode_ACK); /* send the "final"
+ ack */
rap->th_block = htons(recvblock);
(void) swrite(peer, &ackbuf.storage[0], 4);
#if defined(HAVE_ALARM) && defined(SIGALRM)
#endif
if(got_exit_signal)
goto abort;
- if (n >= 4 && /* if read some data */
- rdp->th_opcode == opcode_DATA && /* and got a data block */
- recvblock == rdp->th_block) { /* then my last ack was lost */
+ if(n >= 4 && /* if read some data */
+ rdp->th_opcode == opcode_DATA && /* and got a data block */
+ recvblock == rdp->th_block) { /* then my last ack was lost */
(void) swrite(peer, &ackbuf.storage[0], 4); /* resend final ack */
}
abort:
tp = &buf.hdr;
tp->th_opcode = htons((unsigned short)opcode_ERROR);
tp->th_code = htons((unsigned short)error);
- for (pe = errmsgs; pe->e_code >= 0; pe++)
- if (pe->e_code == error)
+ for(pe = errmsgs; pe->e_code >= 0; pe++)
+ if(pe->e_code == error)
break;
- if (pe->e_code < 0) {
+ if(pe->e_code < 0) {
pe->e_msg = strerror(error - 100);
tp->th_code = EUNDEF; /* set 'undef' errorcode */
}
* report from glibc with FORTIFY_SOURCE */
memcpy(tp->th_msg, pe->e_msg, length + 1);
length += 5;
- if (swrite(peer, &buf.storage[0], length) != length)
+ if(swrite(peer, &buf.storage[0], length) != length)
logmsg("nak: fail\n");
}