I’ve had a good look through this code and, aside from being terrible, I can’t seem to identify the problem. I suspect it may reside in the supporting libraries (maybe some sort incompatibilty?).
I don’t personally own the device you are using so hopefully someone with experience with this device can help you out. May I ask, why did you not use the inbuilt Ethernet library? I believe the above library is quite old (2006?) and may subsiquently have compatibility issues with the latest GCC-AVR