FreeBSD/usr.bin/tftp/main.c
/*
 * RFC3617 handling of TFTP URIs:
 *
 *    tftpURI         = "tftp://" host "/" file [ mode ]
 *    mode            = ";"  "mode=" ( "netascii" / "octet" )
 *    file            = *( unreserved / escaped )
 *    host            = <as specified by RFC 2732>
 *    unreserved      = <as specified in RFC 2396>
 *    escaped         = <as specified in RFC 2396>
 *
 * We are cheating a little bit by allowing any mode as specified in the
 * modes table defined earlier on in this file and mapping it on the real
 * mode.
 */


We are cheating a little bit by allowing any mode as specified in the
modes table defined earlier on in this file and mapping it on the real
mode.
We are cheating a little bit by allowing any mode as specified in the modes table defined earlier on in this file and mapping it on the real mode .
static void
urihandling(char *URI)
{
	char	uri[ARG_MAX];
	char	*host = NULL;
	char	*path = NULL;
	char	*opts = NULL;
	const char *tmode = "octet";
	char	*s;
	char	line[MAXLINE];
	int	i;
	strlcpy(uri, URI, ARG_MAX);
	host = uri + 7;
	if ((s = strchr(host, '/')) == NULL) {
		fprintf(stderr,
		    "Invalid URI: Couldn't find / after hostname\n");
		exit(1);
	}
	*s = '\0';
	path = s + 1;
	if ((s = strchr(path, ';')) != NULL) {
		*s = '\0';
		opts = s + 1;
		if (strncmp(opts, "mode=", 5) == 0) {
			tmode = opts;
			tmode += 5;
			for (i = 0; modes[i].m_name != NULL; i++) {
				if (strcmp(modes[i].m_name, tmode) == 0)
					break;
			}
			if (modes[i].m_name == NULL) {
				fprintf(stderr, "Invalid mode: '%s'\n", mode);
				exit(1);
			}
			settftpmode(modes[i].m_mode);
		}
	} else {
		settftpmode("octet");
	}
	setpeer0(host, NULL);
	sprintf(line, "get %s", path);
	makeargv(line);
	get(margc, margv);
}
static void urihandling ( char * URI ) { char uri [ ARG_MAX ] ; char * host = NULL ; char * path = NULL ; char * opts = NULL ; const char * tmode = " " ; char * s ; char line [ MAXLINE ] ; int i ; strlcpy ( uri , URI , ARG_MAX ) ; host = uri + 7 ; if ( ( s = strchr ( host , ' ' ) ) == NULL ) { fprintf ( stderr , " \n " ) ; exit ( 1 ) ; } * s = ' \0 ' ; path = s + 1 ; if ( ( s = strchr ( path , ' ' ) ) != NULL ) { * s = ' \0 ' ; opts = s + 1 ; if ( strncmp ( opts , " " , 5 ) == 0 ) { tmode = opts ; tmode += 5 ; for ( i = 0 ; modes [ i ] . m_name != NULL ; i ++ ) { if ( strcmp ( modes [ i ] . m_name , tmode ) == 0 ) break ; } if ( modes [ i ] . m_name == NULL ) { fprintf ( stderr , " \n " , mode ) ; exit ( 1 ) ; } settftpmode ( modes [ i ] . m_mode ) ; } } else { settftpmode ( " " ) ; } setpeer0 ( host , NULL ) ; sprintf ( line , " " , path ) ; makeargv ( line ) ; get ( margc , margv ) ; }
RFC3617 handling of TFTP URIs:
    tftpURI         = "tftp://" host "/" file [ mode ]
    mode            = ";"  "mode=" ( "netascii" / "octet" )
    file            = *( unreserved / escaped )
    host            = <as specified by RFC 2732>
    unreserved      = <as specified in RFC 2396>
    escaped         = <as specified in RFC 2396>
RFC3617 handling of TFTP URIs : tftpURI = " tftp : // " host " / " file [ mode ] mode = " ; " " mode = " ( " netascii " / " octet " ) file = * ( unreserved / escaped ) host = <as specified by RFC 2732 > unreserved = <as specified in RFC 2396 > escaped = <as specified in RFC 2396 >