6

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?

dubnde
  • 4,359
  • 9
  • 43
  • 63
  • [This ](http://stackoverflow.com/questions/105252/how-do-i-convert-between-big-endian-and-little-endian-values-in-c/107099#107099) looks like a Boost solution. – Kirill V. Lyadvinsky Aug 06 '10 at 11:01
  • What isn't portable about htons et al already? – Steve-o Aug 09 '10 at 02:53
  • @Steve-o. Thanks for pointing that out. I am aware the implementation is portable. However, I can not find a portable header. I have to include different headers for windows and for *nix as an example. So I have do modify the code depending on platforms. I will probably create a header and put preprocessor directives to include headers depending on platforms. – dubnde Aug 09 '10 at 08:45

4 Answers4

12

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.

dubnde
  • 4,359
  • 9
  • 43
  • 63
6

boost::asio::detail::socket_ops::host_to_network_short in boost/asio/detail/socket_ops.hpp

syffinx
  • 351
  • 4
  • 6
2

POSIX.1-2001 standard is <sys/types.h> & <netinet/in.h>, on Windows you have 2 stacks to choose from <winsock2.h> or <ws2tcpip.h> & <winsock2.h>, the latter is now the preferred choice as it supports Unicode naming but note that they are incompatible.

Platforms pre-2001 might require other headers such as <arpa/inet.h>.

Steve-o
  • 12,678
  • 2
  • 41
  • 60
1

For Windows:

http://msdn.microsoft.com/en-us/library/ms738556(VS.85).aspx

For *nix:

http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/apis/htonl.htm

A quick search did not provide anything resonable in boost.
Hopefuuly somebody else will find somthing.

Martin York
  • 257,169
  • 86
  • 333
  • 562