Portability improvements. Now compiles and works on Solaris 8, as well

as Linux.
This commit is contained in:
hpa 2001-08-03 03:17:57 +00:00
parent 4003a672ce
commit 266427bc5b
10 changed files with 78 additions and 29 deletions

View file

@ -68,8 +68,13 @@ static const char *rcsid UNUSED =
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "extern.h"
#include "../config.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#define TIMEOUT 5 /* secs between rexmt's */
#define LBUFLEN 200 /* size of input buffer */

View file

@ -68,7 +68,9 @@ static const char *rcsid UNUSED =
#include "../config.h"
#include "extern.h"
void bsd_signal(int, void (*)(int));
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#ifndef HAVE_SIGSETJMP
#define sigsetjmp(x,y) setjmp(x)
@ -322,7 +324,7 @@ makerequest(int request, const char *name,
char *cp;
tp->th_opcode = htons((u_short)request);
cp = tp->th_stuff;
cp = (char *) &(tp->th_stuff);
strcpy(cp, name);
cp += strlen(name);
*cp++ = '\0';
@ -397,7 +399,7 @@ tpacket(const char *s, struct tftphdr *tp, int n)
case RRQ:
case WRQ:
n -= 2;
file = cp = tp->th_stuff;
file = cp = (char *) &(tp->th_stuff);
cp = strchr(cp, '\0');
printf("<file=%s, mode=%s>\n", file, cp + 1);
break;

View file

@ -59,12 +59,14 @@ static const char *rcsid UNUSED =
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/tftp.h>
#include <stdio.h>
#include <unistd.h>
#include "../config.h"
#define PKTSIZE MAX_SEGSIZE+4 /* should be moved to tftp.h */
int segsize = SEGSIZE; /* Default segsize */
@ -254,20 +256,28 @@ skipit:
int
synchnet(int f) /* socket to flush */
{
int i, j = 0;
char rbuf[PKTSIZE];
struct sockaddr_in from;
int fromlen;
int pktcount = 0;
char rbuf[PKTSIZE];
struct sockaddr_in from;
int fromlen;
fd_set socketset;
struct timeval notime;
while ( 1 ) {
notime.tv_sec = notime.tv_usec = 0;
FD_ZERO(&socketset);
FD_SET(f, &socketset);
if ( select(f, &socketset, NULL, NULL, &notime) <= 0 )
break; /* Nothing to read */
/* Otherwise drain the packet */
pktcount++;
fromlen = sizeof from;
(void) recvfrom(f, rbuf, sizeof (rbuf), 0,
(struct sockaddr *)&from, &fromlen);
}
while (1) {
(void) ioctl(f, FIONREAD, &i);
if (i) {
j++;
fromlen = sizeof from;
(void) recvfrom(f, rbuf, sizeof (rbuf), 0,
(struct sockaddr *)&from, &fromlen);
} else {
return(j);
}
}
return pktcount; /* Return packets drained */
}

View file

@ -75,7 +75,7 @@ extern char *xstrdup(const char *);
/*
* Signal-related stuff
*/
void bsd_signal(int, void (*)(int));
void (*bsd_signal(int, void (*)(int)))(int);
#ifndef HAVE_SIGSETJMP
#define sigsetjmp(x,y) setjmp(x)