]> git.llucax.com Git - software/posixx.git/blob - test/socket/inet/common.hpp
Improve handling of CFLAGS and LDFLAGS make variables
[software/posixx.git] / test / socket / inet / common.hpp
1 #ifndef TEST_SOCKET_IP_COMMON_HPP_
2 #define TEST_SOCKET_IP_COMMON_HPP_
3
4 #include <posixx/socket/inet.hpp> // posixx::socket::inet
5 #include <posixx/socket/opt.hpp> // posixx::socket::opt::REUSEADDR
6 #include <ostream> // std::ostream
7
8 #define IP "127.0.0.1"
9 #define PORT1 10001
10 #define PORT2 10002
11
12 static inline
13 std::ostream& operator << (std::ostream& os,
14                 const posixx::socket::inet::sockaddr& sa) throw()
15 {
16         return os << "inet::sockaddr(family=" << sa.sin_family
17                 << ", port=" << ntohs(sa.sin_port)
18                 << ", addr=" << inet_ntoa(sa.sin_addr) << ")";
19 }
20
21 static inline
22 void clean_test_address(posixx::socket::inet::socket& socket,
23                 const posixx::socket::inet::sockaddr& addr)
24 {
25         // reuse the socket address (just in case)
26         socket.opt< posixx::socket::opt::REUSEADDR >(true);
27 }
28
29 static posixx::socket::inet::sockaddr test_address1(PORT1, IP);
30 static posixx::socket::inet::sockaddr test_address2(PORT2, IP);
31
32 #endif // TEST_SOCKET_IP_COMMON_HPP_