i386 long Vs alpha long: htons/ntohs question.

From: Gigi Sullivan (sullivan@sikurezza.org)
Date: Thu Jan 27 2000 - 01:36:43 EST

Hello there to all :)

        Maybe this could be a newbie question, but I never though at
        this scenario before yestarday and I cannot try it to be sure,
        so ... I'm asking here :)

        Let's consider this normal little data transfer between an
        alpha architecture machine and an i386 one.

        Host A will be the machine running on top of an alpha processor.
        Host I will be the machine running on top of an i386 processor.

        (Nontheless to say that both A and I are running Linux as OS)

        Host A:


        unsigned long data = 0xffffffffffffffff;

        data = htonl(data);
        send(fd, (char *) &data, sizeof(data), 0);

        where, obviously `fd' represent a connected socket to the `I' machine.
        (We're using TCP as Transport Protocol)

        Host I:

        unsigned long data;

        recv(fd, (char *)&data, sizeof(data), 0);
        data = ntohl(data);

        printf("data received: %ld\n", data);

        where here too, fd represent a connected socket (TCP) to `A' machine.

        On both machine, ntohs/htons will handle the right byte ordering stuff.
        TCP and IP will transmit the right number of byte (8 on alpha for a long)

        What will happen at receive time on the host `I' (i386) where a long is
        4 byte long ?

        Shall I see 0xffffffffffffffff or shall I lost some info ?
        Well, the info isn't lost. It will remain in the TCP input buffer queue
        `till a further recv(). Right ?
        But with only a recv() I'll get only 4 byte (as sizeof(long) on i386)
        Is all this right ?
        Could someone give me other infos ?

        Thx a lot and ... Have a nice day/night ... well whatever :))

bye bye

                                                                -- gg sullivan

Lorenzo Cavallaro	`Gigi Sullivan' <sullivan@sikurezza.org>      -- ITALY

Until I loved, life had no beauty; I did not know I lived until I had loved. (Theodor Korner) - To unsubscribe from this list: send the line "unsubscribe linux-net" in the body of a message to majordomo@vger.rutgers.edu

This archive was generated by hypermail 2b29 : Mon Jan 31 2000 - 21:00:32 EST