components/iftop/patches/06.addrs_dlpi.c.patch
changeset 306 9da68c8821e3
equal deleted inserted replaced
305:e95b65443448 306:9da68c8821e3
       
     1 --- addrs_dlpi.c.orig	Tue Feb 10 13:55:04 2009
       
     2 +++ addrs_dlpi.c	Fri Jan 16 12:42:53 2009
       
     3 @@ -24,11 +24,8 @@
       
     4  #include <sys/sockio.h>
       
     5  #include <sys/ioctl.h>
       
     6  #include <sys/socket.h>
       
     7 -#include <sys/dlpi.h>
       
     8  #include <net/if.h>
       
     9  
       
    10 -#include "dlcommon.h"
       
    11 -
       
    12  extern char *split_dname(char *device, int *unitp);
       
    13  extern char *strncpy2(char *dest, char *src, int n);
       
    14  extern char *strncat2(char *dest, char *src, int n);
       
    15 @@ -56,123 +53,8 @@
       
    16    int got_ip_addr = 0;
       
    17  
       
    18    int fd;
       
    19 -  long buf[MAXDLBUF];		/* long aligned */
       
    20 -  union DL_primitives *dlp;
       
    21 -
       
    22 -  char *cp;
       
    23 -  int unit_num = 0;
       
    24 -  int sap = 0;
       
    25 -
       
    26 -  char *devname = NULL;
       
    27 -  char *devname2 = NULL;
       
    28 -  char fulldevpath[256];
       
    29 -
       
    30    struct ifreq ifr = {};
       
    31  
       
    32 -  /* -- */
       
    33 -
       
    34 -  memset(if_hw_addr, 0, 6);
       
    35 -
       
    36 -  // we want to be able to process either a fully qualified /dev/ge0
       
    37 -  // type interface definition, or just ge0.
       
    38 -
       
    39 -  if (strncmp(interface, "/dev/", strlen("/dev/")) == 0) {
       
    40 -    devname = interface + strlen("/dev/");
       
    41 -  } else {
       
    42 -    devname = interface;
       
    43 -  }
       
    44 -
       
    45 -  strncpy2(fulldevpath, "/dev/", sizeof(fulldevpath)-1);
       
    46 -  cp = strncat2(fulldevpath, interface, sizeof(fulldevpath));
       
    47 -
       
    48 -  if (strlen(cp) != 0) {
       
    49 -    fprintf(stderr, "device name buffer overflow %s\n", fulldevpath);
       
    50 -    return -1;
       
    51 -  }
       
    52 -
       
    53 -  fprintf(stderr,"interface: %s\n", devname);
       
    54 -
       
    55 -  // on Solaris, even though we are wanting to talk to ethernet device
       
    56 -  // ge0, we have to open /dev/ge, then bind to unit 0.  Dupe our
       
    57 -  // full path, then identify and cut off the unit number
       
    58 -
       
    59 -  devname2 = strdup(fulldevpath);
       
    60 -
       
    61 -  cp = split_dname(devname2, &unit_num);
       
    62 -
       
    63 -  if (cp == NULL) {
       
    64 -    free(devname2);
       
    65 -    goto get_ip_address;
       
    66 -  } else {
       
    67 -    *cp = '\0';			/* null terminate devname2 right before numeric extension */
       
    68 -  }
       
    69 -
       
    70 -  // devname2 should now be something akin to /dev/ge.  Try to open
       
    71 -  // it, and if it fails, fall back to the full /dev/ge0.
       
    72 -
       
    73 -  if ((fd = open(devname2, O_RDWR)) < 0) {
       
    74 -    if (errno != ENOENT) {
       
    75 -      fprintf(stderr, "Couldn't open %s\n", devname2);
       
    76 -      free(devname2);
       
    77 -      goto get_ip_address;
       
    78 -    } else {
       
    79 -      if ((fd = open(fulldevpath, O_RDWR)) < 0) {
       
    80 -	fprintf(stderr, "Couldn't open %s\n", fulldevpath);
       
    81 -	free(devname2);
       
    82 -	goto get_ip_address;
       
    83 -      }
       
    84 -    }
       
    85 -  }
       
    86 -
       
    87 -  free(devname2);
       
    88 -  devname2 = NULL;
       
    89 -
       
    90 -  /* Use the dlcommon functions to get access to the DLPI information for this
       
    91 -   * interface.  All of these functions exit() out on failure
       
    92 -   */
       
    93 -
       
    94 -  dlp = (union DL_primitives*) buf;
       
    95 -
       
    96 -  /*
       
    97 -   * DLPI attach to our low-level device
       
    98 -   */
       
    99 -
       
   100 -  dlattachreq(fd, unit_num);
       
   101 -  dlokack(fd, buf);
       
   102 -
       
   103 -  /*
       
   104 -   * DLPI bind
       
   105 -   */
       
   106 -
       
   107 -  dlbindreq(fd, sap, 0, DL_CLDLS, 0, 0);
       
   108 -  dlbindack(fd, buf);
       
   109 -
       
   110 -  /*
       
   111 -   * DLPI DL_INFO_REQ
       
   112 -   */
       
   113 -
       
   114 -  dlinforeq(fd);
       
   115 -  dlinfoack(fd, buf);
       
   116 -
       
   117 -  /* 
       
   118 -     printdlprim(dlp);  // uncomment this to dump out info from DLPI
       
   119 -  */
       
   120 -
       
   121 -  if (dlp->info_ack.dl_addr_length + dlp->info_ack.dl_sap_length == 6) {
       
   122 -    memcpy(if_hw_addr, 
       
   123 -	   OFFADDR(dlp, dlp->info_ack.dl_addr_offset),
       
   124 -	   dlp->info_ack.dl_addr_length);
       
   125 -    got_hw_addr = 1;
       
   126 -  } else {
       
   127 -    fprintf(stderr, "Error, bad length for hardware interface %s -- %d\n", 
       
   128 -	    interface,
       
   129 -	    dlp->info_ack.dl_addr_length);
       
   130 -  }
       
   131 -
       
   132 -  close(fd);
       
   133 -
       
   134 - get_ip_address:
       
   135 -
       
   136    /* Get the IP address of the interface */
       
   137  
       
   138  #ifdef SIOCGIFADDR