Пример #1
0
/*--------------------------------------------------------------------*/
void build_herc_iface_mac ( BYTE* out_mac, const BYTE* in_ip )
{
    // Routine to build a default MAC address for
    // CTCI/LCS/QETH device virtual interfaces...

BYTE ip[4];

    if (!out_mac)
    {
        ASSERT( FALSE );
        return;             // (nothing for us to do!)
    }

    // We base our default MAC address on the last three bytes
    // of the IPv4 address (see further below). If it doesn't
    // have an IP address assigned to it yet however (in_ip is
    // NULL), then we temporarily generate a random IP address
    // only for the purpose of generating a default/random MAC.

    if (in_ip)
        memcpy( ip, in_ip, 4 );   // (use the passed value)
    else                          // (else create temporary)
    {
        int i; for(i=0; i < 4; i++)
            ip[i] = (BYTE)(rand() % 256);
    }

#if defined( OPTION_W32_CTCI )

    // We prefer to let TunTap32 do it for us (since IT'S the one
    // that decides what it should really be) but if they're using
    // an older version of TunTap32 that doesn't have the function
    // then we'll do it ourselves just like before...

    if (tt32_build_herc_iface_mac( out_mac, ip ))
    {
        out_mac[0] &= ~0x01;    // (ensure broadcast bit off)
        out_mac[0] |=  0x02;    // (set local assignment bit)
        return;
    }

#endif

    // Build a default MAC addr based on the guest (destination) ip
    // address so as to effectively *UNOFFICIALLY* assign ourselves
    // the following Ethernet address block:

    /* (from: http://www.iana.org/assignments/ethernet-numbers)
       (only the first 2 and last 2 paragraphs are of interest)

        IANA ETHERNET ADDRESS BLOCK - UNICAST USE

        The IANA owns an Ethernet address block which may be used for
        unicast address asignments or other special purposes.

        The IANA may assign unicast global IEEE 802 MAC address from it's
        assigned OUI (00-00-5E) for use in IETF standard track protocols.  The
        intended usage is for dynamic mapping between IP addresses and IEEE
        802 MAC addresses.  These IEEE 802 MAC addresses are not to be
        permanently assigned to any hardware interface, nor is this a
        substitute for a network equipment supplier getting its own OUI.

        ... (snipped)

        Using this representation, the range of Internet Unicast addresses is:

               00-00-5E-00-00-00  to  00-00-5E-FF-FF-FF  in hex, ...

        ... (snipped)

        The low order 24 bits of these unicast addresses are assigned as
        follows:

        Dotted Decimal          Description                     Reference
        ----------------------- ------------------------------- ---------
        000.000.000-000.000.255 Reserved                        [IANA]
        000.001.000-000.001.255 Virual Router Redundancy (VRRP) [Hinden]
        000.002.000-127.255.255 Reserved                        [IANA]
        128.000.000-255.255.255 Hercules TUNTAP (CTCI)          [Fish] (*UNOFFICIAL*)
    */

    // Here's what we're basically doing:

    //    00-00-5E-00-00-00  to  00-00-5E-00-00-FF  =  'Reserved' by IANA
    //    00-00-5E-00-01-00  to  00-00-5E-00-01-FF  =  'VRRP' by Hinden
    //    00-00-5E-00-02-00  to  00-00-5E-7F-FF-FF  =  (unassigned)
    //    00-00-5E-80-00-00  to  00-00-5E-FF-FF-FF  =  'Hercules' by Fish (*UNOFFICIAL*)

    //    00-00-5E-00-00-00   (starting value)
    //    00-00-5E-ip-ip-ip   (move in low-order 3 bytes of destination IP address)
    //    00-00-5E-8p-ip-ip   ('OR' on the x'80' high-order bit)

    out_mac[0] = 0x02;          // (set local assignment bit)
    out_mac[1] = 0x00;
    out_mac[2] = 0x5E;
    out_mac[3] = ip[1] | 0x80;  // (Hercules *UNOFFICIAL* range)
    out_mac[4] = ip[2];
    out_mac[5] = ip[3];
}
Пример #2
0
/* ------------------------------------------------------------------ */
void build_herc_iface_mac ( BYTE* out_mac, const BYTE* in_ip )
{
    // Routine to build a default MAC address for the CTCI devices
    // virtual interface... (used by ctc_ctci.c CTCI_Init function)

    if (!in_ip || !out_mac)
    {
        ASSERT( FALSE );
        return;                 // (nothing for us to do!)
    }

#if defined( OPTION_W32_CTCI )

    // We prefer to let TunTap32 do it for us (since IT'S the one
    // that decides what it should really be) but if they're using
    // an older version of TunTap32 that doesn't have the function
    // then we'll do it ourselves just like before...

    if (tt32_build_herc_iface_mac( out_mac, in_ip ))
        return;

#endif

    // Build a default MAC addr based on the guest (destination) ip
    // address so as to effectively *UNOFFICIALLY* assign ourselves
    // the following Ethernet address block:

    /* (from: http://www.iana.org/assignments/ethernet-numbers)
       (only the first 2 and last 2 paragraphs are of interest)

        IANA ETHERNET ADDRESS BLOCK - UNICAST USE

        The IANA owns an Ethernet address block which may be used for
        unicast address asignments or other special purposes.

        The IANA may assign unicast global IEEE 802 MAC address from it's
        assigned OUI (00-00-5E) for use in IETF standard track protocols.  The
        intended usage is for dynamic mapping between IP addresses and IEEE
        802 MAC addresses.  These IEEE 802 MAC addresses are not to be
        permanently assigned to any hardware interface, nor is this a
        substitute for a network equipment supplier getting its own OUI.

        ... (snipped)

        Using this representation, the range of Internet Unicast addresses is:

               00-00-5E-00-00-00  to  00-00-5E-FF-FF-FF  in hex, ...

        ... (snipped)

        The low order 24 bits of these unicast addresses are assigned as
        follows:

        Dotted Decimal          Description                     Reference
        ----------------------- ------------------------------- ---------
        000.000.000-000.000.255 Reserved                        [IANA]
        000.001.000-000.001.255 Virual Router Redundancy (VRRP) [Hinden]
        000.002.000-127.255.255 Reserved                        [IANA]
        128.000.000-255.255.255 Hercules TUNTAP (CTCI)          [Fish] (*UNOFFICIAL*)
    */

    // Here's what we're basically doing:

    //    00-00-5E-00-00-00  to  00-00-5E-00-00-FF  =  'Reserved' by IANA
    //    00-00-5E-00-01-00  to  00-00-5E-00-01-FF  =  'VRRP' by Hinden
    //    00-00-5E-00-02-00  to  00-00-5E-7F-FF-FF  =  (unassigned)
    //    00-00-5E-80-00-00  to  00-00-5E-FF-FF-FF  =  'Hercules' by Fish (*UNOFFICIAL*)

    //    00-00-5E-00-00-00   (starting value)
    //    00-00-5E-ip-ip-ip   (move in low-order 3 bytes of destination IP address)
    //    00-00-5E-8p-ip-ip   ('OR' on the x'80' high-order bit)

    *(out_mac+0) = 0x00;
    *(out_mac+1) = 0x00;
    *(out_mac+2) = 0x5E;
    *(out_mac+3) = *(in_ip+1) | 0x80;
    *(out_mac+4) = *(in_ip+2);
    *(out_mac+5) = *(in_ip+3);
}