summaryrefslogtreecommitdiff
blob: 58b6c710b97ea5cd0ea4613cfb65b267f13a977b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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);