/**
* 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
char *device;
+ char set_mark;
+ int mark;
+
char errmsg[PING_ERRMSG_LEN];
pinghost_t *head;
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)
{
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)
{
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;
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);
} /* 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) */
}
}
#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) /* {{{ */
{