Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does boost have portable way to use ntohl/htonl/ntohs/htons type functions?

Tags:

c++

boost

udp

I am using UDP in particular boost::asio::ip::udp::socket sockets if that helps?

What is the header file?

What headers/classes do I need to handle network byte ordering with the UDP under boost?

like image 403
dubnde Avatar asked Aug 06 '10 09:08

dubnde


People also ask

What are Htonl and Ntohl?

The htonl() function converts the unsigned integer hostlong from host byte order to network byte order. The htons() function converts the unsigned short integer hostshort from host byte order to network byte order. The ntohl() function converts the unsigned integer netlong from network byte order to host byte order.

What is the use of Htonl?

The htonl function takes a 32-bit number in host byte order and returns a 32-bit number in the network byte order used in TCP/IP networks (the AF_INET or AF_INET6 address family). The htonl function can be used to convert an IPv4 address in host byte order to the IPv4 address in network byte order.

What is Ntohl?

The ntohl function takes a 32-bit number in TCP/IP network byte order (the AF_INET or AF_INET6 address family) and returns a 32-bit number in host byte order. The ntohl function can be used to convert an IPv4 address in network byte order to the IPv4 address in host byte order.


1 Answers

Just found it is enough to #include <boost/asio.hpp> as this pulls in all the platform dependent headers and gives access to htonl/ntohl which is exactly what I need.

Thanks all for the suggestions.

like image 189
dubnde Avatar answered Sep 20 '22 23:09

dubnde