/* Send an Error Message to the TFTP Server.  */
static int send_err(int sock, struct tftpc *client, int err_code, char *err_msg)
/* Send an Error Message to the TFTP Server.  */
static int send_err(int sock, struct tftpc *client, int err_code, char *err_msg)
{
	uint32_t req_size;
	LOG_DBG("Client sending error code: %d", err_code);
	sys_put_be16(ERROR_OPCODE, client->tftp_buf);
	sys_put_be16(err_code, client->tftp_buf + 2);
	req_size = 4;
	if (err_msg != NULL) {
		size_t copy_len = strlen(err_msg);
		if (copy_len > sizeof(client->tftp_buf) - req_size) {
			copy_len = sizeof(client->tftp_buf) - req_size;
		}
		memcpy(client->tftp_buf + req_size, err_msg, copy_len);
		req_size += copy_len;
	}
	return send(sock, client->tftp_buf, req_size, 0);
}