Shouldn't the fix involve an appropriate use of ntohl or htonl,instead of ad-hoc shifting?
regards, tom lane