*
*/
-#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <linux/version.h>
+
+#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <linux/if.h>
-#include <linux/if_packet.h>
+
+#include <net/if.h>
+#include <net/if_packet.h>
+#include <netpacket/packet.h>
+
+#if __GLIBC__ >=2 && __GLIBC_MINOR >= 1
+#include <net/ethernet.h>
+#else
#include <linux/if_ether.h>
-#include <linux/sockios.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <linux/sockios.h>
+#endif
#include "rt_names.h"
#include "utils.h"
#include "ip_common.h"
-#include "busybox.h"
+#include "libbb.h"
+
+
+/* take from linux/sockios.h */
+#define SIOCSIFNAME 0x8923 /* set interface name */
static int do_link;
static int on_off(char *msg)
{
- error_msg("Error: argument of \"%s\" must be \"on\" or \"off\"", msg);
+ bb_error_msg("Error: argument of \"%s\" must be \"on\" or \"off\"", msg);
return -1;
}
static int do_changename(char *dev, char *newdev)
{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
struct ifreq ifr;
int fd;
int err;
}
close(fd);
return err;
+#endif
+ return 0;
}
static int set_qlen(char *dev, int qlen)
return -1;
memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, dev);
- ifr.ifr_qlen = qlen;
+ strcpy(ifr.ifr_name, dev);
+ ifr.ifr_qlen = qlen;
if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
perror("SIOCSIFXQLEN");
close(s);
}
close(s);
- return 0;
+ return 0;
}
static int set_mtu(char *dev, int mtu)
return -1;
memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, dev);
- ifr.ifr_mtu = mtu;
+ strcpy(ifr.ifr_name, dev);
+ ifr.ifr_mtu = mtu;
if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
perror("SIOCSIFMTU");
close(s);
}
close(s);
- return 0;
+ return 0;
}
static int get_address(char *dev, int *htype)
int s;
s = socket(PF_PACKET, SOCK_DGRAM, 0);
- if (s < 0) {
+ if (s < 0) {
perror("socket(PF_PACKET)");
return -1;
}
if (alen < 0)
return -1;
if (alen != halen) {
- error_msg("Wrong address (%s) length: expected %d bytes", lla, halen);
+ bb_error_msg("Wrong address (%s) length: expected %d bytes", lla, halen);
return -1;
}
- return 0;
+ return 0;
}
static int set_address(struct ifreq *ifr, int brd)
return -1;
}
close(s);
- return 0;
+ return 0;
}
}
if (!dev) {
- error_msg("Not enough of information: \"dev\" argument is required.");
+ bb_error_msg("Not enough of information: \"dev\" argument is required.");
exit(-1);
}
}
if (newbrd) {
if (parse_address(dev, htype, halen, newbrd, &ifr1) < 0)
- return -1;
+ return -1;
}
}
return -1;
dev = newname;
}
- if (qlen != -1) {
+ if (qlen != -1) {
if (set_qlen(dev, qlen) < 0)
- return -1;
+ return -1;
}
- if (mtu != -1) {
+ if (mtu != -1) {
if (set_mtu(dev, mtu) < 0)
- return -1;
+ return -1;
}
if (newaddr || newbrd) {
if (newbrd) {
if (set_address(&ifr1, 1) < 0)
- return -1;
+ return -1;
}
if (newaddr) {
if (set_address(&ifr0, 0) < 0)
{
preferred_family = AF_PACKET;
do_link = 1;
- return ipaddr_list(argc, argv);
+ return ipaddr_list_or_flush(argc, argv, 0);
}
int do_iplink(int argc, char **argv)
} else
return ipaddr_list_link(0, NULL);
- error_msg("Command \"%s\" is unknown, try \"ip link help\".", *argv);
+ bb_error_msg("Command \"%s\" is unknown.", *argv);
exit(-1);
}