Craig Johnston
2006-Dec-11 17:23 UTC
[syslinux] Add option to TFTP client to ignore ':' in file name
I have encountered a situation where I would like to use tftp-hpa to retrieve a file that resides within an absolute path containing a ':' character. Ala, "tftp foobar -c get C:2/tftpdir/myfile". Since the tftp client automatically converts the host:file syntax, I get an error "tftp: C: Unknown host". I made a chage to the tftp client code to add a literal mode (-l), that prevents the special treatment of the ':' character. I've attached a patch set for main.c and tftp.1.in for your consideration. I'm not sure how many folks run into this, but it may be somewhat common for VxWorks and perhaps MSDOS users. Thanks, Craig Johnston *** tftp-hpa-0.43/tftp/main.c 2006-12-01 14:08:58.000000000 -0800 --- tftp-hpa-0.43x/tftp/main.c 2006-12-01 14:02:50.000000000 -0800 *************** *** 89,94 **** --- 89,95 ---- u_short port; int trace; int verbose; + int literal; int connected; const struct modes *mode; #ifdef WITH_READLINE *************** *** 116,121 **** --- 117,123 ---- void settrace (int, char **); void setverbose (int, char **); void status (int, char **); + void setliteral (int, char **); static void command (void); *************** *** 154,159 **** --- 156,164 ---- { "trace", "toggle packet tracing", settrace }, + { "literal", + "toggle literal mode, ignore ':' in file name", + setliteral }, { "status", "show current status", status }, *************** *** 187,193 **** static inline void usage(int errcode) { ! fprintf(stderr, "Usage: %s [-v][-m mode] [host [port]] [-c command]\n", program); exit(errcode); } --- 192,198 ---- static inline void usage(int errcode) { ! fprintf(stderr, "Usage: %s [-v][-l][-m mode] [host [port]] [-c command]\n", program); exit(errcode); } *************** *** 220,225 **** --- 225,233 ---- /* Print version and configuration to stdout and exit */ printf("%s\n", TFTP_CONFIG_STR); exit(0); + case 'l': + literal = 1; + break; case 'm': if ( ++arg >= argc ) usage(EX_USAGE); *************** *** 489,495 **** return; } targ = argv[argc - 1]; ! if (strchr(argv[argc - 1], ':')) { struct hostent *hp; for (n = 1; n < argc - 1; n++) --- 497,503 ---- return; } targ = argv[argc - 1]; ! if (!literal && strchr(argv[argc - 1], ':')) { struct hostent *hp; for (n = 1; n < argc - 1; n++) *************** *** 578,591 **** } if (!connected) { for (n = 1; n < argc ; n++) ! if (strchr(argv[n], ':') == 0) { getusage(argv[0]); return; } } for (n = 1; n < argc ; n++) { src = strchr(argv[n], ':'); ! if (src == NULL) src = argv[n]; else { struct hostent *hp; --- 586,599 ---- } if (!connected) { for (n = 1; n < argc ; n++) ! if (literal || strchr(argv[n], ':') == 0) { getusage(argv[0]); return; } } for (n = 1; n < argc ; n++) { src = strchr(argv[n], ':'); ! if (literal || src == NULL) src = argv[n]; else { struct hostent *hp; *************** *** 687,692 **** --- 695,708 ---- } void + setliteral(int argc, char *argv[]) + { + (void)argc; (void)argv; /* Quiet unused warning */ + literal = !literal; + printf("Literal mode %s.\n", literal ? "on" : "off"); + } + + void status(int argc, char *argv[]) { (void)argc; (void)argv; /* Quiet unused warning */ *************** *** 694,701 **** printf("Connected to %s.\n", hostname); else printf("Not connected.\n"); ! printf("Mode: %s Verbose: %s Tracing: %s\n", mode->m_mode, ! verbose ? "on" : "off", trace ? "on" : "off"); printf("Rexmt-interval: %d seconds, Max-timeout: %d seconds\n", rexmtval, maxtimeout); } --- 710,717 ---- printf("Connected to %s.\n", hostname); else printf("Not connected.\n"); ! printf("Mode: %s Verbose: %s Tracing: %s Literal: %s\n", mode->m_mode, ! verbose ? "on" : "off", trace ? "on" : "off", literal ? "on" : "off"); printf("Rexmt-interval: %d seconds, Max-timeout: %d seconds\n", rexmtval, maxtimeout); } *** tftp-hpa-0.43/tftp/tftp.1.in 2006-12-01 14:08:58.000000000 -0800 --- tftp-hpa-0.43x/tftp/tftp.1.in 2006-12-01 14:29:55.000000000 -0800 *************** *** 60,65 **** --- 60,68 ---- Execute \fIcommand\fP as if it had been entered on the tftp prompt. Must be specified last on the command line. .TP + .B \-l + Default to literal mode. Used to avoid special processing of ':' in a file name. + .TP \fB\-m\fP \fImode\fP Set the default transfer mode to \fImode\fP. This is usually used with \-c. .TP *************** *** 119,125 **** .I "host:filename" to specify both a host and filename at the same time. If the latter form is used, the last hostname specified becomes the default for ! future transfers. .TP \fBmode\fP \fItransfer-mode\fP Specify the mode for transfers; --- 122,133 ---- .I "host:filename" to specify both a host and filename at the same time. If the latter form is used, the last hostname specified becomes the default for ! future transfers. Enable ! .B literal ! mode to prevent special treatment of the ':' character (e.g. C:\\dir\\file). ! .TP ! .B literal ! Toggle literal mode. When set, this mode prevents special treatment of ':' in filenames. .TP \fBmode\fP \fItransfer-mode\fP Specify the mode for transfers; *************** *** 151,157 **** transfers. If the remote-directory form is used, the remote host is assumed to be a UNIX system or another system using .B / ! as directory separator. .TP .B quit Exit --- 159,167 ---- transfers. If the remote-directory form is used, the remote host is assumed to be a UNIX system or another system using .B / ! as directory separator. Enable ! .B literal ! mode to prevent special treatment of the ':' character (e.g. C:\\dir\\file). .TP .B quit Exit