Module Name: src Committed By: pooka Date: Mon Aug 9 15:07:51 UTC 2010
Modified Files: src/tests/net/config: netconfig.c Log Message: add a simple pingtest To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/net/config/netconfig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/net/config/netconfig.c diff -u src/tests/net/config/netconfig.c:1.3 src/tests/net/config/netconfig.c:1.4 --- src/tests/net/config/netconfig.c:1.3 Mon Jul 26 14:07:04 2010 +++ src/tests/net/config/netconfig.c Mon Aug 9 15:07:51 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: netconfig.c,v 1.3 2010/07/26 14:07:04 pooka Exp $ */ +/* $NetBSD: netconfig.c,v 1.4 2010/08/09 15:07:51 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: netconfig.c,v 1.3 2010/07/26 14:07:04 pooka Exp $"); +__RCSID("$NetBSD: netconfig.c,v 1.4 2010/08/09 15:07:51 pooka Exp $"); #endif /* not lint */ #include <sys/types.h> @@ -39,7 +39,11 @@ #include <arpa/inet.h> #include <net/route.h> + #include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> #include <atf-c.h> #include <errno.h> @@ -162,3 +166,43 @@ } rump_sys_close(s); } + +static bool +netcfg_rump_pingtest(const char *dst, int ms_timo) +{ + struct timeval tv; + struct sockaddr_in sin; + struct icmp icmp; + socklen_t slen; + int s; + + s = rump_sys_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP); + if (s == -1) + return false; + tv.tv_sec = ms_timo / 1000; + tv.tv_usec = 1000 * (ms_timo % 1000); + if (rump_sys_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, + &tv, sizeof(tv)) == -1) + return false; + + memset(&sin, 0, sizeof(sin)); + sin.sin_len = sizeof(sin); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = inet_addr(dst); + + memset(&icmp, 0, sizeof(icmp)); + icmp.icmp_type = ICMP_ECHO; + icmp.icmp_id = htons(37); + icmp.icmp_cksum = htons(0xf7da); /* precalc */ + + slen = sizeof(sin); + if (rump_sys_sendto(s, &icmp, sizeof(icmp), 0, + (struct sockaddr *)&sin, slen) == -1) + return false; + + if (rump_sys_recvfrom(s, &icmp, sizeof(icmp), 0, + (struct sockaddr *)&sin, &slen) == -1) + return false; + + return true; +}