Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Test of NETDB.H functions - you need a real Internet connection for this!
27 #include <sys/types.h>
28 #include <sys/socket.h>
29 #include <sys/ioctl.h>
30 #include <libc/netinet/in.h>
31 #include <libc/arpa/inet.h>
35 #include "CTEST.H" /* includes C interface to EPOC32 threads, and SpawnPosixServer */
40 unsigned long addresses[N_ADDRESSES][3] =
42 { 121, 0x112233, 0x79112233 }, /* class A 121.xxxxxxxx */
43 { 33771, 0x1122, 0x83eb1122 }, /* class B 131.235.xxxx */
44 { 12747009, 90, 0xc281015a } /* class C 194.129.1.xx */
48 @SYMTestCaseID SYSLIB-STDLIB-CT-1072
49 @SYMTestCaseDesc Tests for ARPA net functions
51 @SYMTestActions Tests for all basic network functions
52 @SYMTestExpectedResults Test must not fail
60 unsigned long ul1, ul2;
64 test_Next("ARPA/INET.H functions");
68 err=inet_aton(cp, &iaddr);
70 test(iaddr.s_addr==htonl(0x10213243));
71 test(iaddr.s_addr==inet_addr(cp));
73 test(strcmp(cp2,cp)==0);
76 err=inet_aton("16.rubbish.67", &iaddr);
79 for (i=0;i<N_ADDRESSES;i++)
81 iaddr=inet_makeaddr(addresses[i][0], addresses[i][1]);
82 test(iaddr.s_addr==ntohl(addresses[i][2]));
83 ul1=inet_netof(iaddr);
84 ul2=inet_lnaof(iaddr);
85 test(ul1==addresses[i][0]);
86 test(ul2==addresses[i][1]);
91 const char* names[N_NAMES][3] =
93 { "phoenix.doc.ic.ac.uk", "146.169.1.160", "phoenix.doc.ic.ac.uk" },
94 { "httpsmtp.test.intra", "192.168.20.11", "httpsmtp.test.intra" },
95 { "unix.sri.com", "128.18.30.211", "unix.sri.com" }
101 @SYMTestCaseID SYSLIB-STDLIB-CT-1073
102 @SYMTestCaseDesc Tests for ARPA net functions
103 @SYMTestPriority High
104 @SYMTestActions Tests for get host by name and host by address functions
105 @SYMTestExpectedResults Test must not fail
111 struct in_addr addr, *addrp;
115 test_Next("Get Host Name");
117 err=gethostname(hostname,sizeof(hostname));
119 printf(" hostname = >%s<\n", hostname);
121 test_Next("Get Host By Name");
123 for (i=0; i<N_NAMES; i++)
125 hp=gethostbyname(names[i][0]);
127 addrp=(struct in_addr*)(hp->h_addr_list[0]);
128 printf(" %-30s => address %-15s\n", hp->h_name, inet_ntoa(*addrp));
129 test(strcasecmp(hp->h_name,names[i][0])==0);
130 test(addrp->s_addr==inet_addr(names[i][1]));
133 hp=gethostbyname("nosuchname.symbian.com");
134 test_errno(hp==0,ENOENT);
135 test(errno==HOST_NOT_FOUND);
137 test_Next("Get Address of \"\"");
138 hp=gethostbyname("");
140 addrp=(struct in_addr*)(hp->h_addr_list[0]);
141 printf(" %-30s => address %-15s\n", hp->h_name, inet_ntoa(*addrp));
143 test_Next("Get Host By Addr");
145 for (i=0; i<N_NAMES; i++)
147 addr.s_addr=inet_addr(names[i][1]);
148 hp=gethostbyaddr((const char *)&addr,sizeof(addr),AF_INET);
150 addrp=(struct in_addr*)(hp->h_addr_list[0]);
151 printf(" address %-15s => %s\n", inet_ntoa(*addrp), hp->h_name);
152 test(addrp->s_addr==addr.s_addr);
153 test(strcasecmp(hp->h_name,names[i][2])==0);
156 addr.s_addr=inet_addr("10.11.199.255");
157 hp=gethostbyaddr((const char *)&addr,sizeof(addr),AF_INET);
158 test_errno(hp==0,ENOENT);
159 test(errno==HOST_NOT_FOUND);
162 struct sockaddr_in testaddr;
164 test_Next("Connect to the Imperial College Echo server");
166 fd=socket(AF_INET, SOCK_STREAM, 0);
168 testaddr.sin_family=AF_INET;
169 testaddr.sin_addr.s_addr=inet_addr("193.63.255.1");
170 testaddr.sin_port=htons(7); // echo
171 err=connect(fd,(struct sockaddr*)&testaddr, sizeof(testaddr));
176 test_Next("Get Address of roundrobin.test.intra which has multiple address");
177 hp=gethostbyname("roundrobin.test.intra");
185 while (hp->h_addr_list[Index])
187 addrp = (struct in_addr*)(hp->h_addr_list[Index]);
188 printf(" %-30s => address %-15s\n", hp->h_name, inet_ntoa(*addrp));
194 test_Next("Get Host name of 192.168.255.4 which has multiple host name");
195 addr.s_addr=inet_addr("192.168.255.4");
196 hp=gethostbyaddr((const char *)&addr,sizeof(addr),AF_INET);
201 addrp=(struct in_addr*)(hp->h_addr_list[0]);
202 printf(" address %-15s => %s\n", inet_ntoa(*addrp), hp->h_name);
207 while (hp->h_aliases[Index])
209 printf(" address %-15s => %s\n", inet_ntoa(*addrp), hp->h_aliases[Index]);
225 int main(int argc, char *argv[])
230 test_Title("NETDB.H Functionality");
232 err=CommInit(0); /* ensure a workable comms environment */
235 testArpa(); /* doesn't use the MSystemInterface so only tested once */
239 /* Run the test(s) without a CPosixServer first */
243 test_Next("Do it all using the CPosixServer (for them, not me)");
246 start_posix_server(); /* calls SpawnPosixServer from C++ code */
248 client=create_thread(testNetDB, "TNETDB NetDB");
250 start_thread(client);
251 err=wait_for_thread(client);