code:
.Dd 2004-04-09
.Dt IFENSLAVE 8
.\" Manual page created by Guus Sliepen <guus@debian.org>
.Sh NAME
.Nm ifenslave
.Nd Attach and detach slave network devices to a bonding device.
.Sh SYNOPSIS
.Nm
.Op Fl acdfhuvV
.Op Fl -all-interfaces
.Op Fl -change-active
.Op Fl -detach
.Op Fl -force
.Op Fl -help
.Op Fl -usage
.Op Fl -verbose
.Op Fl -version
.Ar master
.Ar slave
.No ...
.Sh DESCRIPTION
.Nm
is a tool to attach and detach slave network devices to a bonding device.
A bonding device will act like a normal Ethernet network device to the kernel,
but will send out the packets via the slave devices using a simple round-robin scheduler.
This allows for simple load-balancing,
identical to "channel bonding" or "trunking" techniques used in switches.
.Pp
The kernel must have support for bonding devices for
.Nm
to be useful.
.Sh OPTIONS
.Bl -tag -width indent
.It Fl a, -all-interfaces
Show information about all interfaces.
.It Fl c, -change-active
Change active slave.
.It Fl d, -detach
Removes slave interfaces from the bonding device.
.It Fl f, -force
Force actions to be taken if one of the specified interfaces appears not to belong to an Ethernet device.
.It Fl h, -help
Display a help message and exit.
.It Fl u, -usage
Show usage information and exit.
.It Fl v, -verbose
Print warning and debug messages.
.It Fl V, -version
Show version information and exit.
.El
If not options are given, the default action will be to enslave interfaces.
.Sh EXAMPLE
The following example shows how to setup a bonding device and
enslave two real Ethernet devices to it:
.Bd -literal
# modprobe bonding
# ifconfig bond0 192.168.0.1 netmask 255.255.0.0
# ifenslave bond0 eth0 eth1
.Ed
.Sh AUTHOR
.Nm
was originally written by
.An Donald Becker Aq becker@cesdis.gsfc.nasa.gov ,
and has since been updated by various kernel developers.
.Pp
This manual page was written by
.An Guus Sliepen Aq guus@debian.org
for the Debian GNU/Linux system.

repo_name: ayhanyalcinsoy/main


code:
/* Mode: C;
 * ifenslave.c: Configure network interfaces for parallel routing.
 *
 *	This program controls the Linux implementation of running multiple
 *	network interfaces in parallel.
 *
 * Author:	Donald Becker <becker@cesdis.gsfc.nasa.gov>
 *		Copyright 1994-1996 Donald Becker
 *
 *		This program is free software; you can redistribute it
 *		and/or modify it under the terms of the GNU General Public
 *		License as published by the Free Software Foundation.
 *
 *	The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
 *	Center of Excellence in Space Data and Information Sciences
 *	   Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
 *
 *  Changes :
 *    - 2000/10/02 Willy Tarreau <willy at meta-x.org> :
 *       - few fixes. Master's MAC address is now correctly taken from
 *         the first device when not previously set ;
 *       - detach support : call BOND_RELEASE to detach an enslaved interface.
 *       - give a mini-howto from command-line help : # ifenslave -h
 *
 *    - 2001/02/16 Chad N. Tindel <ctindel at ieee dot org> :
 *       - Master is now brought down before setting the MAC address.  In
 *         the 2.4 kernel you can't change the MAC address while the device is
 *         up because you get EBUSY.
 *
 *    - 2001/09/13 Takao Indoh <indou dot takao at jp dot fujitsu dot com>
 *       - Added the ability to change the active interface on a mode 1 bond
 *         at runtime.
 *
 *    - 2001/10/23 Chad N. Tindel <ctindel at ieee dot org> :
 *       - No longer set the MAC address of the master.  The bond device will
 *         take care of this itself
 *       - Try the SIOC*** versions of the bonding ioctls before using the
 *         old versions
 *    - 2002/02/18 Erik Habbinga <erik_habbinga @ hp dot com> :
 *       - ifr2.ifr_flags was not initialized in the hwaddr_notset case,
 *         SIOCGIFFLAGS now called before hwaddr_notset test
 *
 *    - 2002/10/31 Tony Cureington <tony.cureington * hp_com> :
 *       - If the master does not have a hardware address when the first slave
 *         is enslaved, the master is assigned the hardware address of that
 *         slave - there is a comment in bonding.c stating "ifenslave takes
 *         care of this now." This corrects the problem of slaves having
 *         different hardware addresses in active-backup mode when
 *         multiple interfaces are specified on a single ifenslave command
 *         (ifenslave bond0 eth0 eth1).
 *
 *    - 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
 *                   Shmulik Hen <shmulik.hen at intel dot com>
 *       - Moved setting the slave's mac address and openning it, from
 *         the application to the driver. This enables support of modes
 *         that need to use the unique mac address of each slave.
 *         The driver also takes care of closing the slave and restoring its
 *         original mac address upon release.
 *         In addition, block possibility of enslaving before the master is up.
 *         This prevents putting the system in an undefined state.
 *
 *    - 2003/05/01 - Amir Noam <amir.noam at intel dot com>
 *       - Added ABI version control to restore compatibility between
 *         new/old ifenslave and new/old bonding.
 *       - Prevent adding an adapter that is already a slave.
 *         Fixes the problem of stalling the transmission and leaving
 *         the slave in a down state.
 *
 *    - 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
 *       - Prevent enslaving if the bond device is down.
 *         Fixes the problem of leaving the system in unstable state and
 *         halting when trying to remove the module.
 *       - Close socket on all abnormal exists.
 *       - Add versioning scheme that follows that of the bonding driver.
 *         current version is 1.0.0 as a base line.
 *
 *    - 2003/05/22 - Jay Vosburgh <fubar at us dot ibm dot com>
 *	 - ifenslave -c was broken; it's now fixed
 *	 - Fixed problem with routes vanishing from master during enslave
 *	   processing.
 *
 *    - 2003/05/27 - Amir Noam <amir.noam at intel dot com>
 *	 - Fix backward compatibility issues:
 *	   For drivers not using ABI versions, slave was set down while
 *	   it should be left up before enslaving.
 *	   Also, master was not set down and the default set_mac_address()
 *	   would fail and generate an error message in the system log.
 * 	 - For opt_c: slave should not be set to the master's setting
 *	   while it is running. It was already set during enslave. To
 *	   simplify things, it is now handled separately.
 *
 *    - 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
 *	 - Code cleanup and style changes
 *	   set version to 1.1.0
 */

#define APP_VERSION	"1.1.0"
#define APP_RELDATE	"December 1, 2003"
#define APP_NAME	"ifenslave"

static char *version =
APP_NAME ".c:v" APP_VERSION " (" APP_RELDATE ")\n"
"o Donald Becker (becker@cesdis.gsfc.nasa.gov).\n"
"o Detach support added on 2000/10/02 by Willy Tarreau (willy at meta-x.org).\n"
"o 2.4 kernel support added on 2001/02/16 by Chad N. Tindel\n"
"  (ctindel at ieee dot org).\n";

static const char *usage_msg =
"Usage: ifenslave [-f] <master-if> <slave-if> [<slave-if>...]\n"
"       ifenslave -d   <master-if> <slave-if> [<slave-if>...]\n"
"       ifenslave -c   <master-if> <slave-if>\n"
"       ifenslave --help\n";

static const char *help_msg =
"\n"
"       To create a bond device, simply follow these three steps :\n"
"       - ensure that the required drivers are properly loaded :\n"
"         # modprobe bonding ; modprobe <3c59x|eepro100|pcnet32|tulip|...>\n"
"       - assign an IP address to the bond device :\n"
"         # ifconfig bond0 <addr> netmask <mask> broadcast <bcast>\n"
"       - attach all the interfaces you need to the bond device :\n"
"         # ifenslave [{-f|--force}] bond0 eth0 [eth1 [eth2]...]\n"
"         If bond0 didn't have a MAC address, it will take eth0's. Then, all\n"
"         interfaces attached AFTER this assignment will get the same MAC addr.\n"
"         (except for ALB/TLB modes)\n"
"\n"
"       To set the bond device down and automatically release all the slaves :\n"
"         # ifconfig bond0 down\n"
"\n"
"       To detach a dead interface without setting the bond device down :\n"
"         # ifenslave {-d|--detach} bond0 eth0 [eth1 [eth2]...]\n"
"\n"
"       To change active slave :\n"
"         # ifenslave {-c|--change-active} bond0 eth0\n"
"\n"
"       To show master interface info\n"
"         # ifenslave bond0\n"
"\n"
"       To show all interfaces info\n"
"       # ifenslave {-a|--all-interfaces}\n"
"\n"
"       To be more verbose\n"
"       # ifenslave {-v|--verbose} ...\n"
"\n"
"       # ifenslave {-u|--usage}   Show usage\n"
"       # ifenslave {-V|--version} Show version\n"
"       # ifenslave {-h|--help}    This message\n"
"\n";

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/if.h>
#include <net/if_arp.h>
#include <linux/if_ether.h>
#include <linux/if_bonding.h>
#include <linux/sockios.h>

typedef unsigned long long u64;	/* hack, so we may include kernel's ethtool.h */
typedef __uint32_t u32;		/* ditto */
typedef __uint16_t u16;		/* ditto */
typedef __uint8_t u8;		/* ditto */
#include <linux/ethtool.h>

struct option longopts[] = {
	/* { name  has_arg  *flag  val } */
	{"all-interfaces",	0, 0, 'a'},	/* Show all interfaces. */
	{"change-active",	0, 0, 'c'},	/* Change the active slave.  */
	{"detach",		0, 0, 'd'},	/* Detach a slave interface. */
	{"force",		0, 0, 'f'},	/* Force the operation. */
	{"help",		0, 0, 'h'},	/* Give help */
	{"usage",		0, 0, 'u'},	/* Give usage */
	{"verbose",		0, 0, 'v'},	/* Report each action taken. */
	{"version",		0, 0, 'V'},	/* Emit version information. */
	{ 0, 0, 0, 0}
};

/* Command-line flags. */
unsigned int
opt_a = 0,	/* Show-all-interfaces flag. */
opt_c = 0,	/* Change-active-slave flag. */
opt_d = 0,	/* Detach a slave interface. */
opt_f = 0,	/* Force the operation. */
opt_h = 0,	/* Help */
opt_u = 0,	/* Usage */
opt_v = 0,	/* Verbose flag. */
opt_V = 0;	/* Version */

int skfd = -1;		/* AF_INET socket for ioctl() calls.*/
int abi_ver = 0;	/* userland - kernel ABI version */
int hwaddr_set = 0;	/* Master's hwaddr is set */
int saved_errno;

struct ifreq master_mtu, master_flags, master_hwaddr;
struct ifreq slave_mtu, slave_flags, slave_hwaddr;

struct dev_ifr {
	struct ifreq *req_ifr;
	char *req_name;
	int req_type;
};

struct dev_ifr master_ifra[] = {
	{&master_mtu,     "SIOCGIFMTU",     SIOCGIFMTU},
	{&master_flags,   "SIOCGIFFLAGS",   SIOCGIFFLAGS},
	{&master_hwaddr,  "SIOCGIFHWADDR",  SIOCGIFHWADDR},
	{NULL, "", 0}
};

struct dev_ifr slave_ifra[] = {
	{&slave_mtu,     "SIOCGIFMTU",     SIOCGIFMTU},
	{&slave_flags,   "SIOCGIFFLAGS",   SIOCGIFFLAGS},
	{&slave_hwaddr,  "SIOCGIFHWADDR",  SIOCGIFHWADDR},
	{NULL, "", 0}
};

