Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/net/config add a simple pingtest
details: https://anonhg.NetBSD.org/src/rev/91baa3091c61
branches: trunk
changeset: 756983:91baa3091c61
user: pooka <pooka%NetBSD.org@localhost>
date: Mon Aug 09 15:07:51 2010 +0000
description:
add a simple pingtest
diffstat:
tests/net/config/netconfig.c | 48 ++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 46 insertions(+), 2 deletions(-)
diffs (74 lines):
diff -r e0066ad0dcc8 -r 91baa3091c61 tests/net/config/netconfig.c
--- a/tests/net/config/netconfig.c Mon Aug 09 13:41:38 2010 +0000
+++ b/tests/net/config/netconfig.c Mon Aug 09 15:07:51 2010 +0000
@@ -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;
+}
Home |
Main Index |
Thread Index |
Old Index