FreeBSD/libexec/tftpd/tftp-io.c
/*
 * Send an ERROR packet (error message).
 * Error code passed in is one of the
 * standard TFTP codes, or a UNIX errno
 * offset by 100.
 */
Send an ERROR packet (error message).
Error code passed in is one of the
standard TFTP codes, or a UNIX errno
offset by 100.
Send an ERROR packet ( error message ) . Error code passed in is one of the standard TFTP codes or a UNIX errno offset by 100 .
void
send_error(int peer, int error)
{
	struct tftphdr *tp;
	int length;
	struct errmsg *pe;
	char buf[MAXPKTSIZE];
	if (debug&DEBUG_PACKETS)
		tftp_log(LOG_DEBUG, "Sending ERROR %d", error);
	DROPPACKET("send_error");
	tp = (struct tftphdr *)buf;
	tp->th_opcode = htons((u_short)ERROR);
	tp->th_code = htons((u_short)error);
	for (pe = errmsgs; pe->e_code >= 0; pe++)
		if (pe->e_code == error)
			break;
	if (pe->e_code < 0) {
		pe->e_msg = strerror(error - 100);
		tp->th_code = EUNDEF;   
	}
	strcpy(tp->th_msg, pe->e_msg);
	length = strlen(pe->e_msg);
	tp->th_msg[length] = '\0';
	length += 5;
	if (debug&DEBUG_PACKETS)
		tftp_log(LOG_DEBUG, "Sending ERROR %d: %s", error, tp->th_msg);
	if (sendto(peer, buf, length, 0,
		(struct sockaddr *)&peer_sock, peer_sock.ss_len) != length)
		tftp_log(LOG_ERR, "send_error: %s", strerror(errno));
}
void send_error ( int peer , int error ) { struct tftphdr * tp ; int length ; struct errmsg * pe ; char buf [ MAXPKTSIZE ] ; if ( debug & DEBUG_PACKETS ) tftp_log ( LOG_DEBUG , " " , error ) ; DROPPACKET ( " " ) ; tp = ( struct tftphdr * ) buf ; tp -> th_opcode = htons ( ( u_short ) ERROR ) ; tp -> th_code = htons ( ( u_short ) error ) ; for ( pe = errmsgs ; pe -> e_code >= 0 ; pe ++ ) if ( pe -> e_code == error ) break ; if ( pe -> e_code < 0 ) { pe -> e_msg = strerror ( error - 100 ) ; tp -> th_code = EUNDEF ; } strcpy ( tp -> th_msg , pe -> e_msg ) ; length = strlen ( pe -> e_msg ) ; tp -> th_msg [ length ] = ' \0 ' ; length += 5 ; if ( debug & DEBUG_PACKETS ) tftp_log ( LOG_DEBUG , " " , error , tp -> th_msg ) ; if ( sendto ( peer , buf , length , 0 , ( struct sockaddr * ) & peer_sock , peer_sock . ss_len ) != length ) tftp_log ( LOG_ERR , " " , strerror ( errno ) ) ; }
Send an ERROR packet (error message).
Send an ERROR packet ( error message ) .
/* set 'undef' errorcode */