static void if_print(char *ifname);
static int get_drv_info(char *master_ifname);
static int get_if_settings(char *ifname, struct dev_ifr ifra[]);
static int get_slave_flags(char *slave_ifname);
static int set_master_hwaddr(char *master_ifname, struct sockaddr *hwaddr);
static int set_slave_hwaddr(char *slave_ifname, struct sockaddr *hwaddr);
static int set_slave_mtu(char *slave_ifname, int mtu);
static int set_if_flags(char *ifname, short flags);
static int set_if_up(char *ifname, short flags);
static int set_if_down(char *ifname, short flags);
static int clear_if_addr(char *ifname);
static int set_if_addr(char *master_ifname, char *slave_ifname);
static int change_active(char *master_ifname, char *slave_ifname);
static int enslave(char *master_ifname, char *slave_ifname);
static int release(char *master_ifname, char *slave_ifname);
#define v_print(fmt, args...)	\
	if (opt_v)		\
		fprintf(stderr, fmt, ## args )

int main(int argc, char *argv[])
{
	char **spp, *master_ifname, *slave_ifname;
	int c, i, rv;
	int res = 0;
	int exclusive = 0;

	while ((c = getopt_long(argc, argv, "acdfhuvV", longopts, 0)) != EOF) {
		switch (c) {
		case 'a': opt_a++; exclusive++; break;
		case 'c': opt_c++; exclusive++; break;
		case 'd': opt_d++; exclusive++; break;
		case 'f': opt_f++; exclusive++; break;
		case 'h': opt_h++; exclusive++; break;
		case 'u': opt_u++; exclusive++; break;
		case 'v': opt_v++; break;
		case 'V': opt_V++; exclusive++; break;

		case '?':
			fprintf(stderr, usage_msg);
			res = 2;
			goto out;
		}
	}

	/* options check */
	if (exclusive > 1) {
		fprintf(stderr, usage_msg);
		res = 2;
		goto out;
	}

	if (opt_v || opt_V) {
		printf(version);
		if (opt_V) {
			res = 0;
			goto out;
		}
	}

	if (opt_u) {
		printf(usage_msg);
		res = 0;
		goto out;
	}

	if (opt_h) {
		printf(usage_msg);
		printf(help_msg);
		res = 0;
		goto out;
	}

	/* Open a basic socket */
	if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
		perror("socket");
		res = 1;
		goto out;
	}

	if (opt_a) {
		if (optind == argc) {
			/* No remaining args */
			/* show all interfaces */
			if_print((char *)NULL);
			goto out;
		} else {
			/* Just show usage */
			fprintf(stderr, usage_msg);
			res = 2;
			goto out;
		}
	}

	/* Copy the interface name */
	spp = argv + optind;
	master_ifname = *spp++;

	if (master_ifname == NULL) {
		fprintf(stderr, usage_msg);
		res = 2;
		goto out;
	}

	/* exchange abi version with bonding module */
	res = get_drv_info(master_ifname);
	if (res) {
		fprintf(stderr,
			"Master '%s': Error: handshake with driver failed. "
			"Aborting\n",
			master_ifname);
		goto out;
	}

	slave_ifname = *spp++;

	if (slave_ifname == NULL) {
		if (opt_d || opt_c) {
			fprintf(stderr, usage_msg);
			res = 2;
			goto out;
		}

		/* A single arg means show the
		 * configuration for this interface
		 */
		if_print(master_ifname);
		goto out;
	}

	res = get_if_settings(master_ifname, master_ifra);
	if (res) {
		/* Probably a good reason not to go on */
		fprintf(stderr,
			"Master '%s': Error: get settings failed: %s. "
			"Aborting\n",
			master_ifname, strerror(res));
		goto out;
	}

	/* check if master is indeed a master;
	 * if not then fail any operation
	 */
	if (!(master_flags.ifr_flags & IFF_MASTER)) {
		fprintf(stderr,
			"Illegal operation; the specified interface '%s' "
			"is not a master. Aborting\n",
			master_ifname);
		res = 1;
		goto out;
	}

	/* check if master is up; if not then fail any operation */
	if (!(master_flags.ifr_flags & IFF_UP)) {
		fprintf(stderr,
			"Illegal operation; the specified master interface "
			"'%s' is not up.\n",
			master_ifname);
		res = 1;
		goto out;
	}

	/* Only for enslaving */
	if (!opt_c && !opt_d) {
		sa_family_t master_family = master_hwaddr.ifr_hwaddr.sa_family;
		unsigned char *hwaddr =
			(unsigned char *)master_hwaddr.ifr_hwaddr.sa_data;

		/* The family '1' is ARPHRD_ETHER for ethernet. */
		if (master_family != 1 && !opt_f) {
			fprintf(stderr,
				"Illegal operation: The specified master "
				"interface '%s' is not ethernet-like.\n "
				"This program is designed to work with "
				"ethernet-like network interfaces.\n "
				"Use the '-f' option to force the "
				"operation.\n",
				master_ifname);
			res = 1;
			goto out;
		}

		/* Check master's hw addr */
		for (i = 0; i < 6; i++) {
			if (hwaddr[i] != 0) {
				hwaddr_set = 1;
				break;
			}
		}

		if (hwaddr_set) {
			v_print("current hardware address of master '%s' "
				"is %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
				"type %d\n",
				master_ifname,
				hwaddr[0], hwaddr[1],
				hwaddr[2], hwaddr[3],
				hwaddr[4], hwaddr[5],
				master_family);
		}
	}

	/* Accepts only one slave */
	if (opt_c) {
		/* change active slave */
		res = get_slave_flags(slave_ifname);
		if (res) {
			fprintf(stderr,
				"Slave '%s': Error: get flags failed. "
				"Aborting\n",
				slave_ifname);
			goto out;
		}
		res = change_active(master_ifname, slave_ifname);
		if (res) {
			fprintf(stderr,
				"Master '%s', Slave '%s': Error: "
				"Change active failed\n",
				master_ifname, slave_ifname);
		}
	} else {
		/* Accept multiple slaves */
		do {
			if (opt_d) {
				/* detach a slave interface from the master */
				rv = get_slave_flags(slave_ifname);
				if (rv) {
					/* Can't work with this slave. */
					/* remember the error and skip it*/
					fprintf(stderr,
						"Slave '%s': Error: get flags "
						"failed. Skipping\n",
						slave_ifname);
					res = rv;
					continue;
				}
				rv = release(master_ifname, slave_ifname);
				if (rv) {
					fprintf(stderr,
						"Master '%s', Slave '%s': Error: "
						"Release failed\n",
						master_ifname, slave_ifname);
					res = rv;
				}
			} else {
				/* attach a slave interface to the master */
				rv = get_if_settings(slave_ifname, slave_ifra);
				if (rv) {
					/* Can't work with this slave. */
					/* remember the error and skip it*/
					fprintf(stderr,
						"Slave '%s': Error: get "
						"settings failed: %s. "
						"Skipping\n",
						slave_ifname, strerror(rv));
					res = rv;
					continue;
				}
				rv = enslave(master_ifname, slave_ifname);
				if (rv) {
					fprintf(stderr,
						"Master '%s', Slave '%s': Error: "
						"Enslave failed\n",
						master_ifname, slave_ifname);
					res = rv;
				}
			}
		} while ((slave_ifname = *spp++) != NULL);
	}

out:
	if (skfd >= 0) {
		close(skfd);
	}

	return res;
}

static short mif_flags;

/* Get the inteface configuration from the kernel. */
static int if_getconfig(char *ifname)
{
	struct ifreq ifr;
	int metric, mtu;	/* Parameters of the master interface. */
	struct sockaddr dstaddr, broadaddr, netmask;
	unsigned char *hwaddr;

	strcpy(ifr.ifr_name, ifname);
	if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
		return -1;
	mif_flags = ifr.ifr_flags;
	printf("The result of SIOCGIFFLAGS on %s is %x.\n",
	       ifname, ifr.ifr_flags);

	strcpy(ifr.ifr_name, ifname);
	if (ioctl(skfd, SIOCGIFADDR, &ifr) < 0)
		return -1;
	printf("The result of SIOCGIFADDR is %2.2x.%2.2x.%2.2x.%2.2x.\n",
	       ifr.ifr_addr.sa_data[2], ifr.ifr_addr.sa_data[3],
	       ifr.ifr_addr.sa_data[4], ifr.ifr_addr.sa_data[5]);

	strcpy(ifr.ifr_name, ifname);
	if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
		return -1;

	/* Gotta convert from 'char' to unsigned for printf(). */
	hwaddr = (unsigned char *)ifr.ifr_hwaddr.sa_data;
	printf("The result of SIOCGIFHWADDR is type %d  "
	       "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n",
	       ifr.ifr_hwaddr.sa_family, hwaddr[0], hwaddr[1],
	       hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);

	strcpy(ifr.ifr_name, ifname);
	if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0) {
		metric = 0;
	} else
		metric = ifr.ifr_metric;

	strcpy(ifr.ifr_name, ifname);
	if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0)
		mtu = 0;
	else
		mtu = ifr.ifr_mtu;

	strcpy(ifr.ifr_name, ifname);
	if (ioctl(skfd, SIOCGIFDSTADDR, &ifr) < 0) {
		memset(&dstaddr, 0, sizeof(struct sockaddr));
	} else
		dstaddr = ifr.ifr_dstaddr;

	strcpy(ifr.ifr_name, ifname);
	if (ioctl(skfd, SIOCGIFBRDADDR, &ifr) < 0) {
		memset(&broadaddr, 0, sizeof(struct sockaddr));
	} else
		broadaddr = ifr.ifr_broadaddr;

	strcpy(ifr.ifr_name, ifname);
	if (ioctl(skfd, SIOCGIFNETMASK, &ifr) < 0) {
		memset(&netmask, 0, sizeof(struct sockaddr));
	} else
		netmask = ifr.ifr_netmask;

	return 0;
}

static void if_print(char *ifname)
{
	char buff[1024];
	struct ifconf ifc;
	struct ifreq *ifr;
	int i;

	if (ifname == (char *)NULL) {
		ifc.ifc_len = sizeof(buff);
		ifc.ifc_buf = buff;
		if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
			perror("SIOCGIFCONF failed");
			return;
		}

		ifr = ifc.ifc_req;
		for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++) {
			if (if_getconfig(ifr->ifr_name) < 0) {
				fprintf(stderr,
					"%s: unknown interface.\n",
					ifr->ifr_name);
				continue;
			}

			if (((mif_flags & IFF_UP) == 0) && !opt_a) continue;
			/*ife_print(&ife);*/
		}
	} else {
		if (if_getconfig(ifname) < 0) {
			fprintf(stderr,
				"%s: unknown interface.\n", ifname);
		}
	}
}

static int get_drv_info(char *master_ifname)
{
	struct ifreq ifr;
	struct ethtool_drvinfo info;
	char *endptr;

	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
	ifr.ifr_data = (caddr_t)&info;

	info.cmd = ETHTOOL_GDRVINFO;
	strncpy(info.driver, "ifenslave", 32);
	snprintf(info.fw_version, 32, "%d", BOND_ABI_VERSION);

	if (ioctl(skfd, SIOCETHTOOL, &ifr) < 0) {
		if (errno == EOPNOTSUPP) {
			goto out;
		}

		saved_errno = errno;
		v_print("Master '%s': Error: get bonding info failed %s\n",
			master_ifname, strerror(saved_errno));
		return 1;
	}

	abi_ver = strtoul(info.fw_version, &endptr, 0);
	if (*endptr) {
                v_print("Master '%s': Error: got invalid string as an ABI "
			"version from the bonding module\n",
			master_ifname);
		return 1;
	}

out:
	v_print("ABI ver is %d\n", abi_ver);

	return 0;
}

static int change_active(char *master_ifname, char *slave_ifname)
{
	struct ifreq ifr;
	int res = 0;

	if (!(slave_flags.ifr_flags & IFF_SLAVE)) {
		fprintf(stderr,
			"Illegal operation: The specified slave interface "
			"'%s' is not a slave\n",
			slave_ifname);
		return 1;
	}

	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
	strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
	if ((ioctl(skfd, SIOCBONDCHANGEACTIVE, &ifr) < 0) &&
	    (ioctl(skfd, BOND_CHANGE_ACTIVE_OLD, &ifr) < 0)) {
		saved_errno = errno;
		v_print("Master '%s': Error: SIOCBONDCHANGEACTIVE failed: "
			"%s\n",
			master_ifname, strerror(saved_errno));
		res = 1;
	}

	return res;
}

static int enslave(char *master_ifname, char *slave_ifname)
{
	struct ifreq ifr;
	int res = 0;

	if (slave_flags.ifr_flags & IFF_SLAVE) {
		fprintf(stderr,
			"Illegal operation: The specified slave interface "
			"'%s' is already a slave\n",
			slave_ifname);
		return 1;
	}

	res = set_if_down(slave_ifname, slave_flags.ifr_flags);
	if (res) {
		fprintf(stderr,
			"Slave '%s': Error: bring interface down failed\n",
			slave_ifname);
		return res;
	}

	if (abi_ver < 2) {
		/* Older bonding versions would panic if the slave has no IP
		 * address, so get the IP setting from the master.
		 */
		set_if_addr(master_ifname, slave_ifname);
	} else {
		res = clear_if_addr(slave_ifname);
		if (res) {
			fprintf(stderr,
				"Slave '%s': Error: clear address failed\n",
				slave_ifname);
			return res;
		}
	}

	if (master_mtu.ifr_mtu != slave_mtu.ifr_mtu) {
		res = set_slave_mtu(slave_ifname, master_mtu.ifr_mtu);
		if (res) {
			fprintf(stderr,
				"Slave '%s': Error: set MTU failed\n",
				slave_ifname);
			return res;
		}
	}

	if (hwaddr_set) {
		/* Master already has an hwaddr
		 * so set it's hwaddr to the slave
		 */
		if (abi_ver < 1) {
			/* The driver is using an old ABI, so
			 * the application sets the slave's
			 * hwaddr
			 */
			res = set_slave_hwaddr(slave_ifname,
					       &(master_hwaddr.ifr_hwaddr));
			if (res) {
				fprintf(stderr,
					"Slave '%s': Error: set hw address "
					"failed\n",
					slave_ifname);
				goto undo_mtu;
			}

			/* For old ABI the application needs to bring the
			 * slave back up
			 */
			res = set_if_up(slave_ifname, slave_flags.ifr_flags);
			if (res) {
				fprintf(stderr,
					"Slave '%s': Error: bring interface "
					"down failed\n",
					slave_ifname);
				goto undo_slave_mac;
			}
		}
		/* The driver is using a new ABI,
		 * so the driver takes care of setting
		 * the slave's hwaddr and bringing
		 * it up again
		 */
	} else {
		/* No hwaddr for master yet, so
		 * set the slave's hwaddr to it
		 */
		if (abi_ver < 1) {
			/* For old ABI, the master needs to be
			 * down before setting it's hwaddr
			 */
			res = set_if_down(master_ifname, master_flags.ifr_flags);
			if (res) {
				fprintf(stderr,
					"Master '%s': Error: bring interface "
					"down failed\n",
					master_ifname);
				goto undo_mtu;
			}
		}

		res = set_master_hwaddr(master_ifname,
					&(slave_hwaddr.ifr_hwaddr));
		if (res) {
			fprintf(stderr,
				"Master '%s': Error: set hw address "
				"failed\n",
				master_ifname);
			goto undo_mtu;
		}

		if (abi_ver < 1) {
			/* For old ABI, bring the master
			 * back up
			 */
			res = set_if_up(master_ifname, master_flags.ifr_flags);
			if (res) {
				fprintf(stderr,
					"Master '%s': Error: bring interface "
					"up failed\n",
					master_ifname);
				goto undo_master_mac;
			}
		}

		hwaddr_set = 1;
	}

	/* Do the real thing */
	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
	strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
	if ((ioctl(skfd, SIOCBONDENSLAVE, &ifr) < 0) &&
	    (ioctl(skfd, BOND_ENSLAVE_OLD, &ifr) < 0)) {
		saved_errno = errno;
		v_print("Master '%s': Error: SIOCBONDENSLAVE failed: %s\n",
			master_ifname, strerror(saved_errno));
		res = 1;
	}

	if (res) {
		goto undo_master_mac;
	}

	return 0;

/* rollback (best effort) */
undo_master_mac:
	set_master_hwaddr(master_ifname, &(master_hwaddr.ifr_hwaddr));
	hwaddr_set = 0;
	goto undo_mtu;
undo_slave_mac:
	set_slave_hwaddr(slave_ifname, &(slave_hwaddr.ifr_hwaddr));
undo_mtu:
	set_slave_mtu(slave_ifname, slave_mtu.ifr_mtu);
	return res;
}

