--- old/usr/src/common/iscsit/iscsit_common.c	2012-09-26 12:51:34.468574842 +0000
+++ new/usr/src/common/iscsit/iscsit_common.c	2012-09-26 12:51:33.617612888 +0000
@@ -21,6 +21,9 @@
 /*
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  */
+/*
+ * Copyright (c) 2012, Nexenta Systems, Inc. All rights reserved.
+ */
 
 #include <sys/time.h>
 
@@ -30,6 +33,7 @@
 #include <sys/sunddi.h>
 #include <sys/socket.h>
 #include <inet/tcp.h>
+#include <inet/ip.h>
 #else
 #include <stdio.h>
 #include <strings.h>
@@ -161,14 +165,6 @@
 		    (void *)&(sin->sin_addr.s_addr)) != 1) {
 			return (NULL);
 		}
-		/*
-		 * intet_pton does not seem to convert to network
-		 * order in kernel. This is a workaround until the
-		 * inet_pton works or we have our own inet_pton function.
-		 */
-#ifdef _KERNEL
-		sin->sin_addr.s_addr = ntohl((uint32_t)sin->sin_addr.s_addr);
-#endif
 		sin->sin_port = htons(tmp_port);
 	} else {
 		sin6 = (struct sockaddr_in6 *)sa;
--- old/usr/src/uts/common/fs/nfs/nfs4_srv_deleg.c	2012-09-26 12:51:36.659810453 +0000
+++ new/usr/src/uts/common/fs/nfs/nfs4_srv_deleg.c	2012-09-26 12:51:35.392463766 +0000
@@ -22,6 +22,9 @@
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
+/*
+ * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
+ */
 
 #include <sys/systm.h>
 #include <rpc/auth.h>
@@ -117,23 +120,7 @@
 				}
 				port += c;
 
-
-				/* reset to network order */
-				if (af == AF_INET) {
-					*(uint32_t *)ap =
-					    htonl(*(uint32_t *)ap);
-					*pp = htons(port);
-				} else {
-					int ix;
-					uint16_t *sap;
-
-					for (sap = ap, ix = 0; ix <
-					    sizeof (struct in6_addr) /
-					    sizeof (uint16_t); ix++)
-						sap[ix] = htons(sap[ix]);
-
-					*pp = htons(port);
-				}
+				*pp = htons(port);
 
 				ua[k] = '.';
 				return (0);
--- old/usr/src/uts/common/fs/sockfs/nl7c.c	2012-09-26 12:51:40.044597493 +0000
+++ new/usr/src/uts/common/fs/sockfs/nl7c.c	2012-09-26 12:51:38.319792317 +0000
@@ -22,6 +22,9 @@
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
+/*
+ * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
+ */
 
 /*
  * NL7C (Network Layer 7 Cache) as part of SOCKFS provides an in-kernel
@@ -60,6 +63,7 @@
 #include <inet/nca/ncadoorhdr.h>
 #include <inet/nca/ncalogd.h>
 #include <inet/nca/ncandd.h>
+#include <inet/ip.h>
 
 #include <sys/promif.h>
 
@@ -76,9 +80,6 @@
 /*
  * Some externs:
  */
-
-extern int	inet_pton(int, char *, void *);
-
 extern void	nl7c_uri_init(void);
 extern boolean_t nl7c_logd_init(int, caddr_t *);
 extern void	nl7c_nca_init(void);
@@ -332,8 +333,8 @@
 		p->family = AF_INET6;
 	} else {
 		p->family = AF_INET;
-		p->addr.v4 = ntohl(p->addr.v4);
 	}
+
 	return (0);
 }
 
--- old/usr/src/uts/common/inet/ip.h	2012-09-26 12:51:42.807417288 +0000
+++ new/usr/src/uts/common/inet/ip.h	2012-09-26 12:51:41.256743992 +0000
@@ -23,6 +23,9 @@
  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 1990 Mentat Inc.
  */
+/*
+ * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
+ */
 
 #ifndef	_INET_IP_H
 #define	_INET_IP_H
@@ -3698,6 +3701,10 @@
 extern mblk_t	*ip_recv_attr_free_mblk(mblk_t *);
 extern boolean_t ip_recv_attr_is_mblk(mblk_t *);
 
+extern char	*inet_ntop(int, const void *, char *, int);
+extern int	_inet_pton(int, char *, void *);
+#define	inet_pton(x, y, z)	_inet_pton(x, y, z)
+
 /*
  * Squeue tags. Tags only need to be unique when the callback function is the
  * same to distinguish between different calls, but we use unique tags for
--- old/usr/src/uts/common/inet/ip/inet_ntop.c	2012-09-26 12:51:45.924618132 +0000
+++ new/usr/src/uts/common/inet/ip/inet_ntop.c	2012-09-26 12:51:44.759663909 +0000
@@ -23,8 +23,9 @@
  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
-
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
+/*
+ * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
+ */
 
 #include <sys/types.h>
 #include <sys/cmn_err.h>
@@ -233,14 +234,16 @@
 	char *end;
 	long byte;
 	int i;
-	ipaddr_t addr = 0;
+	uint8_t *addr = (uint8_t *)addrp;
+
+	*addrp = 0;
 
 	for (i = 0; i < 4; i++) {
 		if (ddi_strtol(cp, &end, 10, &byte) != 0 || byte < 0 ||
 		    byte > 255) {
 			return (0);
 		}
-		addr = (addr << 8) | (uint8_t)byte;
+		addr[i] = (uint8_t)byte;
 		if (i < 3) {
 			if (*end != '.') {
 				return (0);
@@ -251,7 +254,7 @@
 			cp = end;
 		}
 	}
-	*addrp = addr;
+
 	return (1);
 }
 
