aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-03-03 11:44:18 +0000
committerCorinna Vinschen <corinna@vinschen.de>2009-03-03 11:44:18 +0000
commit2895b8b5024af0b63eb4363ca3fb6e9a932994a1 (patch)
tree26f89ba25493b6e8405fcd15c00dc2e386dce8fa
parented296a47279daf8af30812a6084ab4839c3d879d (diff)
downloadnewlib-2895b8b5024af0b63eb4363ca3fb6e9a932994a1.zip
newlib-2895b8b5024af0b63eb4363ca3fb6e9a932994a1.tar.gz
newlib-2895b8b5024af0b63eb4363ca3fb6e9a932994a1.tar.bz2
* net.cc: Include asm/byteorder.h.
(htonl): Move to end of file. Add comment to explain why. Align definition to POSIX. Use related macro from asm/byteorder.h. (ntohl): Ditto. (htons): Ditto. (ntohs): Ditto. * include/asm/byteorder.h: Revert previous patch.
-rw-r--r--winsup/cygwin/ChangeLog10
-rw-r--r--winsup/cygwin/include/asm/byteorder.h3
-rw-r--r--winsup/cygwin/net.cc72
3 files changed, 50 insertions, 35 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 6698f1c..51ea715 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,15 @@
2009-03-03 Corinna Vinschen <corinna@vinschen.de>
+ * net.cc: Include asm/byteorder.h.
+ (htonl): Move to end of file. Add comment to explain why. Align
+ definition to POSIX. Use related macro from asm/byteorder.h.
+ (ntohl): Ditto.
+ (htons): Ditto.
+ (ntohs): Ditto.
+ * include/asm/byteorder.h: Revert previous patch.
+
+2009-03-03 Corinna Vinschen <corinna@vinschen.de>
+
* include/asm/byteorder.h: Disable optimization when building
Cygwin network code.
diff --git a/winsup/cygwin/include/asm/byteorder.h b/winsup/cygwin/include/asm/byteorder.h
index 3f59f70..b656f81 100644
--- a/winsup/cygwin/include/asm/byteorder.h
+++ b/winsup/cygwin/include/asm/byteorder.h
@@ -70,8 +70,7 @@ __ntohs(uint16_t x)
#define __constant_htonl(x) __constant_ntohl(x)
#define __constant_htons(x) __constant_ntohs(x)
-#if defined (__OPTIMIZE__) && !defined (__NO_INLINE__) \
- && !defined (__INSIDE_CYGWIN_NET__)
+#if defined (__OPTIMIZE__) && !defined (__NO_INLINE__)
# define ntohl(x) \
(__builtin_constant_p((long)(x)) ? \
__constant_ntohl((x)) : \
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 39f025a..8ffc041 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -23,6 +23,7 @@ details. */
#include <unistd.h>
#undef gethostname
#include <netdb.h>
+#include <asm/byteorder.h>
#define USE_SYS_TYPES_FD_SET
#include <winsock2.h>
#include <iphlpapi.h>
@@ -73,38 +74,6 @@ get (const int fd)
return fh;
}
-/* htonl: standards? */
-extern "C" unsigned long int
-htonl (unsigned long int x)
-{
- return ((((x & 0x000000ffU) << 24) |
- ((x & 0x0000ff00U) << 8) |
- ((x & 0x00ff0000U) >> 8) |
- ((x & 0xff000000U) >> 24)));
-}
-
-/* ntohl: standards? */
-extern "C" unsigned long int
-ntohl (unsigned long int x)
-{
- return htonl (x);
-}
-
-/* htons: standards? */
-extern "C" unsigned short
-htons (unsigned short x)
-{
- return ((((x & 0x000000ffU) << 8) |
- ((x & 0x0000ff00U) >> 8)));
-}
-
-/* ntohs: standards? */
-extern "C" unsigned short
-ntohs (unsigned short x)
-{
- return htons (x);
-}
-
/* exported as inet_ntoa: BSD 4.3 */
extern "C" char *
cygwin_inet_ntoa (struct in_addr in)
@@ -4019,7 +3988,8 @@ cygwin_getnameinfo (const struct sockaddr *sa, socklen_t salen,
return ret;
}
-/* The below function has been taken from OpenBSD's src/sys/netinet6/in6.c. */
+/* The below function in6_are_prefix_equal has been taken from OpenBSD's
+ src/sys/netinet6/in6.c. */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -4103,3 +4073,39 @@ in6_are_prefix_equal (struct in6_addr *p1, struct in6_addr *p2, int len)
return 1;
}
+
+/* These functions are stick to the end of this file so that the
+ optimization in asm/byteorder.h can be used even here in net.cc. */
+
+#undef htonl
+#undef ntohl
+#undef htons
+#undef ntohs
+
+/* htonl: standards? */
+extern "C" uint32_t
+htonl (uint32_t x)
+{
+ return __htonl (x);
+}
+
+/* ntohl: standards? */
+extern "C" uint32_t
+ntohl (uint32_t x)
+{
+ return __ntohl (x);
+}
+
+/* htons: standards? */
+extern "C" uint16_t
+htons (uint16_t x)
+{
+ return __htons (x);
+}
+
+/* ntohs: standards? */
+extern "C" uint16_t
+ntohs (uint16_t x)
+{
+ return __ntohs (x);
+}