Something went wrong. Try again.
A TFTP server and client library for Zig 0.16: RFC 1350 with blksize, timeout and tsize options, netascii, fuzz-tested.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// SPDX-FileCopyrightText: © 2022 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! The error code carried by a TFTP ERROR packet.
const std = @import("std");
/// The error code of an ERROR packet. Codes 0 through 7 are defined by RFC/// 1350 and code 8 by RFC 2347. The enum is non-exhaustive so that a packet/// carrying a code from some other extension still decodes.pub const ErrorCode = enum(u16) { /// Not defined; the message says what went wrong. not_defined = 0, /// File not found. file_not_found = 1, /// Access violation. access_violation = 2, /// Disk full or allocation exceeded. disk_full = 3, /// Illegal TFTP operation. illegal_operation = 4, /// Unknown transfer ID: a packet arrived from a port that is not part of the transfer. tid_unknown = 5, /// File already exists. file_exists = 6, /// No such user. no_such_user = 7, /// The transfer is terminated because option negotiation failed (RFC 2347). term_option = 8, _,
/// Reads a big endian error code from `input`. Unknown codes decode to an /// unnamed value rather than failing. pub fn decode(input: *std.Io.Reader) !ErrorCode { return try input.takeEnum(ErrorCode, .big); }
/// Writes the error code to `output` as a big endian `u16`. pub fn encode(self: ErrorCode, output: *std.Io.Writer) !void { try output.writeInt(u16, @intFromEnum(self), .big); }
/// The standard message for this code, as worded in RFC 1350 and RFC 2347. /// It is what an ERROR packet carries when no more specific message is /// given. `not_defined` and unknown codes have no standard message, so /// they return the empty string. pub fn message(self: ErrorCode) []const u8 { return switch (self) { .not_defined => "", .file_not_found => "File not found", .access_violation => "Access violation", .disk_full => "Disk full or allocation exceeded", .illegal_operation => "Illegal TFTP operation", .tid_unknown => "Unknown transfer ID", .file_exists => "File already exists", .no_such_user => "No such user", .term_option => "Terminate transfer due to option negotiation", _ => "", }; }};