diff --git a/src/liboping.c b/src/liboping.c
index 74122a80f63706c4c9166f30bba50f6c6e3a3073..d99129ccc3c186d8ba7b8e6b5eec75ed2e0673bc 100644 (file)
--- a/src/liboping.c
+++ b/src/liboping.c
/**
* Object oriented C module to send ICMP and ICMPv6 `echo's.
/**
* Object oriented C module to send ICMP and ICMPv6 `echo's.
- * Copyright (C) 2006-2011 Florian octo Forster <ff at octo.it>
+ * Copyright (C) 2006-2016 Florian octo Forster <ff at octo.it>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
char *device;
char *device;
+ char set_mark;
+ int mark;
+
char errmsg[PING_ERRMSG_LEN];
pinghost_t *head;
char errmsg[PING_ERRMSG_LEN];
pinghost_t *head;
return (0);
}
return (0);
}
+/* Blocks until a packet was received from all hosts or the timeout is reached.
+ * When interrupted, (-EINTR) is returned. On error, -1 is returned. On
+ * success, returns zero. */
static int ping_receive_all (pingobj_t *obj)
{
fd_set read_fds;
static int ping_receive_all (pingobj_t *obj)
{
fd_set read_fds;
if ((status == -1) && (errno == EINTR))
{
dprintf ("select was interrupted by signal..\n");
if ((status == -1) && (errno == EINTR))
{
dprintf ("select was interrupted by signal..\n");
- continue;
+ ping_set_errno (obj, EINTR);
+ return (-EINTR);
}
else if (status < 0)
{
}
else if (status < 0)
{
} /* while (1) */
return (ret);
} /* while (1) */
return (ret);
-}
+} /* int ping_receive_all */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Sending functions: *
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Sending functions: *
} /* case PING_OPT_DEVICE */
break;
} /* case PING_OPT_DEVICE */
break;
+ case PING_OPT_MARK:
+ {
+#ifdef SO_MARK
+ obj->mark = *(int*)(value);
+ obj->set_mark = 1;
+#else /* SO_MARK */
+ ping_set_errno (obj, ENOTSUP);
+ ret = -1;
+#endif /* !SO_MARK */
+
+ } /* case PING_OPT_MARK */
+ break;
+
default:
ret = -2;
} /* switch (option) */
default:
ret = -2;
} /* switch (option) */
int ping_send (pingobj_t *obj)
{
int ping_send (pingobj_t *obj)
{
- int ret;
-
if (obj == NULL)
return (-1);
if (ping_send_all (obj) < 0)
return (-1);
if (obj == NULL)
return (-1);
if (ping_send_all (obj) < 0)
return (-1);
- if ((ret = ping_receive_all (obj)) < 0)
- return (-2);
-
- return (ret);
+ return (ping_receive_all (obj));
}
static pinghost_t *ping_host_search (pinghost_t *ph, const char *host)
}
static pinghost_t *ping_host_search (pinghost_t *ph, const char *host)
}
}
#endif /* SO_BINDTODEVICE */
}
}
#endif /* SO_BINDTODEVICE */
+#ifdef SO_MARK
+ if(obj->set_mark)
+ {
+ if(setsockopt(ph->fd, SOL_SOCKET, SO_MARK, &(obj->mark), sizeof(obj->mark)) != 0)
+ {
+#if WITH_DEBUG
+ char errbuf[PING_ERRMSG_LEN];
+ dprintf ("setsockopt (SO_MARK): %s\n",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+#endif
+ ping_set_errno (obj, errno);
+ close (ph->fd);
+ ph->fd = -1;
+ continue;
+ }
+ }
+#endif
#ifdef SO_TIMESTAMP
if (1) /* {{{ */
{
#ifdef SO_TIMESTAMP
if (1) /* {{{ */
{