1 --- addrs_dlpi.c.orig Tue Feb 10 13:55:04 2009
2 +++ addrs_dlpi.c Fri Jan 16 12:42:53 2009
4 #include <sys/sockio.h>
6 #include <sys/socket.h>
10 -#include "dlcommon.h"
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);
19 - long buf[MAXDLBUF]; /* long aligned */
20 - union DL_primitives *dlp;
26 - char *devname = NULL;
27 - char *devname2 = NULL;
28 - char fulldevpath[256];
30 struct ifreq ifr = {};
34 - memset(if_hw_addr, 0, 6);
36 - // we want to be able to process either a fully qualified /dev/ge0
37 - // type interface definition, or just ge0.
39 - if (strncmp(interface, "/dev/", strlen("/dev/")) == 0) {
40 - devname = interface + strlen("/dev/");
42 - devname = interface;
45 - strncpy2(fulldevpath, "/dev/", sizeof(fulldevpath)-1);
46 - cp = strncat2(fulldevpath, interface, sizeof(fulldevpath));
48 - if (strlen(cp) != 0) {
49 - fprintf(stderr, "device name buffer overflow %s\n", fulldevpath);
53 - fprintf(stderr,"interface: %s\n", devname);
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
59 - devname2 = strdup(fulldevpath);
61 - cp = split_dname(devname2, &unit_num);
65 - goto get_ip_address;
67 - *cp = '\0'; /* null terminate devname2 right before numeric extension */
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.
73 - if ((fd = open(devname2, O_RDWR)) < 0) {
74 - if (errno != ENOENT) {
75 - fprintf(stderr, "Couldn't open %s\n", devname2);
77 - goto get_ip_address;
79 - if ((fd = open(fulldevpath, O_RDWR)) < 0) {
80 - fprintf(stderr, "Couldn't open %s\n", fulldevpath);
82 - goto get_ip_address;
90 - /* Use the dlcommon functions to get access to the DLPI information for this
91 - * interface. All of these functions exit() out on failure
94 - dlp = (union DL_primitives*) buf;
97 - * DLPI attach to our low-level device
100 - dlattachreq(fd, unit_num);
107 - dlbindreq(fd, sap, 0, DL_CLDLS, 0, 0);
108 - dlbindack(fd, buf);
115 - dlinfoack(fd, buf);
118 - printdlprim(dlp); // uncomment this to dump out info from DLPI
121 - if (dlp->info_ack.dl_addr_length + dlp->info_ack.dl_sap_length == 6) {
123 - OFFADDR(dlp, dlp->info_ack.dl_addr_offset),
124 - dlp->info_ack.dl_addr_length);
127 - fprintf(stderr, "Error, bad length for hardware interface %s -- %d\n",
129 - dlp->info_ack.dl_addr_length);
136 /* Get the IP address of the interface */