* NET-3 Networking Distribution for the LINUX operating
* system.
*
- * Version: $Id: arp.c,v 1.24 2005/05/16 04:30:17 ecki Exp $
+ * Version: $Id: arp.c,v 1.27 2009/09/06 22:50:11 vapier Exp $
*
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
*
{
char host[128];
struct arpreq req;
- struct sockaddr sa;
+ struct sockaddr_storage ss;
+ struct sockaddr *sa;
int flags = 0;
int deleted = 0;
return (-1);
}
safe_strncpy(host, *args, (sizeof host));
- if (ap->input(0, host, &sa) < 0) {
+ sa = (struct sockaddr *)&ss;
+ if (ap->input(0, host, sa) < 0) {
ap->herror(host);
return (-1);
}
/* If a host has more than one address, use the correct one! */
- memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr));
+ memcpy((char *) &req.arp_pa, (char *) sa, sizeof(struct sockaddr));
if (hw_set)
req.arp_ha.sa_family = hw->type;
usage();
if (strcmp(*args, "255.255.255.255") != 0) {
strcpy(host, *args);
- if (ap->input(0, host, &sa) < 0) {
+ if (ap->input(0, host, sa) < 0) {
ap->herror(host);
return (-1);
}
- memcpy((char *) &req.arp_netmask, (char *) &sa,
+ memcpy((char *) &req.arp_netmask, (char *) sa,
sizeof(struct sockaddr));
req.arp_flags |= ATF_NETMASK;
}
struct ifreq ifr;
struct hwtype *xhw;
- strcpy(ifr.ifr_name, ifname);
+ strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) {
fprintf(stderr, _("arp: cant get HW-Address for `%s': %s.\n"), ifname, strerror(errno));
return (-1);
{
char host[128];
struct arpreq req;
- struct sockaddr sa;
+ struct sockaddr_storage ss;
+ struct sockaddr *sa;
int flags;
memset((char *) &req, 0, sizeof(req));
return (-1);
}
safe_strncpy(host, *args++, (sizeof host));
- if (ap->input(0, host, &sa) < 0) {
+ sa = (struct sockaddr *)&ss;
+ if (ap->input(0, host, sa) < 0) {
ap->herror(host);
return (-1);
}
/* If a host has more than one address, use the correct one! */
- memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr));
+ memcpy((char *) &req.arp_pa, (char *) sa, sizeof(struct sockaddr));
/* Fetch the hardware address. */
if (*args == NULL) {
usage();
if (strcmp(*args, "255.255.255.255") != 0) {
strcpy(host, *args);
- if (ap->input(0, host, &sa) < 0) {
+ if (ap->input(0, host, sa) < 0) {
ap->herror(host);
return (-1);
}
- memcpy((char *) &req.arp_netmask, (char *) &sa,
+ memcpy((char *) &req.arp_netmask, (char *) sa,
sizeof(struct sockaddr));
flags |= ATF_NETMASK;
}
/* Print the contents of an ARP request block. */
-static void arp_disp_2(char *name, int type, int arp_flags, char *hwa, char *mask, char *dev)
+static void arp_disp_2(const char *name, int type, int arp_flags, const char *hwa, const char *mask, const char *dev)
{
static int title = 0;
struct hwtype *xhw;
}
/* Print the contents of an ARP request block. */
-static void arp_disp(char *name, char *ip, int type, int arp_flags, char *hwa, char *mask, char *dev)
+static void arp_disp(const char *name, const char *ip, int type, int arp_flags, const char *hwa, const char *mask, const char *dev)
{
struct hwtype *xhw;
static int arp_show(char *name)
{
char host[100];
- struct sockaddr sa;
+ struct sockaddr_storage ss;
+ struct sockaddr *sa;
char ip[100];
char hwa[100];
char mask[100];
char dev[100];
int type, flags;
FILE *fp;
- char *hostname;
+ const char *hostname;
int num, entries = 0, showed = 0;
host[0] = '\0';
+ sa = (struct sockaddr *)&ss;
if (name != NULL) {
/* Resolve the host name. */
safe_strncpy(host, name, (sizeof host));
- if (ap->input(0, host, &sa) < 0) {
+ if (ap->input(0, host, sa) < 0) {
ap->herror(host);
return (-1);
}
- safe_strncpy(host, ap->sprint(&sa, 1), sizeof(host));
+ safe_strncpy(host, ap->sprint(sa, 1), sizeof(host));
}
/* Open the PROCps kernel table. */
if ((fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL) {
strcpy(dev, "-");
/* Read the ARP cache entries. */
for (; fgets(line, sizeof(line), fp);) {
- num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n",
+ num = sscanf(line, "%s 0x%x 0x%x %99s %99s %99s\n",
ip, &type, &flags, hwa, mask, dev);
if (num < 4)
break;
if (opt_n)
hostname = "?";
else {
- if (ap->input(0, ip, &sa) < 0)
+ if (ap->input(0, ip, sa) < 0)
hostname = ip;
else
- hostname = ap->sprint(&sa, opt_n | 0x8000);
+ hostname = ap->sprint(sa, opt_n | 0x8000);
if (strcmp(hostname, ip) == 0)
hostname = "?";
}
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -Ds <host> <if> [netmask <nm>] pub <-''-\n\n"));
fprintf(stderr, _(" -a display (all) hosts in alternative (BSD) style\n"));
+ fprintf(stderr, _(" -e display (all) hosts in default (Linux) style\n"));
fprintf(stderr, _(" -s, --set set a new ARP entry\n"));
fprintf(stderr, _(" -d, --delete delete a specified entry\n"));
fprintf(stderr, _(" -v, --verbose be verbose\n"));