--- a/jdk/src/solaris/native/java/net/NetworkInterface.c Tue Sep 20 12:40:23 2011 +0800
+++ b/jdk/src/solaris/native/java/net/NetworkInterface.c Wed Sep 21 14:51:01 2011 +0100
@@ -139,8 +139,12 @@
#ifdef __solaris__
static netif *enumIPvXInterfaces(JNIEnv *env, int sock, netif *ifs, int family);
static int getMacFromDevice(JNIEnv *env, const char* ifname, unsigned char* retbuf);
+
+#ifndef SIOCGLIFHWADDR
+#define SIOCGLIFHWADDR _IOWR('i', 192, struct lifreq)
#endif
+#endif
/******************* Java entry points *****************************/
@@ -1567,6 +1571,20 @@
struct sockaddr_in* sin;
struct sockaddr_in ipAddr;
int len, i;
+ struct lifreq lif;
+
+ /* First, try the new (S11) SIOCGLIFHWADDR ioctl(). If that fails
+ * try the old way.
+ */
+ memset(&lif, 0, sizeof(lif));
+ strlcpy(lif.lifr_name, ifname, sizeof(lif.lifr_name));
+
+ if (ioctl(sock, SIOCGLIFHWADDR, &lif) != -1) {
+ struct sockaddr_dl *sp;
+ sp = (struct sockaddr_dl *)&lif.lifr_addr;
+ memcpy(buf, &sp->sdl_data[0], sp->sdl_alen);
+ return sp->sdl_alen;
+ }
/**
* On Solaris we have to use DLPI, but it will only work if we have
@@ -1576,34 +1594,29 @@
if ((len = getMacFromDevice(env, ifname, buf)) == 0) {
/*DLPI failed - trying to do arp lookup*/
- if (addr == NULL) {
- /**
- * No IPv4 address for that interface, so can't do an ARP lookup.
- */
- return -1;
- }
+ if (addr == NULL) {
+ /**
+ * No IPv4 address for that interface, so can't do an ARP lookup.
+ */
+ return -1;
+ }
- len = 6; //???
+ len = 6; //???
- sin = (struct sockaddr_in *) &arpreq.arp_pa;
- memset((char *) &arpreq, 0, sizeof(struct arpreq));
- ipAddr.sin_port = 0;
- ipAddr.sin_family = AF_INET;
- memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr));
- memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in));
- arpreq.arp_flags= ATF_PUBL;
+ sin = (struct sockaddr_in *) &arpreq.arp_pa;
+ memset((char *) &arpreq, 0, sizeof(struct arpreq));
+ ipAddr.sin_port = 0;
+ ipAddr.sin_family = AF_INET;
+ memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr));
+ memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in));
+ arpreq.arp_flags= ATF_PUBL;
- if (ioctl(sock, SIOCGARP, &arpreq) < 0) {
- if (errno != ENXIO) {
- // "No such device or address" means no hardware address, so it's
- // normal don't throw an exception
- NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL failed");
- return -1;
- }
- }
+ if (ioctl(sock, SIOCGARP, &arpreq) < 0) {
+ return -1;
+ }
- memcpy(buf, &arpreq.arp_ha.sa_data[0], len );
- }
+ memcpy(buf, &arpreq.arp_ha.sa_data[0], len );
+ }
/*
* All bytes to 0 means no hardware address.