Thread: big/little endian issues

  1. #1
    Registered User
    Join Date
    Jan 2004

    big/little endian issues

    I was reading about unix network programming when i found about the big/little endian problem. Im working on PC(as we know Intel-based processors are little-endian), and if i need to send multi-byte numbers over a network, i have to convert them to big-endian format. My question is this, in a certain way, affects the character strings too? if im going to transmit any string, do i have to convert it in some format in order to send it over a network?

    Thanks in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    htonl, htons, ntohl, ntohs − convert values between host and network
    byte order

    #include <netinet/in.h>

    uint32_t htonl(uint32_t hostlong);

    uint16_t htons(uint16_t hostshort);

    uint32_t ntohl(uint32_t netlong);

    uint16_t ntohs(uint16_t netshort);
    You should have these already
    Then it doesn't matter whether your machine is big or little
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Endian Question
    By carrotcake1029 in forum C Programming
    Replies: 8
    Last Post: 01-07-2009, 03:51 PM
  2. Big Endian Little Endian Complex- Converting Characters
    By bd02eagle in forum C Programming
    Replies: 3
    Last Post: 07-11-2006, 01:01 AM
  3. Big and little endian
    By Cactus_Hugger in forum C Programming
    Replies: 4
    Last Post: 10-12-2005, 07:07 PM
  4. Replies: 10
    Last Post: 06-26-2005, 11:27 AM
  5. fopen, fwrite, and endian issues
    By FireAndGlass in forum C Programming
    Replies: 7
    Last Post: 06-19-2004, 07:51 AM