Mega stuck at if(client.connect..) when configuring PORTB7..4 as inputs

On a Arduino mega

Whenever I configure PORTB's available bits i.e bits 7-4 (3-0 used in spi) as inputs, my code deadlocks at if(client.connect) found in the example web client or the playground's SurferTim's email client

Below the code

DDRB&=0x0f; // set pin portB 4-7 as input, leave other untouched

Yet, the dhcp client and the ntp client works perfectly well with these bits as input

And curiously, with a simplified version exhibiting the very problem, the if statement exits with failure instead of deadlock

Any idea?
Whole day wasted on this

Thanks in advance

PORTB pin 4 (PB4) is D10. That is the w5100 slave select. I don't know when you are changing that pin , but it must be an OUTPUT on a Mega. DHCP and NTP shouldn't work either. I'm surprised they do.


PB5 and up is ok.

That's stupid of me!

Ntp and dhcp were only used upon setup before port B configuration

Thanks