Browse Source

[tftp] Strip the initial '/' to keep Windows TFTP servers happy.

tags/v0.9.4
Michael Brown 16 years ago
parent
commit
227bb05a50
1 changed files with 19 additions and 6 deletions
  1. 19
    6
      src/net/udp/tftp.c

+ 19
- 6
src/net/udp/tftp.c View File

@@ -316,17 +316,30 @@ void tftp_set_mtftp_port ( unsigned int port ) {
316 316
  */
317 317
 static int tftp_send_rrq ( struct tftp_request *tftp ) {
318 318
 	struct tftp_rrq *rrq;
319
-	const char *path = tftp->uri->path;
320
-	size_t len = ( sizeof ( *rrq ) + strlen ( path ) + 1 /* NUL */
321
-		       + 5 + 1 /* "octet" + NUL */
322
-		       + 7 + 1 + 5 + 1 /* "blksize" + NUL + ddddd + NUL */
323
-		       + 5 + 1 + 1 + 1 /* "tsize" + NUL + "0" + NUL */ 
324
-		       + 9 + 1 + 1 /* "multicast" + NUL + NUL */ );
319
+	const char *path;
320
+	size_t len;
325 321
 	struct io_buffer *iobuf;
326 322
 
323
+	/* Strip initial '/' if present.  If we were opened via the
324
+	 * URI interface, then there will be an initial '/', since a
325
+	 * full tftp:// URI provides no way to specify a non-absolute
326
+	 * path.  However, many TFTP servers (particularly Windows
327
+	 * TFTP servers) complain about having an initial '/', and it
328
+	 * violates user expectations to have a '/' silently added to
329
+	 * the DHCP-specified filename.
330
+	 */
331
+	path = tftp->uri->path;
332
+	if ( *path == '/' )
333
+		path++;
334
+
327 335
 	DBGC ( tftp, "TFTP %p requesting \"%s\"\n", tftp, path );
328 336
 
329 337
 	/* Allocate buffer */
338
+	len = ( sizeof ( *rrq ) + strlen ( path ) + 1 /* NUL */
339
+		+ 5 + 1 /* "octet" + NUL */
340
+		+ 7 + 1 + 5 + 1 /* "blksize" + NUL + ddddd + NUL */
341
+		+ 5 + 1 + 1 + 1 /* "tsize" + NUL + "0" + NUL */ 
342
+		+ 9 + 1 + 1 /* "multicast" + NUL + NUL */ );
330 343
 	iobuf = xfer_alloc_iob ( &tftp->socket, len );
331 344
 	if ( ! iobuf )
332 345
 		return -ENOMEM;

Loading…
Cancel
Save