static int release(char *master_ifname, char *slave_ifname)
{
	struct ifreq ifr;
	int res = 0;

	if (!(slave_flags.ifr_flags & IFF_SLAVE)) {
		fprintf(stderr,
			"Illegal operation: The specified slave interface "
			"'%s' is not a slave\n",
			slave_ifname);
		return 1;
	}

	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
	strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
	if ((ioctl(skfd, SIOCBONDRELEASE, &ifr) < 0) &&
	    (ioctl(skfd, BOND_RELEASE_OLD, &ifr) < 0)) {
		saved_errno = errno;
		v_print("Master '%s': Error: SIOCBONDRELEASE failed: %s\n",
			master_ifname, strerror(saved_errno));
		return 1;
	} else if (abi_ver < 1) {
		/* The driver is using an old ABI, so we'll set the interface
		 * down to avoid any conflicts due to same MAC/IP
		 */
		res = set_if_down(slave_ifname, slave_flags.ifr_flags);
		if (res) {
			fprintf(stderr,
				"Slave '%s': Error: bring interface "
				"down failed\n",
				slave_ifname);
		}
	}

	/* set to default mtu */
	set_slave_mtu(slave_ifname, 1500);

	return res;
}

static int get_if_settings(char *ifname, struct dev_ifr ifra[])
{
	int i;
	int res = 0;

	for (i = 0; ifra[i].req_ifr; i++) {
		strncpy(ifra[i].req_ifr->ifr_name, ifname, IFNAMSIZ);
		res = ioctl(skfd, ifra[i].req_type, ifra[i].req_ifr);
		if (res < 0) {
			saved_errno = errno;
			v_print("Interface '%s': Error: %s failed: %s\n",
				ifname, ifra[i].req_name,
				strerror(saved_errno));

			return saved_errno;
		}
	}

	return 0;
}

static int get_slave_flags(char *slave_ifname)
{
	int res = 0;

	strncpy(slave_flags.ifr_name, slave_ifname, IFNAMSIZ);
	res = ioctl(skfd, SIOCGIFFLAGS, &slave_flags);
	if (res < 0) {
		saved_errno = errno;
		v_print("Slave '%s': Error: SIOCGIFFLAGS failed: %s\n",
			slave_ifname, strerror(saved_errno));
	} else {
		v_print("Slave %s: flags %04X.\n",
			slave_ifname, slave_flags.ifr_flags);
	}

	return res;
}

static int set_master_hwaddr(char *master_ifname, struct sockaddr *hwaddr)
{
	unsigned char *addr = (unsigned char *)hwaddr->sa_data;
	struct ifreq ifr;
	int res = 0;

	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
	memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
	res = ioctl(skfd, SIOCSIFHWADDR, &ifr);
	if (res < 0) {
		saved_errno = errno;
		v_print("Master '%s': Error: SIOCSIFHWADDR failed: %s\n",
			master_ifname, strerror(saved_errno));
		return res;
	} else {
		v_print("Master '%s': hardware address set to "
			"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n",
			master_ifname, addr[0], addr[1], addr[2],
			addr[3], addr[4], addr[5]);
	}

	return res;
}

static int set_slave_hwaddr(char *slave_ifname, struct sockaddr *hwaddr)
{
	unsigned char *addr = (unsigned char *)hwaddr->sa_data;
	struct ifreq ifr;
	int res = 0;

	strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
	memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
	res = ioctl(skfd, SIOCSIFHWADDR, &ifr);
	if (res < 0) {
		saved_errno = errno;

		v_print("Slave '%s': Error: SIOCSIFHWADDR failed: %s\n",
			slave_ifname, strerror(saved_errno));

		if (saved_errno == EBUSY) {
			v_print("  The device is busy: it must be idle "
				"before running this command.\n");
		} else if (saved_errno == EOPNOTSUPP) {
			v_print("  The device does not support setting "
				"the MAC address.\n"
				"  Your kernel likely does not support slave "
				"devices.\n");
		} else if (saved_errno == EINVAL) {
			v_print("  The device's address type does not match "
				"the master's address type.\n");
		}
		return res;
	} else {
		v_print("Slave '%s': hardware address set to "
			"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n",
			slave_ifname, addr[0], addr[1], addr[2],
			addr[3], addr[4], addr[5]);
	}

	return res;
}

static int set_slave_mtu(char *slave_ifname, int mtu)
{
	struct ifreq ifr;
	int res = 0;

	ifr.ifr_mtu = mtu;
	strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);

	res = ioctl(skfd, SIOCSIFMTU, &ifr);
	if (res < 0) {
		saved_errno = errno;
		v_print("Slave '%s': Error: SIOCSIFMTU failed: %s\n",
			slave_ifname, strerror(saved_errno));
	} else {
		v_print("Slave '%s': MTU set to %d.\n", slave_ifname, mtu);
	}

	return res;
}

static int set_if_flags(char *ifname, short flags)
{
	struct ifreq ifr;
	int res = 0;

	ifr.ifr_flags = flags;
	strncpy(ifr.ifr_name, ifname, IFNAMSIZ);

	res = ioctl(skfd, SIOCSIFFLAGS, &ifr);
	if (res < 0) {
		saved_errno = errno;
		v_print("Interface '%s': Error: SIOCSIFFLAGS failed: %s\n",
			ifname, strerror(saved_errno));
	} else {
		v_print("Interface '%s': flags set to %04X.\n", ifname, flags);
	}

	return res;
}

static int set_if_up(char *ifname, short flags)
{
	return set_if_flags(ifname, flags | IFF_UP);
}

static int set_if_down(char *ifname, short flags)
{
	return set_if_flags(ifname, flags & ~IFF_UP);
}

static int clear_if_addr(char *ifname)
{
	struct ifreq ifr;
	int res = 0;

	strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
	ifr.ifr_addr.sa_family = AF_INET;
	memset(ifr.ifr_addr.sa_data, 0, sizeof(ifr.ifr_addr.sa_data));

	res = ioctl(skfd, SIOCSIFADDR, &ifr);
	if (res < 0) {
		saved_errno = errno;
		v_print("Interface '%s': Error: SIOCSIFADDR failed: %s\n",
			ifname, strerror(saved_errno));
	} else {
		v_print("Interface '%s': address cleared\n", ifname);
	}

	return res;
}

static int set_if_addr(char *master_ifname, char *slave_ifname)
{
	struct ifreq ifr;
	int res;
	unsigned char *ipaddr;
	int i;
	struct {
		char *req_name;
		char *desc;
		int g_ioctl;
		int s_ioctl;
	} ifra[] = {
		{"IFADDR", "addr", SIOCGIFADDR, SIOCSIFADDR},
		{"DSTADDR", "destination addr", SIOCGIFDSTADDR, SIOCSIFDSTADDR},
		{"BRDADDR", "broadcast addr", SIOCGIFBRDADDR, SIOCSIFBRDADDR},
		{"NETMASK", "netmask", SIOCGIFNETMASK, SIOCSIFNETMASK},
		{NULL, NULL, 0, 0},
	};

	for (i = 0; ifra[i].req_name; i++) {
		strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
		res = ioctl(skfd, ifra[i].g_ioctl, &ifr);
		if (res < 0) {
			int saved_errno = errno;

			v_print("Interface '%s': Error: SIOCG%s failed: %s\n",
				master_ifname, ifra[i].req_name,
				strerror(saved_errno));

			ifr.ifr_addr.sa_family = AF_INET;
			memset(ifr.ifr_addr.sa_data, 0,
			       sizeof(ifr.ifr_addr.sa_data));
		}

		strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
		res = ioctl(skfd, ifra[i].s_ioctl, &ifr);
		if (res < 0) {
			int saved_errno = errno;

			v_print("Interface '%s': Error: SIOCS%s failed: %s\n",
				slave_ifname, ifra[i].req_name,
				strerror(saved_errno));

		}

		ipaddr = (unsigned char *)ifr.ifr_addr.sa_data;
		v_print("Interface '%s': set IP %s to %d.%d.%d.%d\n",
			slave_ifname, ifra[i].desc,
			ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
	}

	return 0;
}

/*
 * Local variables:
 *  version-control: t
 *  kept-new-versions: 5
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 4
 *  compile-command: "gcc -Wall -Wstrict-prototypes -O -I/usr/src/linux/include ifenslave.c -o ifenslave"
 * End:
 */


code:
--- a/rarpd.c
+++ b/rarpd.c
@@ -55,10 +55,10 @@ struct iflink
 	unsigned char	lladdr[16];
 	char		name[IFNAMSIZ];
-	struct ifaddr 	*ifa_list;
+	struct kern_ifaddr 	*ifa_list;
 } *ifl_list;

-struct ifaddr
+struct kern_ifaddr
 {
-	struct ifaddr 	*next;
+	struct kern_ifaddr 	*next;
 	__u32		prefix;
 	__u32		mask;
@@ -92,5 +92,5 @@ void load_if(void)
 	struct ifreq *ifrp, *ifend;
 	struct iflink *ifl;
-	struct ifaddr *ifa;
+	struct kern_ifaddr *ifa;
 	struct ifconf ifc;
 	struct ifreq ibuf[256];
@@ -183,5 +183,5 @@ void load_if(void)
 			if (mask == 0 || prefix == 0)
 				continue;
-			ifa = (struct ifaddr*)malloc(sizeof(*ifa));
+			ifa = (struct kern_ifaddr*)malloc(sizeof(*ifa));
 			memset(ifa, 0, sizeof(*ifa));
 			ifa->local = addr;
@@ -239,8 +239,8 @@ int bootable(__u32 addr)
 }

