Skip to content

Commit 3c1d5ca

Browse files
committed
expose htons and ntohs
1 parent 4f1e599 commit 3c1d5ca

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#ifndef SIMPLE_SOCKET_NET_BYTE_ORDER_HPP
3+
#define SIMPLE_SOCKET_NET_BYTE_ORDER_HPP
4+
5+
#include <cstdint>
6+
7+
namespace simple_socket {
8+
9+
uint32_t ss_htons(uint16_t hostshort);
10+
uint16_t ss_ntohs(uint32_t netshort);
11+
12+
}// namespace simple_socket
13+
14+
#endif//SIMPLE_SOCKET_NET_BYTE_ORDER_HPP

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ set(sources
3232

3333
"simple_socket/http/SimpleHttpFetcher.cpp"
3434

35+
"simple_socket/util/net_byteorder.cpp"
3536
"simple_socket/util/port_query.cpp"
3637
)
3738

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
#ifdef _WIN32
3+
#include <WinSock2.h>
4+
#else
5+
#include <arpa/inet.h>
6+
#endif
7+
8+
#include "simple_socket/util/net_byteorder.hpp"
9+
10+
using namespace simple_socket;
11+
12+
uint32_t ss_htons(uint16_t hostshort) {
13+
return ::htons(hostshort);
14+
}
15+
16+
uint16_t ss_ntohs(uint32_t netshort) {
17+
return ::ntohs(static_cast<uint16_t>(netshort));
18+
}

0 commit comments

Comments
 (0)