Thread: socket functions...

  1. #1
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002

    socket functions...

    i am using all of these functions in some of my codes but actually dont know
    what they are exactly doing.
    htons() -- "Host to Network Short"
    htonl() -- "Host to Network Long"
    ntohs() -- "Network to Host Short"
    ntohl() -- "Network to Host Long"
    there are others like atoi()....
    can someone explain me how these functions work/what they do?


  2. #2
    Registered User
    Join Date
    Oct 2002
    These functions are used to overcome byte-ordering differences which may occur between the network protocol (e.g. TCP/IP) and the OS.

    byte ordering relates to whether or not the first bit in an 8-bit byte is the large bit or the small bit (Big-Endian or Little-Endian). As you say, the function acronyms relate to the following...

    H = Host
    N = Network
    L = Long ( really a 32-bit value )
    S = Short ( really a 16-bit value )

  3. #3
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    its clearer to me now thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Non-blocking socket connection problem
    By cbalu in forum Linux Programming
    Replies: 25
    Last Post: 06-03-2009, 02:15 AM
  2. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  3. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  4. Re-enabling functions
    By Hunter2 in forum Networking/Device Communication
    Replies: 7
    Last Post: 02-02-2005, 12:49 PM
  5. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM