FreeBSD/libexec/tftpd/tftp-options.c
/*
 * Parse the received options in the header
 */
Parse the received options in the header
Parse the received options in the header
int
parse_options(int peer, char *buffer, uint16_t size)
{
	int	i, options_failed;
	char	*c, *cp, *option, *value;
	if (!options_rfc_enabled) return (0);
	cp = buffer;
	options_failed = 0;	
	while (size > 0) {
		option = cp;
		i = get_field(peer, cp, size);
		cp += i;
		value = cp;
		i = get_field(peer, cp, size);
		cp += i;
		if (*option == '\0') break;
		if (debug&DEBUG_OPTIONS)
			tftp_log(LOG_DEBUG,
			    "option: '%s' value: '%s'", option, value);
		for (c = option; *c; c++)
			if (isupper(*c))
				*c = tolower(*c);
		for (i = 0; options[i].o_type != NULL; i++) {
			if (strcmp(option, options[i].o_type) == 0) {
				if (!acting_as_client)
					options[i].o_request = value;
				if (!options_extra_enabled && !options[i].rfc) {
					tftp_log(LOG_INFO,
					    "Option '%s' with value '%s' found "
					    "but it is not an RFC option",
					    option, value);
					continue;
				}
				if (options[i].o_handler)
					options_failed +=
					    (options[i].o_handler)(peer);
				break;
			}
		}
		if (options[i].o_type == NULL)
			tftp_log(LOG_WARNING,
			    "Unknown option: '%s'", option);
		size -= strlen(option) + strlen(value) + 2;
	}
	return (options_failed);
}
int parse_options ( int peer , char * buffer , uint16_t size ) { int i , options_failed ; char * c , * cp , * option , * value ; if ( ! options_rfc_enabled ) return ( 0 ) ; cp = buffer ; options_failed = 0 ; while ( size > 0 ) { option = cp ; i = get_field ( peer , cp , size ) ; cp += i ; value = cp ; i = get_field ( peer , cp , size ) ; cp += i ; if ( * option == ' \0 ' ) break ; if ( debug & DEBUG_OPTIONS ) tftp_log ( LOG_DEBUG , " " , option , value ) ; for ( c = option ; * c ; c ++ ) if ( isupper ( * c ) ) * c = tolower ( * c ) ; for ( i = 0 ; options [ i ] . o_type != NULL ; i ++ ) { if ( strcmp ( option , options [ i ] . o_type ) == 0 ) { if ( ! acting_as_client ) options [ i ] . o_request = value ; if ( ! options_extra_enabled && ! options [ i ] . rfc ) { tftp_log ( LOG_INFO , " " " " , option , value ) ; continue ; } if ( options [ i ] . o_handler ) options_failed += ( options [ i ] . o_handler ) ( peer ) ; break ; } } if ( options [ i ] . o_type == NULL ) tftp_log ( LOG_WARNING , " " , option ) ; size -= strlen ( option ) + strlen ( value ) + 2 ; } return ( options_failed ) ; }
Parse the received options in the header
Parse the received options in the header
/* Parse the options */ /* We are at the end */