-struct ifaddr *select_ipaddr(int ifindex, __u32 *sel_addr, __u32 **alist)
+struct kern_ifaddr *select_ipaddr(int ifindex, __u32 *sel_addr, __u32 **alist)
 {
 	struct iflink *ifl;
-	struct ifaddr *ifa;
+	struct kern_ifaddr *ifa;
 	int retry = 0;
 	int i;
@@ -298,5 +298,5 @@ struct rarp_map *rarp_lookup(int ifindex
 	if (r == NULL) {
 		if (hatype == ARPHRD_ETHER && halen == 6) {
-			struct ifaddr *ifa;
+			struct kern_ifaddr *ifa;
 			struct hostent *hp;
 			char ename[256];
@@ -371,5 +371,5 @@ int put_myipaddr(unsigned char **ptr_p,
 	__u32 laddr = 0;
 	struct iflink *ifl;
-	struct ifaddr *ifa;
+	struct kern_ifaddr *ifa;

 	for (ifl=ifl_list; ifl; ifl = ifl->next)


code:
--- iputils-s20071127/ping_common.h.orig	2008-06-10 11:16:06.000000000 +0100
+++ iputils-s20071127/ping_common.h	2008-06-10 11:16:18.000000000 +0100
@@ -28,7 +28,7 @@

 #define	MAXWAIT		10		/* max seconds to wait for response */
 #define MININTERVAL	10		/* Minimal interpacket gap */
-#define MINUSERINTERVAL	200		/* Minimal allowed interval for non-root */
+#define MINUSERINTERVAL	0		/* Minimal allowed interval for non-root */

 #define SCHINT(a)	(((a) <= MININTERVAL) ? MININTERVAL : (a))


code:
https://bugs.gentoo.org/335347

fix building with older linux headers that don't define SO_MARK

--- ping_common.c.org
+++ ping_common.c
@@ -485,6 +485,7 @@
 			fprintf(stderr, "Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP\n");
 	}
 #endif
+#ifdef SO_MARK
 	if (options & F_MARK) {
 		if (setsockopt(icmp_sock, SOL_SOCKET, SO_MARK,
 				&mark, sizeof(mark)) == -1) {
@@ -494,6 +495,7 @@
 			fprintf(stderr, "Warning: Failed to set mark %d\n", mark);
 		}
 	}
+#endif

 	/* Set some SNDTIMEO to prevent blocking forever
 	 * on sends, when device is too slow or stalls. Just put limit


code:
From 568e990d30fc7e9416e0a6f8c74ea5013921eaec Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <arjanvandeven@gmail.com>
Date: Wed, 16 Jan 2013 03:12:15 +0900
Subject: [PATCH [iputils]] ping6: Fix build command line argument with gnutls.

The ping6 command can use either openssl or gnutls...
and the Makefile has a bunch of setup for defining which of the two to use.

Unfortunately, the final -D define on the commandline to enable gnutls
inside the ping6.c file didn't actually make it onto the gcc
commandline.
This patch adds the $(DEF_CRYPTO) Makefile variable to fix this gap.

Signed-off-by: Arjan van de Ven <arjanvandeven@gmail.com>
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index c62d9df..89249f5 100644
--- a/Makefile
+++ b/Makefile
@@ -149,7 +149,7 @@ LIB_clockdiff = $(LIB_CAP)
 DEF_ping_common = $(DEF_CAP) $(DEF_IDN)
 DEF_ping  = $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS)
 LIB_ping  = $(LIB_CAP) $(LIB_IDN)
-DEF_ping6 = $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS) $(DEF_ENABLE_PING6_RTHDR)
+DEF_ping6 = $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS) $(DEF_ENABLE_PING6_RTHDR) $(DEF_CRYPTO)
 LIB_ping6 = $(LIB_CAP) $(LIB_IDN) $(LIB_RESOLV) $(LIB_CRYPTO)

 ping: ping_common.o
--
1.8.0.2


code:
From c66609d2c830d6fe06f48f5d38c54eb5cc6f2975 Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Thu, 24 Jan 2013 23:36:16 -0500
Subject: [PATCH [iputils]] fix handling of CFLAGS

This defaults CFLAGS to -O3 without clobbering settings people have set
up in the environment already.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 Makefile | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 2c49940..ecabac3 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,6 @@
 # Configuration
 #

-# CC
-CC=gcc
 # Path to parent kernel include files directory
 LIBC_INCLUDE=/usr/include
 # Libraries
@@ -48,11 +46,10 @@ ENABLE_RDISC_SERVER=no

 # -------------------------------------
 # What a pity, all new gccs are buggy and -Werror does not work. Sigh.
-# CCOPT=-fno-strict-aliasing -Wstrict-prototypes -Wall -Werror -g
-CCOPT=-fno-strict-aliasing -Wstrict-prototypes -Wall -g
-CCOPTOPT=-O3
-GLIBCFIX=-D_GNU_SOURCE
-DEFINES=
+# CFLAGS+=-fno-strict-aliasing -Wstrict-prototypes -Wall -Werror -g
+CFLAGS?=-O3 -g
+CFLAGS+=-fno-strict-aliasing -Wstrict-prototypes -Wall
+CPPFLAGS+=-D_GNU_SOURCE
 LDLIB=

 FUNC_LIB = $(if $(filter static,$(1)),$(LDFLAG_STATIC) $(2) $(LDFLAG_DYNAMIC),$(2))
@@ -113,7 +110,6 @@ IPV4_TARGETS=tracepath ping clockdiff rdisc arping tftpd rarpd
 IPV6_TARGETS=tracepath6 traceroute6 ping6
 TARGETS=$(IPV4_TARGETS) $(IPV6_TARGETS)

-CFLAGS=$(CCOPTOPT) $(CCOPT) $(GLIBCFIX) $(DEFINES)
 LDLIBS=$(LDLIB) $(ADDLIB)

 UNAME_N:=$(shell uname -n)
@@ -132,6 +128,7 @@ all: $(TARGETS)
 	$(COMPILE.c) $< $(DEF_$(patsubst %.o,%,$@)) -S -o $@
 %.o: %.c
 	$(COMPILE.c) $< $(DEF_$(patsubst %.o,%,$@)) -o $@
+LINK.o += $(CFLAGS)
 $(TARGETS): %: %.o
 	$(LINK.o) $^ $(LIB_$@) $(LDLIBS) -o $@

--
1.8.0.2


code:
From b57d77dcfa5cb363b7eba5b331324669a8505ac4 Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Thu, 24 Jan 2013 23:32:39 -0500
Subject: [PATCH [iputils]] ping6: allow disabling of openssl support

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 Makefile |  5 ++++-
 ping6.c  | 14 +++++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 89249f5..2c49940 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ ARPING_DEFAULT_DEVICE=

 # GNU TLS library for ping6 [yes|no|static]
 USE_GNUTLS=yes
-# Crypto library for ping6 [shared|static]
+# Crypto library for ping6 [shared|static|no]
 USE_CRYPTO=shared
 # Resolv library for ping6 [yes|static]
 USE_RESOLV=yes
@@ -63,7 +63,10 @@ ifneq ($(USE_GNUTLS),no)
 	LIB_CRYPTO = $(call FUNC_LIB,$(USE_GNUTLS),$(LDFLAG_GNUTLS))
 	DEF_CRYPTO = -DUSE_GNUTLS
 else
+ifneq ($(USE_CRYPTO),no)
 	LIB_CRYPTO = $(call FUNC_LIB,$(USE_CRYPTO),$(LDFLAG_CRYPTO))
+	DEF_CRYPTO = -DUSE_OPENSSL
+endif
 endif

 # USE_RESOLV: LIB_RESOLV
diff --git a/ping6.c b/ping6.c
index c39864d..f2f90af 100644
--- a/ping6.c
+++ b/ping6.c
@@ -168,8 +168,10 @@ static int icmp_sock;

 #ifdef USE_GNUTLS
 # include <gnutls/openssl.h>
-#else
+# define USE_CRYPTO
+#elif defined USE_OPENSSL
 # include <openssl/md5.h>
+# define USE_CRYPTO
 #endif

 /* Node Information query */
@@ -326,6 +328,7 @@ static void niquery_init_nonce(void)
 #if !PING6_NONCE_MEMORY
 static int niquery_nonce(__u8 *nonce, int fill)
 {
+# ifdef USE_CRYPTO
 	static __u8 digest[MD5_DIGEST_LENGTH];
 	static int seq = -1;

@@ -348,6 +351,10 @@ static int niquery_nonce(__u8 *nonce, int fill)
 			return -1;
 		return ntohsp((__u16 *)nonce);
 	}
+# else
+	fprintf(stderr, "ping6: function not available; crypto disabled\n");
+	exit(3);
+# endif
 }
 #endif

@@ -502,6 +509,7 @@ static int niquery_option_subject_addr_handler(int index, const char *arg)

 static int niquery_option_subject_name_handler(int index, const char *arg)
 {
+#ifdef USE_CRYPTO
 	static char nigroup_buf[INET6_ADDRSTRLEN + 1 + IFNAMSIZ];
 	unsigned char *dnptrs[2], **dpp, **lastdnptr;
 	int n;
@@ -627,6 +635,10 @@ errexit:
 	free(idn);
 	free(name);
 	exit(1);
+#else
+	fprintf(stderr, "ping6: function not available; crypto disabled\n");
+	exit(3);
+#endif
 }

 int niquery_option_help_handler(int index, const char *arg)
--
1.8.0.2


code:
http://openwall.info/wiki/people/segoon/ping

--- iputils-s20101006/ping.c
+++ iputils-s20101006/ping.c
@@ -88,6 +88,7 @@ struct sockaddr_in whereto;	/* who to pi
 int optlen = 0;
 int settos = 0;			/* Set TOS, Precendence or other QOS options */
 int icmp_sock;			/* socket file descriptor */
+int using_ping_socket = 0;
 u_char outpack[0x10000];
 int maxpacket = sizeof(outpack);

@@ -123,7 +124,11 @@ main(int argc, char **argv)
 	char *target, hnamebuf[MAX_HOSTNAMELEN];
 	char rspace[3 + 4 * NROUTES + 1];	/* record route space */

-	icmp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
+	icmp_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
+	if (icmp_sock != -1)
+		using_ping_socket = 1;
+	else
+		icmp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
 	socket_errno = errno;

 	uid = getuid();
@@ -377,13 +382,35 @@ main(int argc, char **argv)
 		}
 	}

-	if ((options&F_STRICTSOURCE) &&
-	    bind(icmp_sock, (struct sockaddr*)&source, sizeof(source)) == -1) {
-		perror("bind");
-		exit(2);
+	if (!using_ping_socket) {
+		if ((options&F_STRICTSOURCE) &&
+		    bind(icmp_sock, (struct sockaddr*)&source, sizeof(source)) == -1) {
+			perror("bind");
+			exit(2);
+		}
+	} else {
+		struct sockaddr_in sa;
+		socklen_t sl;
+
+		sa.sin_family = AF_INET;
+		sa.sin_port = 0;
+		sa.sin_addr.s_addr = (options&F_STRICTSOURCE) ?
+			source.sin_addr.s_addr : 0;
+		sl = sizeof(sa);
+
+		if (bind(icmp_sock, (struct sockaddr *) &sa, sl) == -1) {
+			perror("bind");
+			exit(2);
+		}
+
+		if (getsockname(icmp_sock, (struct sockaddr *) &sa, &sl) == -1) {
+			perror("getsockname");
+			exit(2);
+		}
+		ident = sa.sin_port;
 	}

-	if (1) {
+	if (!using_ping_socket) {
 		struct icmp_filter filt;
 		filt.data = ~((1<<ICMP_SOURCE_QUENCH)|
 			      (1<<ICMP_DEST_UNREACH)|
@@ -398,6 +425,12 @@ main(int argc, char **argv)
 	hold = 1;
 	if (setsockopt(icmp_sock, SOL_IP, IP_RECVERR, (char *)&hold, sizeof(hold)))
 		fprintf(stderr, "WARNING: your kernel is veeery old. No problems.\n");
+	if (using_ping_socket) {
+		if (setsockopt(icmp_sock, SOL_IP, IP_RECVTTL, (char *)&hold, sizeof(hold)))
+			perror("WARNING: setsockopt(IP_RECVTTL)");
+		if (setsockopt(icmp_sock, SOL_IP, IP_RETOPTS, (char *)&hold, sizeof(hold)))
+			perror("WARNING: setsockopt(IP_RETOPTS)");
+	}

 	/* record route option */
 	if (options & F_RROUTE) {
@@ -566,6 +599,7 @@ int receive_error_msg()
 		nerrors++;
 	} else if (e->ee_origin == SO_EE_ORIGIN_ICMP) {
 		struct sockaddr_in *sin = (struct sockaddr_in*)(e+1);
+		int error_pkt;

 		if (res < sizeof(icmph) ||
 		    target.sin_addr.s_addr != whereto.sin_addr.s_addr ||
@@ -576,9 +610,18 @@ int receive_error_msg()
 			goto out;
 		}

-		acknowledge(ntohs(icmph.un.echo.sequence));
+		error_pkt = (e->ee_type != ICMP_REDIRECT &&
+			     e->ee_type != ICMP_SOURCE_QUENCH);
+		if (error_pkt) {
+			acknowledge(ntohs(icmph.un.echo.sequence));
+			net_errors++;
+			nerrors++;
+		}
+		else {
+			saved_errno = 0;
+		}

-		if (!working_recverr) {
+		if (!using_ping_socket && !working_recverr) {
 			struct icmp_filter filt;
 			working_recverr = 1;
 			/* OK, it works. Add stronger filter. */
@@ -589,15 +632,14 @@ int receive_error_msg()
 				perror("\rWARNING: setsockopt(ICMP_FILTER)");
 		}

-		net_errors++;
-		nerrors++;
 		if (options & F_QUIET)
 			goto out;
 		if (options & F_FLOOD) {
-			write_stdout("\bE", 2);
+			if (error_pkt)
+				write_stdout("\bE", 2);
 		} else {
 			print_timestamp();
-			printf("From %s icmp_seq=%u ", pr_addr(sin->sin_addr.s_addr), ntohs(icmph.un.echo.sequence));
+			printf("From %s: icmp_seq=%u ", pr_addr(sin->sin_addr.s_addr), ntohs(icmph.un.echo.sequence));
 			pr_icmph(e->ee_type, e->ee_code, e->ee_info, NULL);
 			fflush(stdout);
 		}
@@ -695,15 +737,41 @@ parse_reply(struct msghdr *msg, int cc,
 	struct iphdr *ip;
 	int hlen;
 	int csfailed;
+	struct cmsghdr *cmsg;
+	int ttl;
+	__u8 *opts;
+	int optlen;

 	/* Check the IP header */
 	ip = (struct iphdr *)buf;
-	hlen = ip->ihl*4;
-	if (cc < hlen + 8 || ip->ihl < 5) {
-		if (options & F_VERBOSE)
-			fprintf(stderr, "ping: packet too short (%d bytes) from %s\n", cc,
-				pr_addr(from->sin_addr.s_addr));
-		return 1;
+	if (!using_ping_socket) {
+		hlen = ip->ihl*4;
+		if (cc < hlen + 8 || ip->ihl < 5) {
+			if (options & F_VERBOSE)
+				fprintf(stderr, "ping: packet too short (%d bytes) from %s\n", cc,
+					pr_addr(from->sin_addr.s_addr));
+			return 1;
+		}
+		ttl = ip->ttl;
+		opts = buf + sizeof(struct iphdr);
+		optlen = hlen - sizeof(struct iphdr);
+	} else {
+		hlen = 0;
+		ttl = 0;
+		opts = buf;
+		optlen = 0;
+		for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
+			if (cmsg->cmsg_level != SOL_IP)
+				continue;
+			if (cmsg->cmsg_type == IP_TTL) {
+				if (cmsg->cmsg_len < sizeof(int))
+					continue;
+				ttl = *(int *) CMSG_DATA(cmsg);
+			} else if (cmsg->cmsg_type == IP_RETOPTS) {
+				opts = (__u8 *) CMSG_DATA(cmsg);
+				optlen = cmsg->cmsg_len;
+			}
+		}
 	}

 	/* Now the ICMP part */
@@ -716,7 +784,7 @@ parse_reply(struct msghdr *msg, int cc,
 			return 1;			/* 'Twas not our ECHO */
 		if (gather_statistics((__u8*)icp, sizeof(*icp), cc,
 				      ntohs(icp->un.echo.sequence),
-				      ip->ttl, 0, tv, pr_addr(from->sin_addr.s_addr),
+				      ttl, 0, tv, pr_addr(from->sin_addr.s_addr),
 				      pr_echo_reply))
 			return 0;
 	} else {
@@ -807,7 +875,7 @@ parse_reply(struct msghdr *msg, int cc,
 	}

 	if (!(options & F_FLOOD)) {
-		pr_options(buf + sizeof(struct iphdr), hlen);
+		pr_options(opts, optlen + sizeof(struct iphdr));

 		if (options & F_AUDIBLE)
 			putchar('\a');
@@ -916,8 +984,7 @@ void pr_icmph(__u8 type, __u8 code, __u3
 			printf("Redirect, Bad Code: %d", code);
 			break;
 		}
-		if (icp)
-			printf("(New nexthop: %s)\n", pr_addr(icp->un.gateway));
+		printf("(New nexthop: %s)\n", pr_addr(icp ? icp->un.gateway : info));
 		if (icp && (options & F_VERBOSE))
 			pr_iph((struct iphdr*)(icp + 1));
 		break;
@@ -1217,7 +1284,7 @@ void install_filter(void)
 		insns
 	};

-	if (once)
+	if (once || using_ping_socket)
 		return;
 	once = 1;

--- iputils-s20101006/ping_common.c
+++ iputils-s20101006/ping_common.c
@@ -515,7 +515,8 @@ void setup(int icmp_sock)
 			*p++ = i;
 	}

-	ident = htons(getpid() & 0xFFFF);
+	if (!ident)
+		ident = htons(getpid() & 0xFFFF);

 	set_signal(SIGINT, sigexit);
 	set_signal(SIGALRM, sigexit);


code:
From 23fcb10ae15a96aa9e5a823cfe0b612d9522691c Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Sat, 14 Aug 2010 01:16:42 -0400
Subject: [PATCH [iputils]] tracepath: re-use printf return in print_host

Since the printf funcs already return the length of chars displayed,
use that value instead of re-calculating the length with strlen.

This also fixes the handling of the strlen return -- it's a size_t,
not an int.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 tracepath.c  | 11 ++++-------
 tracepath6.c | 11 ++++-------
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/tracepath.c b/tracepath.c
index 8a08f1d..f155816 100644
--- a/tracepath.c
+++ b/tracepath.c
@@ -73,13 +73,10 @@ void data_wait(int fd)

 void print_host(const char *a, const char *b, int both)
 {
-	int plen = 0;
-	printf("%s", a);
-	plen = strlen(a);
-	if (both) {
-		printf(" (%s)", b);
-		plen += strlen(b) + 3;
-	}
+	int plen;
+	plen = printf("%s", a);
+	if (both)
+		plen += printf(" (%s)", b);
 	if (plen >= HOST_COLUMN_SIZE)
 		plen = HOST_COLUMN_SIZE - 1;
 	printf("%*s", HOST_COLUMN_SIZE - plen, "");
diff --git a/tracepath6.c b/tracepath6.c
index 126fadf..bee95c3 100644
--- a/tracepath6.c
+++ b/tracepath6.c
@@ -86,13 +86,10 @@ void data_wait(int fd)

 void print_host(const char *a, const char *b, int both)
 {
-	int plen = 0;
-	printf("%s", a);
-	plen = strlen(a);
-	if (both) {
-		printf(" (%s)", b);
-		plen += strlen(b) + 3;
-	}
+	int plen;
+	plen = printf("%s", a);
+	if (both)
+		plen += printf(" (%s)", b);
 	if (plen >= HOST_COLUMN_SIZE)
 		plen = HOST_COLUMN_SIZE - 1;
 	printf("%*s", HOST_COLUMN_SIZE - plen, "");
--
1.8.0.2


code:
.\" This manpage has been automatically generated by docbook2man
.\" from a DocBook document.  This tool can be found at:
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.TH "ARPING" "8" "24 Mayıs 2011" "iputils-101006" "System Manager's Manual: iputils"
.SH NAME
arping \- send ARP REQUEST to a neighbour host
.SH SYNOPSIS

\fBarping\fR [ \fB-AbDfhqUV\fR]  [ \fB-c \fIcount\fB\fR]  [ \fB-w \fIdeadline\fB\fR]  [ \fB-s \fIsource\fB\fR]  \fB-I \fIinterface\fB\fR \fB\fIdestination\fB\fR

.SH "DESCRIPTION"
.PP
Ping \fIdestination\fR on device \fIinterface\fR by ARP packets,
using source address \fIsource\fR.
.SH "OPTIONS"
.TP
\fB-A\fR
The same as \fB-U\fR, but ARP REPLY packets used instead
of ARP REQUEST.
.TP
\fB-b\fR
Send only MAC level broadcasts. Normally \fBarping\fR starts
from sending broadcast, and switch to unicast after reply received.
.TP
\fB-c \fIcount\fB\fR
Stop after sending \fIcount\fR ARP REQUEST
packets. With
\fIdeadline\fR
option, \fBarping\fR waits for
\fIcount\fR ARP REPLY packets, until the timeout expires.
.TP
\fB-D\fR
Duplicate address detection mode (DAD). See
RFC2131, 4.4.1.
Returns 0, if DAD succeeded i.e. no replies are received
.TP
\fB-f\fR
Finish after the first reply confirming that target is alive.
.TP
\fB-I \fIinterface\fB\fR
Name of network device where to send ARP REQUEST packets. This option
is required.
.TP
\fB-h\fR
Print help page and exit.
.TP
\fB-q\fR
Quiet output. Nothing is displayed.
.TP
\fB-s \fIsource\fB\fR
IP source address to use in ARP packets.
If this option is absent, source address is:
.RS
.TP 0.2i
\(bu
In DAD mode (with option \fB-D\fR) set to 0.0.0.0.
.TP 0.2i
\(bu
In Unsolicited ARP mode (with options \fB-U\fR or \fB-A\fR)
set to \fIdestination\fR.
.TP 0.2i
\(bu
Otherwise, it is calculated from routing tables.
.RE
.TP
\fB-U\fR
Unsolicited ARP mode to update neighbours' ARP caches.
No replies are expected.
.TP
\fB-V\fR
Print version of the program and exit.
.TP
\fB-w \fIdeadline\fB\fR
Specify a timeout, in seconds, before
\fBarping\fR
exits regardless of how many
packets have been sent or received. In this case
\fBarping\fR
does not stop after
\fIcount\fR
packet are sent, it waits either for
\fIdeadline\fR
expire or until
\fIcount\fR
probes are answered.
.SH "SEE ALSO"
.PP
\fBping\fR(8),
\fBclockdiff\fR(8),
\fBtracepath\fR(8).
.SH "AUTHOR"
.PP
\fBarping\fR was written by
Alexey Kuznetsov
<kuznet@ms2.inr.ac.ru>.
It is now maintained by
YOSHIFUJI Hideaki
<yoshfuji@skbuff.net>.
.SH "SECURITY"
.PP
\fBarping\fR requires CAP_NET_RAWIO capability
to be executed. It is not recommended to be used as set-uid root,
because it allows user to modify ARP caches of neighbour hosts.
.SH "AVAILABILITY"
.PP
\fBarping\fR is part of \fIiputils\fR package
and the latest versions are  available in source form at
http://www.skbuff.net/iputils/iputils-current.tar.bz2.


code:
.\" This manpage has been automatically generated by docbook2man
.\" from a DocBook document.  This tool can be found at:
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.TH "CLOCKDIFF" "8" "24 Mayıs 2011" "iputils-101006" "System Manager's Manual: iputils"
.SH NAME
clockdiff \- measure clock difference between hosts
.SH SYNOPSIS

\fBclockdiff\fR [ \fB-o\fR]  [ \fB-o1\fR]  \fB\fIdestination\fB\fR

.SH "DESCRIPTION"
.PP
\fBclockdiff\fR Measures clock difference between us and
\fIdestination\fR with 1 msec resolution using ICMP TIMESTAMP
[2]
packets or, optionally, IP TIMESTAMP option
[3]
option added to ICMP ECHO.
[1]
.SH "OPTIONS"
.TP
\fB-o\fR
Use IP TIMESTAMP with ICMP ECHO instead of ICMP TIMESTAMP
messages. It is useful with some destinations, which do not support
ICMP TIMESTAMP (f.e. Solaris <2.4).
.TP
\fB-o1\fR
Slightly different form of \fB-o\fR, namely it uses three-term
IP TIMESTAMP with prespecified hop addresses instead of four term one.
What flavor works better depends on target host. Particularly,
\fB-o\fR is better for Linux.
.SH "WARNINGS"
.TP 0.2i
\(bu
Some nodes (Cisco) use non-standard timestamps, which is allowed
by RFC, but makes timestamps mostly useless.
.TP 0.2i
\(bu
Some nodes generate messed timestamps (Solaris>2.4), when
run \fBxntpd\fR. Seems, its IP stack uses a corrupted clock source,
which is synchronized to time-of-day clock periodically and jumps
randomly making timestamps mostly useless. Good news is that you can
use NTP in this case, which is even better.
.TP 0.2i
\(bu
\fBclockdiff\fR shows difference in time modulo 24 days.
.SH "SEE ALSO"
.PP
\fBping\fR(8),
\fBarping\fR(8),
\fBtracepath\fR(8).
.SH "REFERENCES"
.PP
[1] ICMP ECHO,
RFC0792, page 14.
.PP
[2] ICMP TIMESTAMP,
RFC0792, page 16.
.PP
[3] IP TIMESTAMP option,
RFC0791, 3.1, page 16.
.SH "AUTHOR"
.PP
\fBclockdiff\fR was compiled by
Alexey Kuznetsov
<kuznet@ms2.inr.ac.ru>. It was based on code borrowed
from BSD \fBtimed\fR daemon.
It is now maintained by
YOSHIFUJI Hideaki
<yoshfuji@skbuff.net>.
.SH "SECURITY"
.PP
\fBclockdiff\fR requires CAP_NET_RAWIO capability
to be executed. It is safe to be used as set-uid root.
.SH "AVAILABILITY"
.PP
\fBclockdiff\fR is part of \fIiputils\fR package
and the latest versions are  available in source form at
http://www.skbuff.net/iputils/iputils-current.tar.bz2.


code:
.\" This manpage has been automatically generated by docbook2man
.\" from a DocBook document.  This tool can be found at:
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.TH "PING" "8" "24 Mayıs 2011" "iputils-101006" "System Manager's Manual: iputils"
.SH NAME
ping, ping6 \- send ICMP ECHO_REQUEST to network hosts
.SH SYNOPSIS

\fBping\fR [ \fB-LRUbdfnqrvVaAB\fR]  [ \fB-c \fIcount\fB\fR]  [ \fB-m \fImark\fB\fR]  [ \fB-i \fIinterval\fB\fR]  [ \fB-l \fIpreload\fB\fR]  [ \fB-p \fIpattern\fB\fR]  [ \fB-s \fIpacketsize\fB\fR]  [ \fB-t \fIttl\fB\fR]  [ \fB-w \fIdeadline\fB\fR]  [ \fB-F \fIflowlabel\fB\fR]  [ \fB-I \fIinterface\fB\fR]  [ \fB-M \fIhint\fB\fR]  [ \fB-N \fInioption\fB\fR]  [ \fB-Q \fItos\fB\fR]  [ \fB-S \fIsndbuf\fB\fR]  [ \fB-T \fItimestamp option\fB\fR]  [ \fB-W \fItimeout\fB\fR]  [ \fB\fIhop\fB\fR\fI ...\fR]  \fB\fIdestination\fB\fR

.SH "DESCRIPTION"
.PP
\fBping\fR uses the ICMP protocol's mandatory ECHO_REQUEST
datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway.
ECHO_REQUEST datagrams (``pings'') have an IP and ICMP
header, followed by a struct timeval and then an arbitrary
number of ``pad'' bytes used to fill out the packet.
.PP
\fBping6\fR can also send Node Information Queries (RFC4620).
.SH "OPTIONS"
.TP
\fB-a\fR
Audible ping.
.TP
\fB-A\fR
Adaptive ping. Interpacket interval adapts to round-trip time, so that
effectively not more than one (or more, if preload is set) unanswered probe
is present in the network. Minimal interval is 200msec for not super-user.
On networks with low rtt this mode is essentially equivalent to flood mode.
.TP
\fB-b\fR
Allow pinging a broadcast address.
.TP
\fB-B\fR
Do not allow \fBping\fR to change source address of probes.
The address is bound to one selected when \fBping\fR starts.
.TP
\fB-m \fImark\fB\fR
use \fImark\fR to tag the packets going out. This is useful
for variety of reasons within the kernel such as using policy
routing to select specific outbound processing.
.TP
\fB-c \fIcount\fB\fR
Stop after sending \fIcount\fR ECHO_REQUEST
packets. With
\fIdeadline\fR
option, \fBping\fR waits for
\fIcount\fR ECHO_REPLY packets, until the timeout expires.
.TP
\fB-d\fR
Set the SO_DEBUG option on the socket being used.
Essentially, this socket option is not used by Linux kernel.
.TP
\fB-F \fIflow label\fB\fR
Allocate and set 20 bit flow label on echo request packets.
(Only \fBping6\fR). If value is zero, kernel allocates random flow label.
.TP
\fB-f\fR
Flood ping. For every ECHO_REQUEST sent a period ``.'' is printed,
while for ever ECHO_REPLY received a backspace is printed.
This provides a rapid display of how many packets are being dropped.
If interval is not given, it sets interval to zero and
outputs packets as fast as they come back or one hundred times per second,
whichever is more.
Only the super-user may use this option with zero interval.
.TP
\fB-i \fIinterval\fB\fR
Wait \fIinterval\fR seconds between sending each packet.
The default is to wait for one second between each packet normally,
or not to wait in flood mode. Only super-user may set interval
to values less 0.2 seconds.
.TP
\fB-I \fIinterface address\fB\fR
Set source address to specified interface address. Argument
may be numeric IP address or name of device. When pinging IPv6
link-local address this option is required.
.TP
\fB-l \fIpreload\fB\fR
If \fIpreload\fR is specified,
\fBping\fR sends that many packets not waiting for reply.
Only the super-user may select preload more than 3.
.TP
\fB-L\fR
Suppress loopback of multicast packets.  This flag only applies if the ping
destination is a multicast address.
.TP
\fB-N \fInioption\fB\fR
Send ICMPv6 Node Information Queries (RFC4620), instead of Echo Request.
.RS
.TP
\fBname\fR
Queries for Node Names.
.RE
.RS
.TP
\fBipv6\fR
Queries for IPv6 Addresses. There are several IPv6 specific flags.
.RS
.TP
\fBipv6-global\fR
Request IPv6 global-scope addresses.
.RE
.RS
.TP
\fBipv6-sitelocal\fR
Request IPv6 site-local addresses.
.RE
.RS
.TP
\fBipv6-linklocal\fR
Request IPv6 link-local addresses.
.RE
.RS
.TP
\fBipv6-all\fR
Request IPv6 addresses on other interfaces.
.RE
.RE
.RS
.TP
\fBipv4\fR
Queries for IPv4 Addresses.  There is one IPv4 specific flag.
.RS
.TP
\fBipv4-all\fR
Request IPv4 addresses on other interfaces.
.RE
.RE
.RS
.TP
\fBsubject-ipv6=\fIipv6addr\fB\fR
IPv6 subject address.
.RE
.RS
.TP
\fBsubject-ipv4=\fIipv4addr\fB\fR
IPv4 subject address.
.RE
.RS
.TP
\fBsubject-name=\fInodename\fB\fR
Subject name.  If it contains more than one dot,
fully-qualified domain name is assumed.
.RE
.RS
.TP
\fBsubject-fqdn=\fInodename\fB\fR
Subject name.  Fully-qualified domain name is
always assumed.
.RE
.TP
\fB-n\fR
Numeric output only.
No attempt will be made to lookup symbolic names for host addresses.
.TP
\fB-p \fIpattern\fB\fR
You may specify up to 16 ``pad'' bytes to fill out the packet you send.
This is useful for diagnosing data-dependent problems in a network.
For example, \fB-p ff\fR will cause the sent packet
to be filled with all ones.
.TP
\fB-D\fR
Print timestamp (unix time + microseconds as in gettimeofday) before
each line.
.TP
\fB-Q \fItos\fB\fR
Set Quality of Service -related bits in ICMP datagrams.
\fItos\fR can be either decimal or hex number.
Traditionally (RFC1349), these have been interpreted as: 0 for reserved
(currently being redefined as congestion control), 1-4 for Type of Service
and 5-7 for Precedence.
Possible settings for Type of Service are: minimal cost: 0x02,
reliability: 0x04, throughput: 0x08, low delay: 0x10.  Multiple TOS bits
should not be set simultaneously.  Possible settings for
special Precedence range from priority (0x20) to net control (0xe0).  You
must be root (CAP_NET_ADMIN capability) to use Critical or
higher precedence value.  You cannot set
bit 0x01 (reserved) unless ECN has been enabled in the kernel.
In RFC2474, these fields has been redefined as 8-bit Differentiated
Services (DS), consisting of: bits 0-1 of separate data (ECN will be used,
here), and bits 2-7 of Differentiated Services Codepoint (DSCP).
.TP
\fB-q\fR
Quiet output.
Nothing is displayed except the summary lines at startup time and
when finished.
.TP
\fB-R\fR
Record route.
Includes the RECORD_ROUTE option in the ECHO_REQUEST
packet and displays the route buffer on returned packets.
Note that the IP header is only large enough for nine such routes.
Many hosts ignore or discard this option.
.TP
\fB-r\fR
Bypass the normal routing tables and send directly to a host on an attached
interface.
If the host is not on a directly-attached network, an error is returned.
This option can be used to ping a local host through an interface
that has no route through it provided the option \fB-I\fR is also
used.
.TP
\fB-s \fIpacketsize\fB\fR
Specifies the number of data bytes to be sent.
The default is 56, which translates into 64 ICMP
data bytes when combined with the 8 bytes of ICMP header data.
.TP
\fB-S \fIsndbuf\fB\fR
Set socket sndbuf. If not specified, it is selected to buffer
not more than one packet.
.TP
\fB-t \fIttl\fB\fR
Set the IP Time to Live.
.TP
\fB-T \fItimestamp option\fB\fR
Set special IP timestamp options.
\fItimestamp option\fR may be either
\fItsonly\fR (only timestamps),
\fItsandaddr\fR (timestamps and addresses) or
\fItsprespec host1 [host2 [host3 [host4]]]\fR
(timestamp prespecified hops).
.TP
\fB-M \fIhint\fB\fR
Select Path MTU Discovery strategy.
\fIhint\fR may be either \fIdo\fR
(prohibit fragmentation, even local one),
\fIwant\fR (do PMTU discovery, fragment locally when packet size
is large), or \fIdont\fR (do not set DF flag).
.TP
\fB-U\fR
Print full user-to-user latency (the old behaviour). Normally
\fBping\fR
prints network round trip time, which can be different
f.e. due to DNS failures.
.TP
\fB-v\fR
Verbose output.
.TP
\fB-V\fR
Show version and exit.
.TP
\fB-w \fIdeadline\fB\fR
Specify a timeout, in seconds, before
\fBping\fR
exits regardless of how many
packets have been sent or received. In this case
\fBping\fR
does not stop after
\fIcount\fR
packet are sent, it waits either for
\fIdeadline\fR
expire or until
\fIcount\fR
probes are answered or for some error notification from network.
.TP
\fB-W \fItimeout\fB\fR
Time to wait for a response, in seconds. The option affects only timeout
in absence of any responses, otherwise \fBping\fR waits for two RTTs.
.PP
When using \fBping\fR for fault isolation, it should first be run
on the local host, to verify that the local network interface is up
and running. Then, hosts and gateways further and further away should be
``pinged''. Round-trip times and packet loss statistics are computed.
If duplicate packets are received, they are not included in the packet
loss calculation, although the round trip time of these packets is used
in calculating the minimum/average/maximum round-trip time numbers.
When the specified number of packets have been sent (and received) or
if the program is terminated with a
SIGINT, a brief summary is displayed. Shorter current statistics
can be obtained without termination of process with signal
SIGQUIT.
.PP
If \fBping\fR does not receive any reply packets at all it will
exit with code 1. If a packet
\fIcount\fR
and
\fIdeadline\fR
are both specified, and fewer than
\fIcount\fR
packets are received by the time the
\fIdeadline\fR
has arrived, it will also exit with code 1.
On other error it exits with code 2. Otherwise it exits with code 0. This
makes it possible to use the exit code to see if a host is alive or
not.
.PP
This program is intended for use in network testing, measurement and
management.
Because of the load it can impose on the network, it is unwise to use
\fBping\fR during normal operations or from automated scripts.
.SH "ICMP PACKET DETAILS"
.PP
An IP header without options is 20 bytes.
An ICMP ECHO_REQUEST packet contains an additional 8 bytes worth
of ICMP header followed by an arbitrary amount of data.
When a \fIpacketsize\fR is given, this indicated the size of this
extra piece of data (the default is 56). Thus the amount of data received
inside of an IP packet of type ICMP ECHO_REPLY will always be 8 bytes
more than the requested data space (the ICMP header).
.PP
If the data space is at least of size of struct timeval
\fBping\fR uses the beginning bytes of this space to include
a timestamp which it uses in the computation of round trip times.
If the data space is shorter, no round trip times are given.
.SH "DUPLICATE AND DAMAGED PACKETS"
.PP
\fBping\fR will report duplicate and damaged packets.
Duplicate packets should never occur, and seem to be caused by
inappropriate link-level retransmissions.
Duplicates may occur in many situations and are rarely (if ever) a
good sign, although the presence of low levels of duplicates may not
always be cause for alarm.
.PP
Damaged packets are obviously serious cause for alarm and often
indicate broken hardware somewhere in the
\fBping\fR packet's path (in the network or in the hosts).
.SH "TRYING DIFFERENT DATA PATTERNS"
.PP
The (inter)network layer should never treat packets differently depending
on the data contained in the data portion.
Unfortunately, data-dependent problems have been known to sneak into
networks and remain undetected for long periods of time.
In many cases the particular pattern that will have problems is something
that doesn't have sufficient ``transitions'', such as all ones or all
zeros, or a pattern right at the edge, such as almost all zeros.
It isn't necessarily enough to specify a data pattern of all zeros (for
example) on the command line because the pattern that is of interest is
at the data link level, and the relationship between what you type and
what the controllers transmit can be complicated.
.PP
This means that if you have a data-dependent problem you will probably
have to do a lot of testing to find it.
If you are lucky, you may manage to find a file that either can't be sent
across your network or that takes much longer to transfer than other
similar length files.
You can then examine this file for repeated patterns that you can test
using the \fB-p\fR option of \fBping\fR.
.SH "TTL DETAILS"
.PP
The TTL value of an IP packet represents the maximum number of IP routers
that the packet can go through before being thrown away.
In current practice you can expect each router in the Internet to decrement
the TTL field by exactly one.
.PP
The TCP/IP specification states that the TTL field for TCP
packets should be set to 60, but many systems use smaller values
(4.3 BSD uses 30, 4.2 used 15).
.PP
The maximum possible value of this field is 255, and most Unix systems set
the TTL field of ICMP ECHO_REQUEST packets to 255.
This is why you will find you can ``ping'' some hosts, but not reach them
with
\fBtelnet\fR(1)
or
\fBftp\fR(1).
.PP
In normal operation ping prints the TTL value from the packet it receives.
When a remote system receives a ping packet, it can do one of three things
with the TTL field in its response:
.TP 0.2i
\(bu
Not change it; this is what Berkeley Unix systems did before the
4.3BSD Tahoe release. In this case the TTL value in the received packet
will be 255 minus the number of routers in the round-trip path.
.TP 0.2i
\(bu
Set it to 255; this is what current Berkeley Unix systems do.
In this case the TTL value in the received packet will be 255 minus the
number of routers in the path \fBfrom\fR
the remote system \fBto\fR the \fBping\fRing host.
.TP 0.2i
\(bu
Set it to some other value. Some machines use the same value for
ICMP packets that they use for TCP packets, for example either 30 or 60.
Others may use completely wild values.
.SH "BUGS"
.TP 0.2i
\(bu
Many Hosts and Gateways ignore the RECORD_ROUTE option.
.TP 0.2i
\(bu
The maximum IP header length is too small for options like
RECORD_ROUTE to be completely useful.
There's not much that that can be done about this, however.
.TP 0.2i
\(bu
Flood pinging is not recommended in general, and flood pinging the
broadcast address should only be done under very controlled conditions.
.SH "SEE ALSO"
.PP
\fBnetstat\fR(1),
\fBifconfig\fR(8).
.SH "HISTORY"
.PP
The \fBping\fR command appeared in 4.3BSD.
.PP
The version described here is its descendant specific to Linux.
.SH "SECURITY"
.PP
\fBping\fR requires CAP_NET_RAWIO capability
to be executed. It may be used as set-uid root.
.SH "AVAILABILITY"
.PP
\fBping\fR is part of \fIiputils\fR package
and the latest versions are  available in source form at
http://www.skbuff.net/iputils/iputils-current.tar.bz2.


code:
.\" This manpage has been automatically generated by docbook2man
.\" from a DocBook document.  This tool can be found at:
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.TH "RARPD" "8" "24 Mayıs 2011" "iputils-101006" "System Manager's Manual: iputils"
.SH NAME
rarpd \- answer RARP REQUESTs
.SH SYNOPSIS

\fBarping\fR [ \fB-aAvde\fR]  [ \fB-b \fIbootdir\fB\fR]  [ \fB\fIinterface\fB\fR]

.SH "DESCRIPTION"
.PP
Listens
RARP
requests from clients. Provided MAC address of client
is found in \fI/etc/ethers\fR database and
obtained host name is resolvable to an IP address appropriate
for attached network, \fBrarpd\fR answers to client with RARPD
reply carrying an IP address.
.PP
To allow multiple boot servers on the network \fBrarpd\fR
optionally checks for presence Sun-like bootable image in TFTP directory.
It should have form \fBHexadecimal_IP.ARCH\fR, f.e. to load
sparc 193.233.7.98 \fIC1E90762.SUN4M\fR is linked to
an image appropriate for SUM4M in directory \fI/etc/tftpboot\fR.
.SH "WARNING"
.PP
This facility is deeply obsoleted by
BOOTP
and later
DHCP protocols.
However, some clients really still need this to boot.
.SH "OPTIONS"
.TP
\fB-a\fR
Listen on all the interfaces. Currently it is an internal
option, its function is overridden with \fIinterface\fR
argument. It should not be used.
.TP
\fB-A\fR
Listen not only RARP but also ARP messages, some rare clients
use ARP by some unknown reason.
.TP
\fB-v\fR
Be verbose.
.TP
\fB-d\fR
Debug mode. Do not go to background.
.TP
\fB-e\fR
Do not check for presence of a boot image, reply if MAC address
resolves to a valid IP address using \fI/etc/ethers\fR
database and DNS.
.TP
\fB-b \fIbootdir\fB\fR
TFTP boot directory. Default is \fI/etc/tftpboot\fR
.SH "SEE ALSO"
.PP
\fBarping\fR(8),
\fBtftpd\fR(8).
.SH "AUTHOR"
.PP
\fBrarpd\fR was written by
Alexey Kuznetsov
<kuznet@ms2.inr.ac.ru>.
It is now maintained by
YOSHIFUJI Hideaki
<yoshfuji@skbuff.net>.
.SH "SECURITY"
.PP
\fBrarpd\fR requires CAP_NET_RAWIO capability
to listen and send RARP and ARP packets. It also needs CAP_NET_ADMIN
to give to kernel hint for ARP resolution; this is not strictly required,
but some (most of, to be more exact) clients are so badly broken that
are not able to answer ARP before they are finally booted. This is
not wonderful taking into account that clients using RARPD in 2002
are all unsupported relic creatures of 90's and even earlier.
.SH "AVAILABILITY"
.PP
\fBrarpd\fR is part of \fIiputils\fR package
and the latest versions are  available in source form at
http://www.skbuff.net/iputils/iputils-current.tar.bz2.


code:
.\" This manpage has been automatically generated by docbook2man
.\" from a DocBook document.  This tool can be found at:
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.TH "RDISC" "8" "24 Mayıs 2011" "iputils-101006" "System Manager's Manual: iputils"
.SH NAME
rdisc \- network router discovery daemon
.SH SYNOPSIS

\fBrdisc\fR [ \fB-abdfstvV\fR]  [ \fB\fIsend_address\fB\fR]  [ \fB\fIreceive_address\fB\fR]

.SH "DESCRIPTION"
.PP
\fBrdisc\fR implements client side of the ICMP router discover protocol.
\fBrdisc\fR is invoked at boot time to populate the network
routing tables with default routes.
.PP
\fBrdisc\fR listens on the ALL_HOSTS (224.0.0.1) multicast address
(or \fIreceive_address\fR provided it is given)
for ROUTER_ADVERTISE messages from routers. The received
messages are handled by first ignoring those listed router addresses
with which the host does not share a network. Among the remaining addresses
the ones with the highest preference are selected as default routers
and a default route is entered in the kernel routing table
for each one of them.
.PP
Optionally, \fBrdisc\fR can avoid waiting for routers to announce
themselves by sending out a few ROUTER_SOLICITATION messages
to the ALL_ROUTERS (224.0.0.2) multicast address
(or \fIsend_address\fR provided it is given)
when it is started.
.PP
A timer is associated with each router address and the address will
no longer be considered for inclusion in the the routing tables if the
timer expires before a new
\fBadvertise\fR message is received from the router.
The address will also be excluded from consideration if the host receives an
\fBadvertise\fR
message with the preference being maximally negative.
.PP
Server side of router discovery protocol is supported by Cisco IOS
and by any more or less complete UNIX routing daemon, f.e \fBgated\fR.
.SH "OPTIONS"
.TP
\fB-a\fR
Accept all routers independently of the preference they have in their
\fBadvertise\fR messages.
Normally \fBrdisc\fR only accepts (and enters in the kernel routing
tables) the router or routers with the highest preference.
.TP
\fB-b\fR
Opposite to \fB-a\fR, i.e. install only router with the best
preference value. It is default behaviour.
.TP
\fB-d\fR
Send debugging messages to syslog.
.TP
\fB-f\fR
Run \fBrdisc\fR forever even if no routers are found.
Normally \fBrdisc\fR gives up if it has not received any
\fBadvertise\fR message after after soliciting three times,
in which case it exits with a non-zero exit code.
If \fB-f\fR is not specified in the first form then
\fB-s\fR must be specified.
.TP
\fB-s\fR
Send three \fBsolicitation\fR messages initially to quickly discover
the routers when the system is booted.
When \fB-s\fR is specified \fBrdisc\fR
exits with a non-zero exit code if it can not find any routers.
This can be overridden with the \fB-f\fR option.
.TP
\fB-t\fR
Test mode. Do not go to background.
.TP
\fB-v\fR
Be verbose i.e. send lots of debugging messages to syslog.
.TP
\fB-V\fR
Print version and exit.
.SH "HISTORY"
.PP
This program was developed by Sun Microsystems (see copyright
notice in source file). It was ported to Linux by
Alexey Kuznetsov
<kuznet@ms2.inr.ac.ru>.
It is now maintained by
YOSHIFUJI Hideaki
<yoshfuji@skbuff.net>.
.SH "SEE ALSO"
.PP
\fBicmp\fR(7),
\fBinet\fR(7),
\fBping\fR(8).
.SH "REFERENCES"
.PP
Deering, S.E.,ed "ICMP Router Discovery Messages",
RFC1256, Network Information Center, SRI International,
Menlo Park, Calif., September 1991.
.SH "SECURITY"
.PP
\fBrdisc\fR requires CAP_NET_RAWIO to listen
and send ICMP messages and capability CAP_NET_ADMIN
to update routing tables.
.SH "AVAILABILITY"
.PP
\fBrdisc\fR is part of \fIiputils\fR package
and the latest versions are  available in source form at
http://www.skbuff.net/iputils/iputils-current.tar.bz2.


code:
.\" This manpage has been automatically generated by docbook2man
.\" from a DocBook document.  This tool can be found at:
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.TH "TRACEPATH" "8" "24 Mayıs 2011" "iputils-101006" "System Manager's Manual: iputils"
.SH NAME
tracepath, tracepath6 \- traces path to a network host discovering MTU along this path
.SH SYNOPSIS

\fBtracepath\fR [ \fB-n\fR]  [ \fB-b\fR]  [ \fB-l \fIpktlen\fB\fR]  \fB\fIdestination\fB\fR [ \fB\fIport\fB\fR]

.SH "DESCRIPTION"
.PP
It traces path to \fIdestination\fR discovering MTU along this path.
It uses UDP port \fIport\fR or some random port.
It is similar to \fBtraceroute\fR, only does not require superuser
privileges and has no fancy options.
.PP
\fBtracepath6\fR is good replacement for \fBtraceroute6\fR
and classic example of application of Linux error queues.
The situation with IPv4 is worse, because commercial
IP routers do not return enough information in ICMP error messages.
Probably, it will change, when they will be updated.
For now it uses Van Jacobson's trick, sweeping a range
of UDP ports to maintain trace history.
.SH "OPTIONS"
.TP
\fB-n\fR
Print primarily IP addresses numerically.
.TP
\fB-b\fR
Print both of host names and IP addresses.
.TP
\fB-l\fR
Sets the initial packet length to \fIpktlen\fR instead of
65536 for \fBtracepath\fR or 128000 for \fBtracepath6\fR.
.SH "OUTPUT"
.PP

.nf
root@mops:~ # tracepath6 3ffe:2400:0:109::2
 1?: [LOCALHOST]                              pmtu 1500
 1:  dust.inr.ac.ru                   0.411ms
 2:  dust.inr.ac.ru        asymm  1   0.390ms pmtu 1480
 2:  3ffe:2400:0:109::2               463.514ms reached
     Resume: pmtu 1480 hops 2 back 2
.fi
.PP
The first column shows TTL of the probe, followed by colon.
Usually value of TTL is obtained from reply from network,
but sometimes reply does not contain necessary information and
we have to guess it. In this case the number is followed by ?.
.PP
The second column shows the network hop, which replied to the probe.
It is either address of router or word [LOCALHOST], if
the probe was not sent to the network.
.PP
The rest of line shows miscellaneous information about path to
the correspinding network hop. As rule it contains value of RTT.
Additionally, it can show Path MTU, when it changes.
If the path is asymmetric
or the probe finishes before it reach prescribed hop, difference
between number of hops in forward and backward direction is shown
following keyword async. This information is not reliable.
F.e. the third line shows asymmetry of 1, it is because the first probe
with TTL of 2 was rejected at the first hop due to Path MTU Discovery.
.PP
The last line summarizes information about all the path to the destination,
it shows detected Path MTU, amount of hops to the destination and our
guess about amount of hops from the destination to us, which can be
different when the path is asymmetric.
.SH "SEE ALSO"
.PP
\fBtraceroute\fR(8),
\fBtraceroute6\fR(8),
\fBping\fR(8).
.SH "AUTHOR"
.PP
\fBtracepath\fR was written by
Alexey Kuznetsov
<kuznet@ms2.inr.ac.ru>.
.SH "SECURITY"
.PP
No security issues.
.PP
This lapidary deserves to be elaborated.
\fBtracepath\fR is not a privileged program, unlike
\fBtraceroute\fR, \fBping\fR and other beasts of this kind.
\fBtracepath\fR may be executed by everyone who has some access
to network, enough to send UDP datagrams to investigated destination
using given port.
.SH "AVAILABILITY"
.PP
\fBtracepath\fR is part of \fIiputils\fR package
and the latest versions are  available in source form at
http://www.skbuff.net/iputils/iputils-current.tar.bz2.


code:
.\" This manpage has been automatically generated by docbook2man
.\" from a DocBook document.  This tool can be found at:
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
.\" Please send any bug reports, improvements, comments, patches,
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.TH "TRACEROUTE6" "8" "24 Mayıs 2011" "iputils-101006" "System Manager's Manual: iputils"
.SH NAME
traceroute6 \- traces path to a network host
.SH SYNOPSIS

\fBtraceroute6\fR [ \fB-dnrvV\fR]  [ \fB-i \fIinterface\fB\fR]  [ \fB-m \fImax_ttl\fB\fR]  [ \fB-p \fIport\fB\fR]  [ \fB-q \fImax_probes\fB\fR]  [ \fB-s \fIsource\fB\fR]  [ \fB-w \fIwait time\fB\fR]  \fB\fIdestination\fB\fR [ \fB\fIsize\fB\fR]

.SH "DESCRIPTION"
.PP
Description can be found in
\fBtraceroute\fR(8),
all the references to IP replaced to IPv6. It is needless to copy
the description from there.
.SH "SEE ALSO"
.PP
\fBtraceroute\fR(8),
\fBtracepath\fR(8),
\fBping\fR(8).
.SH "HISTORY"
.PP
This program has long history. Author of \fBtraceroute\fR
is Van Jacobson and it first appeared in 1988. This clone is
based on a port of \fBtraceroute\fR to IPv6 published
in NRL IPv6 distribution in 1996. In turn, it was ported
to Linux by Pedro Roque. After this it was kept in sync by
Alexey Kuznetsov
<kuznet@ms2.inr.ac.ru>. And eventually entered
\fBiputils\fR package.
.SH "SECURITY"
.PP
\fBtracepath6\fR requires CAP_NET_RAWIO capability
to be executed. It is safe to be used as set-uid root.
.SH "AVAILABILITY"
.PP
\fBtraceroute6\fR is part of \fIiputils\fR package
and the latest versions are  available in source form at
http://www.skbuff.net/iputils/iputils-current.tar.bz2.


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>iputils</Name>
        <Homepage>https://github.com/iputils/iputils</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>BSD</License>
        <IsA>app:console</IsA>
        <Summary>Network monitoring tools including ping and ping6</Summary>
        <Description>iputils contains network monitoring tools including ping and ping6.</Description>
        <Archive sha1sum="d6fb34d3798eb042dd18a49c66a9680cc13e28ca" type="targz">https://github.com/iputils/iputils/archive/s20161105.tar.gz</Archive>
        <BuildDependencies>
            <Dependency>openssl-devel</Dependency>
            <Dependency>libidn-devel</Dependency>
            <Dependency>libcap-devel</Dependency>
            <!-- needed for generating man pages, see below
            <Dependency>docbook-utils</Dependency>
             -->
        </BuildDependencies>
    </Source>

    <Package>
        <Name>iputils</Name>
        <RuntimeDependencies>
            <Dependency>libcap</Dependency>
            <Dependency>libidn</Dependency>
            <Dependency>openssl</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="config">/etc</Path>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="executable">/usr/sbin</Path>
            <Path fileType="executable">/sbin</Path>
            <Path fileType="data">/lib/systemd/system</Path>
            <Path fileType="config">/etc/conf.d/rdisc</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="man">/usr/share/man</Path>
        </Files>
        <AdditionalFiles>
            <!-- pregenerated man pages, update if necessary. -->
            <AdditionalFile owner="root" permission="0644" target="/usr/share/man/man8/arping.8">man/arping.8</AdditionalFile>
            <AdditionalFile owner="root" permission="0644" target="/usr/share/man/man8/clockdiff.8">man/clockdiff.8</AdditionalFile>
            <AdditionalFile owner="root" permission="0644" target="/usr/share/man/man8/ping.8">man/ping.8</AdditionalFile>
            <AdditionalFile owner="root" permission="0644" target="/usr/share/man/man8/rarpd.8">man/rarpd.8</AdditionalFile>
            <AdditionalFile owner="root" permission="0644" target="/usr/share/man/man8/rdisc.8">man/rdisc.8</AdditionalFile>
            <AdditionalFile owner="root" permission="0644" target="/usr/share/man/man8/tracepath.8">man/tracepath.8</AdditionalFile>
            <AdditionalFile owner="root" permission="0644" target="/usr/share/man/man8/traceroute6.8">man/traceroute6.8</AdditionalFile>

            <AdditionalFile owner="root" permission="0644" target="/etc/xinetd.d/tftp">fedora/tftp.xinetd</AdditionalFile>
            <!-- Add systemd files for rdisc daemon -->
            <!--AdditionalFile owner="root" permission="0644" target="/etc/conf.d/rdisc">fedora/rdisc.sysconfig</AdditionalFile>
            <AdditionalFile owner="root" permission="0644" target="/lib/systemd/system/rdisc.service">fedora/rdisc.service</AdditionalFile-->
        </AdditionalFiles>
    </Package>

    <History>
         <Update release="3">
            <Date>2017-03-02</Date>
            <Version>20161105</Version>
            <Comment>Version Bump</Comment>
            <Name>Ayhan Yalçınsoy</Name>
            <Email>ayhanyalcinsoy@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-06-09</Date>
            <Version>20150815</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2015-10-01</Date>
            <Version>20150815</Version>
            <Comment>First release</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>iputils</Name>
        <Summary xml:lang="tr">ping ve ping6 uygulamalarını da içeren ağ izleme araçları</Summary>
        <Description xml:lang="tr">Iputils, ping ve ping6 gibi ağ izleme araçlarını içeren bir pakettir.</Description>
        <Description xml:lang="fr">Iputils contient les outils de surveillance réseau incluant ping et ping6.</Description>
    </Source>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools

def setup():
    autotools.configure("--enable-static=no \
                         --disable-lynx \
                         --disable-static")

    pisitools.dosed("libtool", " -shared ", " -Wl,-O1,--as-needed -shared ")

def build():
    autotools.make()

def install():
    autotools.install()

    pisitools.dodoc("LICENSE")


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>libasyncns</Name>
        <Homepage>http://0pointer.de/lennart/projects/libasyncns</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>LGPLv2.1</License>
        <IsA>library</IsA>
        A C library for asynchronous name service queries
        <Description>libasyncns is a C library for Linux/Unix for executing name service queries asynchronously. It is an asynchronous wrapper around getaddrinfo(), getnameinfo(), res_query() and res_search() from libc and libresolv.</Description>
        <Archive sha1sum="e82843056e98672ae82d46eae2c164cbf0b09ef9" type="targz">http://0pointer.de/lennart/projects/libasyncns/libasyncns-0.8.tar.gz</Archive>
    </Source>

    <Package>
        <Name>libasyncns</Name>
        <Files>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="doc">/usr/share/doc</Path>
        </Files>
    </Package>

    <Package>
        <Name>libasyncns-devel</Name>
        Development files for libasyncns
        <RuntimeDependencies>
            <Dependency release="current">libasyncns</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="header">/usr/include</Path>
            <Path fileType="data">/usr/lib/pkgconfig</Path>
            <Path fileType="man">/usr/share/man/man3</Path>
        </Files>
    </Package>

    <History>
        <Update release="3">
            <Date>2017-02-17</Date>
            <Version>0.8</Version>
            <Comment>Rebuild.</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-06-09</Date>
            <Version>0.8</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2014-01-29</Date>
            <Version>0.8</Version>
            <Comment>First release</Comment>
            <Name>Stefan Gronewold(groni)</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>libasyncns</Name>
        Asenkron isim servisi sorguları için C kitaplığı
        <Description xml:lang="tr">libasyncns, Linux/Unix üzerinde isim servisi sorgularını asenkron olarak gerçekleştirme imkanı veren bir C kitaplığıdır.</Description>
    </Source>

    <Package>
        <Name>libasyncns-devel</Name>
        libasyncns için geliştirme dosyaları
    </Package>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import get

def setup():
    pisitools.dosed("src/osdep/unix/Makefile","SSLDIR=/usr/local/ssl","SSLDIR=/usr/")
    pisitools.dosed("src/osdep/unix/Makefile","SSLCERTS=$(SSLDIR)/certs","SSLCERTS=/etc/pki/tls/certs/")

def build():
    autotools.make("lnp EXTRAAUTHENTICATORS=gss SSLTYPE=unix.nopwd  \
            EXTRACFLAGS=\"%s\" " %get.CFLAGS())

def install():
    pisitools.dolib("c-client/libc-client.so.1.0.0")
    pisitools.dosym("/usr/lib/libc-client.so.1.0.0", "/usr/lib/libc-client.so.1")
    pisitools.dosym("libc-client.so.1.0.0","/usr/lib/libc-client.so")
    pisitools.dodir("/usr/include/imap")
    pisitools.insinto("/usr/include/imap", "src/c-client/*.h")
    pisitools.insinto("/usr/include/imap", "c-client/linkage.c")
    pisitools.insinto("/usr/include/imap", "c-client/linkage.h")
    pisitools.insinto("/usr/include/imap", "c-client/osdep.h")
    pisitools.insinto("/usr/include/imap", "src/osdep/unix/dummy.h")
    pisitools.insinto("/usr/include/imap", "src/osdep/unix/env_unix.h")
    pisitools.insinto("/usr/include/imap", "src/osdep/unix/f*.h")
    pisitools.insinto("/usr/include/imap", "src/osdep/unix/pseudo.h")
    pisitools.insinto("/usr/include/imap", "src/osdep/unix/tcp_unix.h")
    pisitools.insinto("/usr/include/imap", "src/osdep/unix/unix.h")
    pisitools.insinto("/usr/include/imap", "src/osdep/unix/os_slx.h")
    #pisitools.remove("/usr/include/imap/os_*.h")


code:
diff -Naur imap-2007e/Makefile imap-2007e.oden/Makefile
--- imap-2007e/Makefile	2008-06-04 20:43:35.000000000 +0200
+++ imap-2007e.oden/Makefile	2009-01-13 23:59:31.000000000 +0100
@@ -144,7 +144,7 @@
 # mbox	if file "mbox" exists on the home directory, automatically moves mail
 #	 from the spool directory to "mbox" and uses "mbox" as INBOX.

-EXTRADRIVERS=mbox
+EXTRADRIVERS=

 # Plaintext password type.  Defines how plaintext password authentication is
diff -Naur imap-2007e/src/osdep/unix/Makefile imap-2007e.oden/src/osdep/unix/Makefile
--- imap-2007e/src/osdep/unix/Makefile	2009-01-13 23:59:14.000000000 +0100
+++ imap-2007e.oden/src/osdep/unix/Makefile	2009-01-13 23:59:31.000000000 +0100
@@ -27,7 +27,7 @@
 # Command line build parameters

 EXTRAAUTHENTICATORS=
-EXTRADRIVERS=mbox
+EXTRADRIVERS=
 PASSWDTYPE=std
 SSLTYPE=nopwd
 IP=4


code:
--- imap-2001a/src/c-client/rfc822.c.overflow	Wed Apr 17 22:39:13 2002
+++ imap-2001a/src/c-client/rfc822.c	Wed Apr 17 22:40:25 2002
@@ -610,6 +610,9 @@
 	if (CHR (bs) == '\012'){/* following LF? */
 	  c = SNX (bs); i--;	/* yes, slurp it */
 	}
+	if (!i)			/* Make sure we don't get an overflow for */
+	  break;		/* messages ending on \015 (or the following */
+				/* i-- will cause i to be MAXINT. Not good.) */
       case '\012':		/* at start of a line, start with -- ? */
 	if (i-- && ((c = SNX (bs)) == '-') && i-- && ((c = SNX (bs)) == '-')) {
 				/* see if cookie matches */


code:
Patch by Robert Scheck <redhat@linuxnetz.de> for uw-imap >= 2004a, which corrects
paths to imapd, ipop2d and ipop3d in the man pages.

This patch is based on Red Hat Bugzilla ID #127271 and solves ID #229781.

--- imap-2004a/src/imapd/imapd.8		2004-05-18 19:46:54.000000000 +0200
+++ imap-2004a/src/imapd/imapd.8.doc		2004-07-23 15:24:17.000000000 +0200
@@ -3,7 +3,7 @@
 .SH NAME
 IMAPd \- Internet Message Access Protocol server
 .SH SYNOPSIS
-.B /usr/etc/imapd
+.B /usr/sbin/imapd
 .SH DESCRIPTION
 .I imapd
 is a server which supports the
--- imap-2004a/src/ipopd/ipopd.8		2004-05-18 19:50:05.000000000 +0200
+++ imap-2004a/src/ipopd/ipopd.8.doc		2004-07-23 15:23:38.000000000 +0200
@@ -3,9 +3,9 @@
 .SH NAME
 IPOPd \- Post Office Protocol server
 .SH SYNOPSIS
-.B /usr/etc/ipop2d
+.B /usr/sbin/ipop2d
 .PP
-.B /usr/etc/ipop3d
+.B /usr/sbin/ipop3d
 .SH DESCRIPTION
 .I ipop2d
 and


code:
diff -Naurp imap-2007e/src/osdep/unix/env_unix.c imap-2007e.oden/src/osdep/unix/env_unix.c
--- imap-2007e/src/osdep/unix/env_unix.c	2008-06-04 20:46:10.000000000 +0200
+++ imap-2007e.oden/src/osdep/unix/env_unix.c	2009-01-14 00:01:54.000000000 +0100
@@ -24,6 +24,7 @@
  * Last Edited:	15 May 2008
  */

+#include <time.h>
 #include <grp.h>
 #include <signal.h>
 #include <sys/wait.h>
diff -Naurp imap-2007e/src/osdep/unix/mh.c imap-2007e.oden/src/osdep/unix/mh.c
--- imap-2007e/src/osdep/unix/mh.c	2008-06-04 20:18:34.000000000 +0200
+++ imap-2007e.oden/src/osdep/unix/mh.c	2009-01-14 00:01:54.000000000 +0100
@@ -36,11 +36,11 @@ extern int errno;		/* just in case */
 #include <pwd.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <time.h>
 #include "misc.h"
 #include "dummy.h"
 #include "fdstring.h"

-
 /* Build parameters */

 #define MHINBOX "#mhinbox"	/* corresponds to namespace in env_unix.c */
diff -Naurp imap-2007e/src/osdep/unix/mx.c imap-2007e.oden/src/osdep/unix/mx.c
--- imap-2007e/src/osdep/unix/mx.c	2008-06-04 20:18:34.000000000 +0200
+++ imap-2007e.oden/src/osdep/unix/mx.c	2009-01-14 00:01:54.000000000 +0100
@@ -36,6 +36,7 @@ extern int errno;		/* just in case */
 #include <pwd.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <time.h>
 #include "misc.h"
 #include "dummy.h"
 #include "fdstring.h"
diff -Naurp imap-2007e/src/osdep/unix/news.c imap-2007e.oden/src/osdep/unix/news.c
--- imap-2007e/src/osdep/unix/news.c	2008-06-04 20:18:34.000000000 +0200
+++ imap-2007e.oden/src/osdep/unix/news.c	2009-01-14 00:01:54.000000000 +0100
@@ -35,6 +35,7 @@ extern int errno;		/* just in case */
 #include "osdep.h"
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <time.h>
 #include "misc.h"
 #include "newsrc.h"
 #include "fdstring.h"
diff -Naurp imap-2007e/src/osdep/unix/phile.c imap-2007e.oden/src/osdep/unix/phile.c
--- imap-2007e/src/osdep/unix/phile.c	2008-06-04 20:18:34.000000000 +0200
+++ imap-2007e.oden/src/osdep/unix/phile.c	2009-01-14 00:01:54.000000000 +0100
@@ -37,6 +37,7 @@ extern int errno;		/* just in case */
 #include <pwd.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <time.h>
 #include "rfc822.h"
 #include "misc.h"
 #include "dummy.h"


code:
--- src/osdep/unix/Makefile.gss	2006-08-31 03:32:16.000000000 +0200
+++ src/osdep/unix/Makefile.gss.oden	2006-10-26 16:40:37.000000000 +0200
@@ -26,7 +26,7 @@

 # Extended flags needed for additional authenticators.  You may need to modify.

-GSSDIR=/usr/local
+GSSDIR=/usr
 GSSINCLUDE=$(GSSDIR)/include
 GSSLIB=$(GSSDIR)/lib
 GSSCFLAGS= -I$(GSSINCLUDE) -DGSS_C_NT_HOSTBASED_SERVICE=gss_nt_service_name


code:
--- src/osdep/unix/Makefile	2007-12-17 23:10:24.000000000 +0100
+++ src/osdep/unix/Makefile.oden	2008-05-18 19:06:50.000000000 +0200
@@ -42,7 +42,7 @@
 # -O3 seems to be safe, but empirical observation from our local expert
 # indicates that in some (many?) cases -O3 code runs slower than -O2.

-GCCOPTLEVEL= -O2
+GCCOPTLEVEL=

 # Try to have some consistency in GCC builds.  We want optimization, but we
@@ -96,19 +96,18 @@
 LOGINPW=std
 SIGTYPE=bsd
 CRXTYPE=std
-ACTIVEFILE=/usr/lib/news/active
-SPOOLDIR=/usr/spool
+ACTIVEFILE=/var/lib/news/active
+SPOOLDIR=/var/spool
 MAILSPOOL=$(SPOOLDIR)/mail
 NEWSSPOOL=$(SPOOLDIR)/news
-RSHPATH=/usr/ucb/rsh
+RSHPATH=/usr/bin/rsh
 MD5PWD=/etc/cram-md5.pwd
 # Tries one of the test alternatives below if not specified.
-LOCKPGM=
+#LOCKPGM=/etc/mlock
 # Test alternatives if LOCKPGM not specified
-LOCKPGM1=/usr/libexec/mlock
-LOCKPGM2=/usr/sbin/mlock
-LOCKPGM3=/etc/mlock
-
+#LOCKPGM1=/usr/libexec/mlock
+#LOCKPGM2=/usr/sbin/mlock
+#LOCKPGM3=/etc/mlock

 # Default formats for creating new mailboxes and for empty mailboxes in the
 # default namespace; must be set to the associated driver's prototype.


code:
diff -up imap-2007e/src/c-client/auth_md5.c.authmd5 imap-2007e/src/c-client/auth_md5.c
--- imap-2007e/src/c-client/auth_md5.c.authmd5	2008-06-04 13:18:34.000000000 -0500
+++ imap-2007e/src/c-client/auth_md5.c	2009-07-07 19:24:12.348005485 -0500
@@ -42,17 +42,17 @@ typedef struct {

 /* Prototypes */

-long auth_md5_valid (void);
-long auth_md5_client (authchallenge_t challenger,authrespond_t responder,
+static long auth_md5_valid (void);
+static long auth_md5_client (authchallenge_t challenger,authrespond_t responder,
 		      char *service,NETMBX *mb,void *stream,
 		      unsigned long *trial,char *user);
-char *auth_md5_server (authresponse_t responder,int argc,char *argv[]);
-char *auth_md5_pwd (char *user);
+static char *auth_md5_server (authresponse_t responder,int argc,char *argv[]);
+static char *auth_md5_pwd (char *user);
 char *apop_login (char *chal,char *user,char *md5,int argc,char *argv[]);
-char *hmac_md5 (char *text,unsigned long tl,char *key,unsigned long kl);
-void md5_init (MD5CONTEXT *ctx);
-void md5_update (MD5CONTEXT *ctx,unsigned char *data,unsigned long len);
-void md5_final (unsigned char *digest,MD5CONTEXT *ctx);
+static char *hmac_md5 (char *text,unsigned long tl,char *key,unsigned long kl);
+static void md5_init (MD5CONTEXT *ctx);
+static void md5_update (MD5CONTEXT *ctx,unsigned char *data,unsigned long len);
+static void md5_final (unsigned char *digest,MD5CONTEXT *ctx);
 static void md5_transform (unsigned long *state,unsigned char *block);
 static void md5_encode (unsigned char *dst,unsigned long *src,int len);
 static void md5_decode (unsigned long *dst,unsigned char *src,int len);


code:
diff -up imap-2007e/src/osdep/unix/Makefile.shared imap-2007e/src/osdep/unix/Makefile
--- imap-2007e/src/osdep/unix/Makefile.shared	2009-07-07 19:28:02.909755512 -0500
+++ imap-2007e/src/osdep/unix/Makefile	2009-07-07 19:29:35.870006799 -0500
@@ -170,6 +170,10 @@ BUILD=$(MAKE) build EXTRACFLAGS='$(EXTRA
  EXTRADRIVERS='$(EXTRADRIVERS)' EXTRAAUTHENTICATORS='$(EXTRAAUTHENTICATORS)'\
  PASSWDTYPE=$(PASSWDTYPE) SSLTYPE=$(SSLTYPE) IP=$(IP)

+# Need this for the shared library rule to work correctly
+.SUFFIXES: .o .so
+SOFILES=${BINARIES:.o=.so}
+

 # Here if no make argument established

@@ -845,18 +849,24 @@ vu2:	# VAX Ultrix 2.3, etc.

 # Build it!

-build:	clean once $(ARCHIVE)
+build:	clean once $(ARCHIVE) $(SHLIBNAME)

-all:	$(ARCHIVE)
+all:	$(ARCHIVE) $(SHLIBNAME)

 $(ARCHIVE): $(BINARIES)
 	sh -c '$(RM) $(ARCHIVE) || true'
 	@$(CAT) ARCHIVE
 	@$(SH) ARCHIVE

-.c.o:
-	`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` $*.c
+$(SHLIBNAME):	$(SOFILES)
+	gcc -shared -Wl,-soname,$(SHLIBNAME) -o $(SHLIBNAME) $(SOFILES) `cat LDFLAGS`
+	ln -s $(SHLIBNAME) lib$(SHLIBBASE).so

+.c.so:	osdep.h
+	$(CC) -fPIC -DPIC -D_REENTRANT -c `$(CAT) CFLAGS` ${@:.so=.c} -o $@
+
+.c.o:
+	$(CC) -fPIC -DPIC -D_REENTRANT -c `$(CAT) CFLAGS` $*.c

 # Cleanup

@@ -895,8 +905,7 @@ utf8aux.o: mail.h misc.h osdep.h utf8.h

 # OS-dependent
-
-osdep.o:mail.h misc.h env.h fs.h ftl.h nl.h tcp.h \
+OSDEPS= mail.h misc.h env.h fs.h ftl.h nl.h tcp.h \
 	osdep.h env_unix.h tcp_unix.h \
 	osdep.c env_unix.c fs_unix.c ftl_unix.c nl_unix.c tcp_unix.c ip_unix.c\
 	auths.c crexcl.c flockcyg.c flocklnx.c flocksim.c fsync.c \
@@ -910,12 +919,19 @@ osdep.o:mail.h misc.h env.h fs.h ftl.h n
 	write.c sslstdio.c \
 	strerror.c strpbrk.c strstr.c strtok.c strtoul.c \
 	OSCFLAGS
+
+osdep.o:	$(OSDEPS)
+	$(CC) -fPIC -DPIC -D_REENTRANT `$(CAT) CFLAGS` `$(CAT) OSCFLAGS` -c osdep.c
+	@echo ========================================================================
 	@echo Building OS-dependent module
 	@echo If you get No such file error messages for files x509.h, ssl.h,
 	@echo pem.h, buffer.h, bio.h, and crypto.h, that means that OpenSSL
 	@echo is not installed on your system.  Either install OpenSSL first
 	@echo or build with command: make `$(CAT) OSTYPE` SSLTYPE=none
-	`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` `$(CAT) OSCFLAGS` -c osdep.c
+	@echo ========================================================================
+
+osdep.so:	$(OSDEPS)
+	$(CC) -fPIC -DPIC -D_REENTRANT `$(CAT) CFLAGS` `cat OSCFLAGS` -c osdep.c -o $@

 osdep.c: osdepbas.c osdepckp.c osdeplog.c osdepssl.c
 	$(CAT) osdepbas.c osdepckp.c osdeplog.c osdepssl.c > osdep.c