blob: c0f2f54f9ba576c4bef0c035d83e651fa5307e15 [file] [log] [blame]
Alexandre Lisionddd731e2014-01-31 11:50:08 -05001// Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
2//
3// This file is part of GNU uCommon C++.
4//
5// GNU uCommon C++ is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published
7// by the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GNU uCommon C++ is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GNU ucommon. If not, see <http://www.gnu.org/licenses/>.
17
18#ifndef DEBUG
19#define DEBUG
20#endif
21
22#include <ucommon/ucommon.h>
23
24#include <stdio.h>
25
26using namespace UCOMMON_NAMESPACE;
27
28static Socket::address localhost("127.0.0.1", 4444);
29#ifdef AF_INET6
30static Socket::address testing6("44:022:66::1", 4444);
31static Socket::address localhost6("::1", 4444);
32#endif
33
34extern "C" int main()
35{
36 struct sockaddr_internet addr;
37
38 char addrbuf[128];
39 addrbuf[0] = 0;
40 assert(localhost.get(AF_INET) != NULL);
41 Socket::query(localhost.get(AF_INET), addrbuf, sizeof(addrbuf));
42 assert(0 == strcmp(addrbuf, "127.0.0.1"));
43 Socket::via((struct sockaddr *)&addr, localhost.get(AF_INET));
44 Socket::query((struct sockaddr *)&addr, addrbuf, sizeof(addrbuf));
45 assert(0 == strcmp(addrbuf, "127.0.0.1"));
46 assert(eq((struct sockaddr *)&addr, localhost.get(AF_INET)));
47 assert(eq_subnet((struct sockaddr *)&addr, localhost.get(AF_INET)));
48#ifdef AF_INET6
49 // we can only test if interface/ipv6 support is actually running
50 // so we use getinterface to find out first. it will return -1 for
51 // localhost interface if ipv6 is down...
52 assert(localhost6.get(AF_INET6) != NULL);
53 if(!Socket::via((struct sockaddr *)&addr, localhost6.get(AF_INET6))) {
54 Socket::query((struct sockaddr *)&addr, addrbuf, sizeof(addrbuf));
55 assert(0 == strcmp(addrbuf, "::1"));
56 assert(Socket::equal((struct sockaddr *)&addr, localhost6.get(AF_INET6)));
57 Socket::query(testing6.get(AF_INET6), addrbuf, sizeof(addrbuf));
58 assert(0 == strcmp(addrbuf, "44:22:66::1"));
59 }
60#endif
61 return 0;
62}