Exemplo n.º 1
0
/**
 * Solver::__fix
 *
 * Swap two last cells in a board if unsolvable
 *
 */
inline void Solver::__fix()
{
    int cs = __checksum();
    int zx, zy = 0;
    _board.getValueXY(0, zx, zy);
    int size = _board.getSize() - 1;
    if ( size & 1 )
    {
        // for boards like 2x2(3), 2x3(5), 3x2(5), ...
        // add row index of zero
        cs += zx;
    }
    if ( ! (_board.getHeight() & 1) )
    {
        if ( ! (_board.getWidth() & 1) )
        {
            // for boards like 2x2, 4x4, ...
            // row index of zero numbered from 1
            cs += 1;
        }
        else
        {
            // for boards like 3x2, 3x4, 5x2, ...
            // add parity of zero row index
            cs += (zx & 1);
        }
    }

    // if parity odd then should swap
    if ( cs & 1 )
    {
        _board.swap(size - 1, size - 2);
    }
}
Exemplo n.º 2
0
void __ip_make_header( ip_header * ip, u08 proto, u16 ident, u16 len, u32 dest )
{
	ip->version = 0x45;
	ip->tos = 0;
	ip->length = __htons( len );
	ip->fraginfo = 0;
	ip->ident = ident;
	ip->dest_addr = dest;
	ip->src_addr = get_hostaddr();
	ip->ttl = 128;
	ip->proto = proto;
	ip->checksum = ~__htons( __checksum( ip, sizeof(ip_header) ) );
}
Exemplo n.º 3
0
static void icmp_send_reply( ip_header * reqip, icmp_header * reqping, u16 len )
{
	u08 iface;
	memset( &out, 0, sizeof(out) );

	if (!arp_make_eth_header( &out.eth, reqip->src_addr, &iface ))
		return;

	__ip_make_response( &out.ip, reqip, len );

	out.icmp.type = 0;
	out.icmp.code = 0;
	out.icmp.sequence = reqping->sequence;
	out.icmp.id = reqping->id;
	memcpy( &out.crap, reqping + 1, len - sizeof( ip_header ) - sizeof( icmp_header ) );
	out.icmp.checksum = ~__htons(__checksum( &out.icmp, len - sizeof( ip_header ) ));

	__send_packet( iface, &out, len + sizeof( eth_header ) );
}