@@ -264,7 +267,7 @@
  *            -1 when af is not AF_INET or AF_INET6
  */
 int
-inet_pton(int af, char *inp, void *outp)
+m_inet_pton(int af, char *inp, void *outp, int revert)
 {
 	int i;
 	long byte;
@@ -272,7 +275,13 @@
 
 	switch (af) {
 	case AF_INET:
-		return (str2inet_addr(inp, (ipaddr_t *)outp));
+		if (str2inet_addr(inp, (ipaddr_t *)outp)) {
+			if (! revert)
+				*(uint32_t *)outp = ntohl(*(uint32_t *)outp);
+			return (1);
+		} else {
+			return (0);
+		}
 	case AF_INET6: {
 		union v6buf_u {
 			uint16_t v6words_u[8];
@@ -316,7 +325,11 @@
 			if (byte < 0 || byte > 0x0ffff) {
 				return (0);
 			}
-			v6buf.v6words_u[i] = (uint16_t)byte;
+			if (revert) {
+				v6buf.v6words_u[i] = htons((uint16_t)byte);
+			} else {
+				v6buf.v6words_u[i] = (uint16_t)byte;
+			}
 			if (*end == NULL || i == 7) {
 				inp = end;
 				break;
@@ -388,3 +401,24 @@
 	}	/* switch */
 	return (-1);	/* return -1 for default case */
 }
+
+
+int
+_inet_pton(int af, char *inp, void *outp)
+{
+	return (m_inet_pton(af, inp, outp, 1));
+}
+
+/*
+ * We need this inet_pton to preserve compatibility with old closed binaries.
+ * Earlier, inet_pton returned address in hardware native order,
+ * not in network one. (See http://www.illumos.org/issue/3105).
+ * Having fixed that, we still need to support binaries, that use bad inet_pton
+ * and reverse returned address manually. All new inet_pton calls will be
+ * redirected to _inet_pton with #define in the header file.
+ */
+int
+inet_pton(int af, char *inp, void *outp)
+{
+	return (m_inet_pton(af, inp, outp, 0));
+}
--- old/usr/src/uts/common/inet/ip6.h	2012-09-26 12:51:47.930519611 +0000
+++ new/usr/src/uts/common/inet/ip6.h	2012-09-26 12:51:46.749548410 +0000
@@ -22,6 +22,9 @@
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
+/*
+ * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
+ */
 
 #ifndef	_INET_IP6_H
 #define	_INET_IP6_H
@@ -226,8 +229,6 @@
  */
 
 extern void	convert2ascii(char *buf, const in6_addr_t *addr);
-extern char	*inet_ntop(int, const void *, char *, int);
-extern int	inet_pton(int, char *, void *);
 extern void	icmp_param_problem_nexthdr_v6(mblk_t *, boolean_t,
     ip_recv_attr_t *);
 extern void	icmp_pkt2big_v6(mblk_t *, uint32_t, boolean_t,
--- old/usr/src/uts/common/io/scsi/adapters/iscsi/iscsi.h	2012-09-26 12:51:49.924022653 +0000
+++ new/usr/src/uts/common/io/scsi/adapters/iscsi/iscsi.h	2012-09-26 12:51:48.829316876 +0000
@@ -21,6 +21,7 @@
 /*
  * Copyright 2000 by Cisco Systems, Inc.  All rights reserved.
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
  */
 
 #ifndef _ISCSI_H
@@ -54,6 +55,7 @@
 #include <sys/idm/idm.h>
 #include <sys/idm/idm_conn_sm.h>
 #include <nvfile.h>
+#include <inet/ip.h>
 
 #ifndef MIN
 #define	MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -1403,12 +1405,6 @@
 
 extern void bcopy(const void *s1, void *s2, size_t n);
 extern void bzero(void *s, size_t n);
-/*
- * Here we need a contract for inet_ntop() and inet_pton()
- * in uts/common/inet/ip/inet_ntop.c
- */
-extern char *inet_ntop(int af, const void *addr, char *buf, int addrlen);
-extern int inet_pton(int af, char *inp, void *outp);
 
 #ifdef __cplusplus
 }
--- old/usr/src/uts/common/io/scsi/adapters/iscsi/iscsi_doorclt.c	2012-09-26 12:51:51.984810681 +0000
+++ new/usr/src/uts/common/io/scsi/adapters/iscsi/iscsi_doorclt.c	2012-09-26 12:51:50.856268955 +0000
@@ -22,6 +22,7 @@
  * Copyright 2000 by Cisco Systems, Inc.  All rights reserved.
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
  *
  * iSCSI Software Initiator
  */
@@ -243,8 +244,6 @@
 	getipnodebyname_req_t	*req;
 	getipnodebyname_cnf_t	*cnf;
 	struct hostent		*hptr;
-	int			i;
-	uint16_t		*swap;
 
 
 	buffer_size = msg_size + hostent_size + sizeof (mybuffer_t);
@@ -312,17 +311,7 @@
 		if (inet_pton(af, (char *)name, cnf) == 1) {
 			/*
 			 * inet_pton converted the string successfully.
-			 * reset to network order.  swaps based on nfs code
 			 */
-			if (af == AF_INET) {
-				*((uint32_t *)cnf) = htonl(*((uint32_t *)cnf));
-			} else {
-				for (swap = ((void *)cnf), i = 0;
-				    i < hptr->h_length / sizeof (uint16_t);
-				    i++) {
-					swap[i] = htons(swap[i]);
-				}
-			}
 			hptr->h_addrtype = af;
 			hptr->h_addr_list = (char **)((char *)hptr +
 			    sizeof (struct hostent));
