Test of the gettaddrinfo POSIX facility.

Ref #2682
This commit is contained in:
Ehmry - 2018-02-18 12:17:58 +01:00 committed by Christian Helmuth
parent 401ba6e7fd
commit e4328de251
3 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,89 @@
source ${genode_dir}/repos/base/run/platform_drv.inc
if {[have_spec linux]} {
puts "The [run_name] scenario requires QEMU networking."
exit 1
}
set build_components {
core init
drivers/timer
lib/vfs/lxip
test/libc_getaddrinfo
}
append_platform_drv_build_components
build $build_components
create_boot_directory
append config {
<config>
<parent-provides>
<service name="CPU"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="IRQ"/>
<service name="LOG"/>
<service name="PD"/>
<service name="RM"/>
<service name="ROM"/>
</parent-provides>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
<default caps="128"/>}
append_platform_drv_config
append config {
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides> <service name="Timer"/> </provides>
</start>
<start name="nic_drv">
<binary name="} [nic_drv_binary] {"/>
<resource name="RAM" quantum="4M"/>
<provides> <service name="Nic"/> </provides>
</start>
<start name="test-libc_getaddrinfo" caps="256">
<resource name="RAM" quantum="32M"/>
<config>
<vfs>
<dir name="etc">
<inline name="resolv.conf">nameserver 10.0.2.3</inline>
</dir>
<dir name="dev"> <log/> </dir>
<dir name="socket"> <lxip dhcp="yes"/> </dir>
</vfs>
<libc stdout="/dev/log" socket="/socket"/>
<arg value="test-libc_getenv"/>
<arg value="genode.org"/>
<arg value="hypervisor.org"/>
<arg value="example.com"/>
</config>
</start>
</config>
}
install_config $config
set boot_modules {
core init ld.lib.so
libc.lib.so libm.lib.so posix.lib.so
lxip.lib.so vfs_lxip.lib.so
test-libc_getaddrinfo
timer
}
# platform-specific modules
append_platform_drv_boot_modules
lappend boot_modules [nic_drv_binary]
build_boot_image $boot_modules
append qemu_args " -nographic -net nic,model=e1000 -net user -net dump,file=[run_dir]/dump.pcap"
run_genode_until "child .* exited with exit value 0.*\n" 20

View File

@ -0,0 +1,63 @@
/*
* \brief Libc getaddrinfo(...) test
* \author Emery Hemingway
* \date 2018-02-18
*/
/*
* This code lifted from Beej's Guide to Network Programming.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>
int main(int argc, char **argv)
{
struct addrinfo hints;
char ipstr[INET6_ADDRSTRLEN];
int i;
for (i = 1; i < argc; ++i) {
int res;
char const *arg = argv[i];
struct addrinfo *info, *p;
memset(&hints, 0x00, sizeof(hints));
hints.ai_family = AF_UNSPEC;
res = getaddrinfo(arg, NULL, &hints, &info);
if (res != 0) {
printf("getaddrinfo error: %d\n", res);
continue;
}
for (p = info; p != NULL; p = p->ai_next) {
void *addr;
// get the pointer to the address itself,
// different fields in IPv4 and IPv6:
if (p->ai_family == AF_INET) { // IPv4
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
addr = &(ipv4->sin_addr);
} else { // IPv6
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
addr = &(ipv6->sin6_addr);
}
inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
printf("%s: %s\n", arg, ipstr);
break;
}
freeaddrinfo(info);
}
return 0;
}

View File

@ -0,0 +1,3 @@
TARGET = test-libc_getaddrinfo
SRC_C = main.c
LIBS = posix