Revision 78be0566
b/slirp/tftp.c | ||
---|---|---|
37 | 37 |
|
38 | 38 |
static void tftp_session_terminate(struct tftp_session *spt) |
39 | 39 |
{ |
40 |
if (spt->fd >= 0) { |
|
41 |
close(spt->fd); |
|
42 |
spt->fd = -1; |
|
43 |
} |
|
40 | 44 |
g_free(spt->filename); |
41 | 45 |
spt->slirp = NULL; |
42 | 46 |
} |
... | ... | |
54 | 58 |
|
55 | 59 |
/* sessions time out after 5 inactive seconds */ |
56 | 60 |
if ((int)(curtime - spt->timestamp) > 5000) { |
57 |
g_free(spt->filename);
|
|
61 |
tftp_session_terminate(spt);
|
|
58 | 62 |
goto found; |
59 | 63 |
} |
60 | 64 |
} |
... | ... | |
64 | 68 |
found: |
65 | 69 |
memset(spt, 0, sizeof(*spt)); |
66 | 70 |
memcpy(&spt->client_ip, &tp->ip.ip_src, sizeof(spt->client_ip)); |
71 |
spt->fd = -1; |
|
67 | 72 |
spt->client_port = tp->udp.uh_sport; |
68 | 73 |
spt->slirp = slirp; |
69 | 74 |
|
... | ... | |
95 | 100 |
static int tftp_read_data(struct tftp_session *spt, uint16_t block_nr, |
96 | 101 |
uint8_t *buf, int len) |
97 | 102 |
{ |
98 |
int fd; |
|
99 |
int bytes_read = 0; |
|
100 |
|
|
101 |
fd = open(spt->filename, O_RDONLY | O_BINARY); |
|
103 |
int bytes_read = 0; |
|
102 | 104 |
|
103 |
if (fd < 0) {
|
|
104 |
return -1;
|
|
105 |
} |
|
105 |
if (spt->fd < 0) {
|
|
106 |
spt->fd = open(spt->filename, O_RDONLY | O_BINARY);
|
|
107 |
}
|
|
106 | 108 |
|
107 |
if (len) { |
|
108 |
lseek(fd, block_nr * 512, SEEK_SET); |
|
109 |
if (spt->fd < 0) { |
|
110 |
return -1; |
|
111 |
} |
|
109 | 112 |
|
110 |
bytes_read = read(fd, buf, len);
|
|
111 |
}
|
|
113 |
if (len) {
|
|
114 |
lseek(spt->fd, block_nr * 512, SEEK_SET);
|
|
112 | 115 |
|
113 |
close(fd); |
|
116 |
bytes_read = read(spt->fd, buf, len); |
|
117 |
} |
|
114 | 118 |
|
115 |
return bytes_read; |
|
119 |
return bytes_read;
|
|
116 | 120 |
} |
117 | 121 |
|
118 | 122 |
static int tftp_send_oack(struct tftp_session *spt, |
b/slirp/tftp.h | ||
---|---|---|
33 | 33 |
struct tftp_session { |
34 | 34 |
Slirp *slirp; |
35 | 35 |
char *filename; |
36 |
int fd; |
|
36 | 37 |
|
37 | 38 |
struct in_addr client_ip; |
38 | 39 |
uint16_t client_port; |
Also available in: Unified diff