forked from mirrors/tftp-hpa-google
Working on version 0.29.
Initial work for compiling on Win32/Cygwin. Posixly correctness.
This commit is contained in:
parent
f9e7950883
commit
98d7543721
10 changed files with 81 additions and 31 deletions
|
@ -1,14 +1,14 @@
|
|||
all: tftpd tftpd.8
|
||||
|
||||
SRCROOT = ..
|
||||
VERSION = $(shell cat ../version)
|
||||
|
||||
-include ../MCONFIG
|
||||
include ../MRULES
|
||||
|
||||
OBJS = tftpd.o tftpsubs.o recvfrom.o misc.o $(TFTPDOBJS)
|
||||
OBJS = tftpd.$(O) tftpsubs.$(O) recvfrom.$(O) misc.$(O) $(TFTPDOBJS)
|
||||
|
||||
tftpd: $(OBJS)
|
||||
all: tftpd$(X) tftpd.8
|
||||
|
||||
tftpd$(X): $(OBJS)
|
||||
$(CC) $(LDFLAGS) $^ $(TFTPD_LIBS) -o $@
|
||||
|
||||
tftpsubs.c:
|
||||
|
@ -23,12 +23,12 @@ tftpd.8: tftpd.8.in ../version
|
|||
|
||||
install: all
|
||||
mkdir -p $(INSTALLROOT)$(SBINDIR) $(INSTALLROOT)$(MANDIR)/man8
|
||||
$(INSTALL_PROGRAM) tftpd $(INSTALLROOT)$(SBINDIR)/in.tftpd
|
||||
$(INSTALL_PROGRAM) tftpd$(X) $(INSTALLROOT)$(SBINDIR)/in.tftpd
|
||||
$(INSTALL_DATA) tftpd.8 $(INSTALLROOT)$(MANDIR)/man8/in.tftpd.8
|
||||
cd $(INSTALLROOT)$(MANDIR)/man8 && ln -sf in.tftpd.8 tftpd.8
|
||||
|
||||
clean:
|
||||
rm -f *.o tftpd tftpsubs.c tftpsubs.h tftpd.8
|
||||
rm -f *.o *.obj *.exe tftpd tftpsubs.c tftpsubs.h tftpd.8
|
||||
|
||||
distclean: clean
|
||||
rm -f *~
|
||||
|
|
|
@ -56,7 +56,6 @@ static const char *rcsid UNUSED =
|
|||
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
|
@ -180,7 +179,6 @@ main(int argc, char **argv)
|
|||
struct sockaddr_in myaddr;
|
||||
struct sockaddr_in bindaddr;
|
||||
int n;
|
||||
int on = 1;
|
||||
int fd = 0;
|
||||
int standalone = 0; /* Standalone (listen) mode */
|
||||
char *address = NULL; /* Address to listen to */
|
||||
|
@ -298,10 +296,26 @@ main(int argc, char **argv)
|
|||
if ( spec_umask || !unixperms )
|
||||
umask(my_umask);
|
||||
|
||||
if (ioctl(fd, FIONBIO, &on) < 0) {
|
||||
syslog(LOG_ERR, "ioctl(FIONBIO): %m");
|
||||
exit(EX_OSERR);
|
||||
#if defined(HAVE_FCNTL) && defined(O_NONBLOCK)
|
||||
/* Posixly correct */
|
||||
{
|
||||
int flags;
|
||||
if ( (flags = fcntl(fd, F_GETFL, 0) < 0) ||
|
||||
(fcntl(fd, F_SETFL, flags|O_NONBLOCK)) ) {
|
||||
syslog(LOG_ERR, "Cannot set nonblocking socket: %m");
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* Old BSD version */
|
||||
{
|
||||
int on = 1;
|
||||
if ( ioctl(fd, FIONBIO, &on) < 0 ) {
|
||||
syslog(LOG_ERR, "Cannot set nonblocking socket: %m");
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_REGEX
|
||||
if ( rewrite_file )
|
||||
|
@ -421,7 +435,7 @@ main(int argc, char **argv)
|
|||
continue; /* Signal caught, reloop */
|
||||
if ( rv == -1 ) {
|
||||
syslog(LOG_ERR, "select loop: %m");
|
||||
exit(EX_OSERR);
|
||||
exit(EX_IOERR);
|
||||
} else if ( rv == 0 ) {
|
||||
exit(0); /* Timeout, return to inetd */
|
||||
}
|
||||
|
@ -431,17 +445,22 @@ main(int argc, char **argv)
|
|||
(struct sockaddr *)&from, &fromlen,
|
||||
&myaddr);
|
||||
|
||||
if ( n < 0 ) {
|
||||
if ( E_WOULD_BLOCK(errno) || errno == EINTR ) {
|
||||
continue; /* Again, from the top */
|
||||
} else {
|
||||
syslog(LOG_ERR, "recvfrom: %m");
|
||||
exit(EX_IOERR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( standalone && myaddr.sin_addr.s_addr == INADDR_ANY ) {
|
||||
/* myrecvfrom() didn't capture the source address; but we might
|
||||
have bound to a specific address, if so we should use it */
|
||||
memcpy(&myaddr.sin_addr, &bindaddr.sin_addr, sizeof bindaddr.sin_addr);
|
||||
}
|
||||
|
||||
if (n < 0) {
|
||||
syslog(LOG_ERR, "recvfrom: %m");
|
||||
exit(EX_IOERR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now that we have read the request packet from the UDP
|
||||
* socket, we fork and go back to listening to the socket.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue