Always reopen socket after a get/put in tftp. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=130292 --- tftp/main.c 2008-05-16 09:56:18 +0000 +++ tftp/main.c 2008-05-16 10:48:23 +0000 @@ -69,7 +69,7 @@ #define TIMEOUT 5 /* secs between rexmt's */ struct sockaddr_in s_inn; -int f; +int f = -1; int trace; int verbose; int rexmtval = TIMEOUT; @@ -151,17 +151,11 @@ static struct cmd *getcmd(const char *name); static char *tail(char *filename); -int -main(int argc, char *argv[]) -{ +void initsock() { struct sockaddr_in s_in; - int top; - sp = getservbyname("tftp", "udp"); - if (sp == 0) { - fprintf(stderr, "tftp: udp/tftp: unknown service\n"); - exit(1); - } + if (f >= 0) + close(f); f = socket(AF_INET, SOCK_DGRAM, 0); if (f < 0) { perror("tftp: socket"); @@ -173,6 +167,19 @@ perror("tftp: bind"); exit(1); } +} + +int +main(int argc, char *argv[]) +{ + int top; + + sp = getservbyname("tftp", "udp"); + if (sp == 0) { + fprintf(stderr, "tftp: udp/tftp: unknown service\n"); + exit(1); + } + initsock(); strcpy(mode, "netascii"); mysignal(SIGINT, intr); if (argc > 1) { --- tftp/tftp.c 2008-05-16 09:56:18 +0000 +++ tftp/tftp.c 2008-05-16 10:41:30 +0000 @@ -204,6 +204,7 @@ block++; } while (1); abort: + initsock(); fclose(file); stopclock(); if (amount > 0) @@ -307,6 +308,7 @@ amount += size; } while (size == SEGSIZE); abort: /* ok to ack, since user */ + initsock(); ap->th_opcode = htons((u_short)ACK); /* has seen err msg */ ap->th_block = htons((u_short)block); (void) sendto(f, ackbuf, 4, 0, (struct sockaddr *)&s_inn, sizeof(s_inn)); --- tftp/tftpsubs.h 2008-05-16 09:56:18 +0000 +++ tftp/tftpsubs.h 2008-05-16 10:50:03 +0000 @@ -1,6 +1,7 @@ #define PKTSIZE SEGSIZE+4 /* should be moved to tftp.h */ int synchnet(int); +void initsock(void); struct tftphdr *r_init(void); struct tftphdr *w_init(void); int readit(FILE *file, struct tftphdr **dpp, int convert);