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, net::Ipv6Addr,fmt};

use crate::{IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, LocalFrom, OptWMarker, SockOptMarker, ipv6_mreq, in6_addr};

#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct Ip6AddMembership(ipv6_mreq);


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

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

impl SockOptMarker for Ip6AddMembership
{
    const SO_LEVEL: c_int = IPPROTO_IPV6;   
    const SO_OPTNAME: c_int = IPV6_ADD_MEMBERSHIP;

    /// (imr_multiaddr, imr_interface)
    type DataType = (Ipv6Addr, u32);
    type InputType = ();

    #[inline]
    fn from(_value: Self::InputType) -> Self 
    {
        panic!("Ip6AddMembership cannot be read");
    }

    #[inline]
    fn get(self) -> Self::DataType
    {
        panic!("Ip6AddMembership cannot be consumed");
    }

    #[inline]
    fn from_user(inp: Self::DataType) -> Self where Self: Sized
    {
        return Self( 
            ipv6_mreq
            { 
                ipv6mr_multiaddr: <in6_addr as LocalFrom<&Ipv6Addr>>::from(&inp.0),
                ipv6mr_interface: inp.1,
            } 
        );
    }
}

impl OptWMarker for Ip6AddMembership {}