use std::io;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum McrxError {
#[error("MCRX: invalid destination port")]
InvalidDestinationPort,
#[error("MCRX: group must be a multicast IP address")]
InvalidMulticastGroup,
#[error("MCRX: invalid source address")]
InvalidSourceAddress,
#[error("MCRX: IPv6 SSM groups must use the ff3x:: prefix")]
InvalidIpv6SsmGroup,
#[error("MCRX: source address family must match group address family")]
SourceAddressFamilyMismatch,
#[error("MCRX: interface address family must match group address family")]
InterfaceAddressFamilyMismatch,
#[error("MCRX: interface index must be greater than 0")]
InvalidInterfaceIndex,
#[error("MCRX: interface index is only supported for IPv6 subscriptions")]
InterfaceIndexRequiresIpv6,
#[error("MCRX: subscription already exists")]
DuplicateSubscription,
#[error("MCRX: subscription not found")]
SubscriptionNotFound,
#[error("MCRX: subscription not joined")]
SubscriptionNotJoined,
#[error("MCRX: subscription already joined")]
SubscriptionAlreadyJoined,
#[error("MCRX: failed to create UDP socket: {0}")]
SocketCreateFailed(io::Error),
#[error("MCRX: failed to set socket option: {0}")]
SocketOptionFailed(io::Error),
#[error("MCRX: failed to bind UDP socket: {0}")]
SocketBindFailed(io::Error),
#[error("MCRX: failed to create raw receive socket: {0}")]
RawSocketCreateFailed(io::Error),
#[error("MCRX: failed to bind raw receive socket: {0}")]
RawSocketBindFailed(io::Error),
#[error("MCRX: raw multicast receive is not supported on this platform: {0}")]
RawPacketReceiveUnsupported(String),
#[error("MCRX: requested IPv6 functionality is not implemented yet")]
Ipv6NotYetImplemented,
#[error("MCRX: failed to read local address from existing socket: {0}")]
SocketLocalAddrFailed(io::Error),
#[error("MCRX: failed to look up socket extension function: {0}")]
SocketIoctlFailed(io::Error),
#[error("MCRX: existing socket address family does not match the subscription configuration")]
ExistingSocketAddressFamilyMismatch,
#[error("MCRX: existing socket is bound to UDP port {actual}, expected {expected}")]
ExistingSocketPortMismatch { expected: u16, actual: u16 },
#[error("MCRX: failed to join multicast group: {0}")]
MulticastJoinFailed(io::Error),
#[error("MCRX: failed to leave multicast group: {0}")]
MulticastLeaveFailed(io::Error),
#[error("MCRX: source-specific multicast is not supported on this platform")]
SourceSpecificMulticastUnsupported,
#[error(
"MCRX: IPv6 source-specific multicast requires an explicit interface address or interface index"
)]
Ipv6SourceSpecificMulticastRequiresInterface,
#[error("MCRX: IPv6 source-specific multicast is not implemented yet")]
Ipv6SourceSpecificMulticastNotYetImplemented,
#[error("MCRX: failed to bind interface probe socket: {0}")]
InterfaceProbeBindFailed(io::Error),
#[error("MCRX: failed to connect interface probe socket: {0}")]
InterfaceProbeConnectFailed(io::Error),
#[error("MCRX: failed to read local address from interface probe socket: {0}")]
InterfaceProbeLocalAddrFailed(io::Error),
#[error("MCRX: failed to discover local interface: {0}")]
InterfaceDiscoveryFailed(String),
#[error("MCRX: received packet from non-IP socket address")]
NonIpSocketAddress,
#[error("MCRX: receive failed: {0}")]
ReceiveFailed(io::Error),
}