Changeset 1016 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- Feb 21, 2007 7:57:07 PM (18 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/tftp.c
r1 r1016 103 103 int fd; 104 104 int bytes_read = 0; 105 106 #ifndef VBOX 107 fd = open(spt->filename, O_RDONLY | O_BINARY); 108 #else /* VBOX */ 109 fd = open((char *)spt->filename, O_RDONLY | O_BINARY); 110 #endif /* VBOX */ 105 char buffer[1024]; 106 int n; 107 108 n = snprintf(buffer, sizeof(buffer), "%s/%s", 109 tftp_prefix, spt->filename); 110 if (n >= sizeof(buffer)) 111 return -1; 112 113 fd = open(buffer, O_RDONLY | O_BINARY); 111 114 112 115 if (fd < 0) { … … 124 127 return bytes_read; 125 128 } 129 130 static int tftp_send_oack(struct tftp_session *spt, 131 const char *key, uint32_t value, 132 struct tftp_t *recv_tp) 133 { 134 struct sockaddr_in saddr, daddr; 135 struct mbuf *m; 136 struct tftp_t *tp; 137 int n = 0; 138 139 m = m_get(); 140 141 if (!m) 142 return -1; 143 144 memset(m->m_data, 0, m->m_size); 145 146 m->m_data += if_maxlinkhdr; 147 tp = (void *)m->m_data; 148 m->m_data += sizeof(struct udpiphdr); 149 150 tp->tp_op = htons(TFTP_OACK); 151 n += sprintf(tp->x.tp_buf + n, "%s", key) + 1; 152 n += sprintf(tp->x.tp_buf + n, "%u", value) + 1; 153 154 saddr.sin_addr = recv_tp->ip.ip_dst; 155 saddr.sin_port = recv_tp->udp.uh_dport; 156 157 daddr.sin_addr = spt->client_ip; 158 daddr.sin_port = spt->client_port; 159 160 m->m_len = sizeof(struct tftp_t) - 514 + n - 161 sizeof(struct ip) - sizeof(struct udphdr); 162 udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); 163 164 return 0; 165 } 166 167 126 168 127 169 static int tftp_send_error(struct tftp_session *spt, … … 281 323 return; 282 324 } 325 326 k += 6; /* skipping octet */ 283 327 284 328 /* do sanity checks on the filename */ … … 299 343 /* only allow exported prefixes */ 300 344 301 #ifndef VBOX 302 if (!tftp_prefix 303 || (strncmp(spt->filename, tftp_prefix, strlen(tftp_prefix)) != 0)) { 304 #else /* VBOX */ 305 if (!tftp_prefix 306 || (strncmp((char *)spt->filename, tftp_prefix, strlen(tftp_prefix)) != 0)) { 307 #endif /* VBOX */ 345 if (!tftp_prefix) { 308 346 tftp_send_error(spt, 2, "Access violation", tp); 309 347 return; … … 315 353 tftp_send_error(spt, 1, "File not found", tp); 316 354 return; 355 } 356 357 if (src[n - 1] != 0) { 358 tftp_send_error(spt, 2, "Access violation", tp); 359 return; 360 } 361 362 while (k < n) { 363 const char *key, *value; 364 365 key = src + k; 366 k += strlen(key) + 1; 367 368 if (k >= n) { 369 tftp_send_error(spt, 2, "Access violation", tp); 370 return; 371 } 372 373 value = src + k; 374 k += strlen(value) + 1; 375 376 if (strcmp(key, "tsize") == 0) { 377 int tsize = atoi(value); 378 struct stat stat_p; 379 380 if (tsize == 0 && tftp_prefix) { 381 char buffer[1024]; 382 int len; 383 384 len = snprintf(buffer, sizeof(buffer), "%s/%s", 385 tftp_prefix, spt->filename); 386 387 if (stat(buffer, &stat_p) == 0) 388 tsize = stat_p.st_size; 389 else { 390 tftp_send_error(spt, 1, "File not found", tp); 391 return; 392 } 393 } 394 395 tftp_send_oack(spt, "tsize", tsize, tp); 396 } 317 397 } 318 398 -
trunk/src/VBox/Devices/Network/slirp/tftp.h
r1 r1016 10 10 #define TFTP_ACK 4 11 11 #define TFTP_ERROR 5 12 #define TFTP_OACK 6 12 13 13 14 #define TFTP_FILENAME_MAX 512
Note:
See TracChangeset
for help on using the changeset viewer.