pscan: new applet (portscanner). ~1350 bytes. By Tito <farmatito@tiscali.it>
[oweals/busybox.git] / networking / libiproute / ll_addr.c
index 51ff13b8c0ec431fdbe6a2c2750eb09ea3301212..ab5a2c522c46035a39371376bf705a1324ac1409 100644 (file)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * ll_addr.c
  *
  * Authors:    Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-
-#include <linux/netdevice.h>
-#include <linux/if_arp.h>
-#include <linux/sockios.h>
+#include <net/if_arp.h>
 
+#include "libbb.h"
+#include "rt_names.h"
 #include "utils.h"
 
 
@@ -40,7 +29,7 @@ const char *ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int
        l = 0;
        for (i=0; i<alen; i++) {
                if (i==0) {
-                       snprintf(buf+l, blen, "%02x", addr[i]);
+                       snprintf(buf+l, blen, ":%02x"+1, addr[i]);
                        blen -= 2;
                        l += 2;
                } else {
@@ -57,11 +46,12 @@ int ll_addr_a2n(unsigned char *lladdr, int len, char *arg)
        if (strchr(arg, '.')) {
                inet_prefix pfx;
                if (get_addr_1(&pfx, arg, AF_INET)) {
-                       fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg);
+                       bb_error_msg("\"%s\" is invalid lladdr", arg);
                        return -1;
                }
-               if (len < 4)
+               if (len < 4) {
                        return -1;
+               }
                memcpy(lladdr, pfx.data, 4);
                return 4;
        } else {
@@ -75,16 +65,17 @@ int ll_addr_a2n(unsigned char *lladdr, int len, char *arg)
                                cp++;
                        }
                        if (sscanf(arg, "%x", &temp) != 1) {
-                               fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg);
+                               bb_error_msg("\"%s\" is invalid lladdr", arg);
                                return -1;
                        }
                        if (temp < 0 || temp > 255) {
-                               fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg);
+                               bb_error_msg("\"%s\" is invalid lladdr", arg);
                                return -1;
                        }
                        lladdr[i] = temp;
-                       if (!cp)
+                       if (!cp) {
                                break;
+                       }
                        arg = cp;
                }
                return i+1;