X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fliboping.c;h=396f489f3d0b1d0d2f9ef382dbfc266f2ea0c189;hb=2599a5dc9ee489282f799ec6ceb7130c703eab73;hp=40a0ba21b570bab19fea04fc71d8c69231125173;hpb=4710e5477bfa3902b5f5600475ea21c44fabf446;p=liboping.git diff --git a/src/liboping.c b/src/liboping.c index 40a0ba2..396f489 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -1,6 +1,6 @@ /** * Object oriented C module to send ICMP and ICMPv6 `echo's. - * Copyright (C) 2006-2011 Florian octo Forster + * Copyright (C) 2006-2016 Florian octo Forster * * 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 @@ -142,6 +142,9 @@ struct pingobj char *device; + char set_mark; + int mark; + char errmsg[PING_ERRMSG_LEN]; pinghost_t *head; @@ -295,12 +298,12 @@ static pinghost_t *ping_receive_ipv4 (pingobj_t *obj, char *buffer, buffer += ip_hdr_len; buffer_len -= ip_hdr_len; - if (buffer_len < sizeof (struct icmp)) + if (buffer_len < sizeof (struct icmphdr)) return (NULL); icmp_hdr = (struct icmp *) buffer; - buffer += sizeof (struct icmp); - buffer_len -= sizeof (struct icmp); + buffer += sizeof (struct icmphdr); + buffer_len -= sizeof (struct icmphdr); if (icmp_hdr->icmp_type != ICMP_ECHOREPLY) { @@ -311,7 +314,7 @@ static pinghost_t *ping_receive_ipv4 (pingobj_t *obj, char *buffer, recv_checksum = icmp_hdr->icmp_cksum; icmp_hdr->icmp_cksum = 0; calc_checksum = ping_icmp4_checksum ((char *) icmp_hdr, - sizeof (struct icmp) + buffer_len); + sizeof (struct icmphdr) + buffer_len); if (recv_checksum != calc_checksum) { @@ -822,7 +825,7 @@ static int ping_send_one_ipv4 (pingobj_t *obj, pinghost_t *ph) memset (buf, '\0', sizeof (buf)); icmp4 = (struct icmp *) buf; - data = (char *) (icmp4 + 1); + data = buf + sizeof (struct icmphdr); icmp4->icmp_type = ICMP_ECHO; icmp4->icmp_code = 0; @@ -830,11 +833,11 @@ static int ping_send_one_ipv4 (pingobj_t *obj, pinghost_t *ph) icmp4->icmp_id = htons (ph->ident); icmp4->icmp_seq = htons (ph->sequence); - buflen = 4096 - sizeof (struct icmp); + buflen = sizeof(buf) - sizeof (struct icmphdr); strncpy (data, ph->data, buflen); datalen = strlen (data); - buflen = datalen + sizeof (struct icmp); + buflen = datalen + sizeof (struct icmphdr); icmp4->icmp_cksum = ping_icmp4_checksum (buf, buflen); @@ -1322,6 +1325,19 @@ int ping_setopt (pingobj_t *obj, int option, void *value) } /* 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) */ @@ -1508,6 +1524,23 @@ int ping_host_add (pingobj_t *obj, const char *host) } } #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) /* {{{ */ {