1 /**
2 * Object oriented C module to send ICMP and ICMPv6 `echo's.
3 * Copyright (C) 2006 Florian octo Forster <octo at verplant.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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 General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
20 #ifndef OCTO_PING_H
21 #define OCTO_PING_H 1
23 #if HAVE_CONFIG_H
24 # include <config.h>
25 #endif
27 #if HAVE_STDLIB_H
28 # include <stdlib.h>
29 #endif
30 #if HAVE_UNISTD_H
31 # include <unistd.h>
32 #endif
33 #if HAVE_SYS_SOCKET_H
34 # include <sys/socket.h>
35 #endif
37 /*
38 * Type definitions
39 */
40 typedef struct pinghost
41 {
42 char *hostname;
43 struct sockaddr_storage *addr;
44 socklen_t addrlen;
45 int addrfamily;
46 int fd;
47 int ident;
48 int sequence;
49 struct timeval *timer;
50 double latency;
52 struct pinghost *next;
53 } pinghost_t;
55 typedef pinghost_t pingobj_iter_t;
57 typedef struct pingobj
58 {
59 double timeout;
60 int ttl;
61 int addrfamily;
63 pinghost_t *head;
64 } pingobj_t;
66 #define PING_OPT_TIMEOUT 0x01
67 #define PING_OPT_TTL 0x02
68 #define PING_OPT_AF 0x04
70 #define PING_DEF_TIMEOUT 1.0
71 #define PING_DEF_TTL 255
72 #define PING_DEF_AF AF_UNSPEC
74 /*
75 * Method definitions
76 */
77 pingobj_t *ping_construct (void);
78 void ping_destroy (pingobj_t *obj);
80 int ping_setopt (pingobj_t *obj, int option, void *value);
82 int ping_send (pingobj_t *obj);
84 int ping_host_add (pingobj_t *obj, const char *host);
85 int ping_host_remove (pingobj_t *obj, const char *host);
87 pingobj_iter_t *ping_iterator_get (pingobj_t *obj);
88 pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter);
90 const char *ping_iterator_get_host (pingobj_iter_t *iter);
91 double ping_iterator_get_latency (pingobj_iter_t *iter);
93 #endif /* OCTO_PING_H */