socket9 0.1.0-alpha.1

Extended untilities for the networking/unix sockets and raw network sockets
Documentation
/*-
 * socket9 - A RAW networking sockets manipulation and configration basing on 
 * strong types.
 * 
 * Copyright (C) 2021 Aleksandr Morozov, Lucia Hoffmann
 * Copyright (C) 2025 Aleksandr Morozov
 * 
 * The syslog-rs crate can be redistributed and/or modified
 * under the terms of either of the following licenses:
 *
 *   1. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016 OR
 *
 *   2. the Mozilla Public License Version 2.0 (the “MPL”) OR
 *                     
 *   3. The MIT License (MIT)
 */

 
use std::{ffi::c_int, fmt, net::Ipv4Addr};

use crate::{IP_MULTICAST_IF, IPPROTO_IP, LocalFrom, OptRMarker, OptWMarker, SockOptMarker, in_addr};


#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct IpMulticastIf(in_addr);

#[cfg(unix)]
impl fmt::Debug for IpMulticastIf
{
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result 
    {
        f.debug_tuple("IpMulticastIf").field(&self.0).finish()
    }
}

#[cfg(windows)]
impl fmt::Debug for IpMulticastIf
{
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result 
    {
        f.debug_tuple("IpMulticastIf").finish()
    }
}

impl SockOptMarker for IpMulticastIf 
{
    const SO_LEVEL: c_int = IPPROTO_IP;   
    const SO_OPTNAME: c_int = IP_MULTICAST_IF;

    type DataType = Ipv4Addr;
    type InputType = in_addr;

    #[inline]
    fn from(value: Self::InputType) -> Self 
    {
        return Self(value);
    }

    #[inline]
    fn get(self) -> Self::DataType
    {
        return <Ipv4Addr as LocalFrom<in_addr>>::from(self.0);
    }

     #[inline]
    fn from_user(ip4: Self::DataType) -> Self where Self: Sized
    {
        return Self(<in_addr as LocalFrom<&Ipv4Addr>>::from(&ip4),);
    }
}

impl OptRMarker for IpMulticastIf {}
impl OptWMarker for IpMulticastIf {}