From 2895b8b5024af0b63eb4363ca3fb6e9a932994a1 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 3 Mar 2009 11:44:18 +0000 Subject: * 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. --- winsup/cygwin/net.cc | 72 ++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 33 deletions(-) (limited to 'winsup/cygwin/net.cc') diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 39f025aad..8ffc041b3 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -23,6 +23,7 @@ details. */ #include #undef gethostname #include +#include #define USE_SYS_TYPES_FD_SET #include #include @@ -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); +} -- cgit v1.2.3