Messages in this thread Patch in this message | | | Date | Sun, 12 Sep 1999 00:06:34 +0200 | From | Jakub Jelinek <> | Subject | [PATCH] ntohl/htonl prototype in kernel headers |
| |
Hi!
As glibc prototypes ntohl/htonl as returning uint32_t and taking the same argument while the kernel declares them still as returning/taking unsigned long, once cannot mix e.g. netinet/in.h and linux/capability.h (the latter indirectly sources in linux/byteorder/generic.h) which is bad. The following patch makes the kernel ntohl/htonl work on __u32 and declares the same prototype for userland with glibc 2.0+. For libc5 it keeps the commonly used definition. Are there any objections? This patch should apply cleanly against linux 2.2.12 and 2.3.18. BTW: Solaris 7 declares ntohl/htonl as 32bit, while Irix 6.5 declares it to unsigned long, so apparently other Unices don't agree on it either.
--- include/linux/byteorder/generic.h.jj Wed Jul 28 13:33:14 1999 +++ include/linux/byteorder/generic.h Sat Sep 11 23:36:09 1999 @@ -129,7 +129,7 @@ * also have a macro for them in case some strange program * wants to take the address of the thing or something.. * - * Note that these traditionally return a "long", even though + * Note that these used to return a "long" in libc5, even though * long is often 64-bit these days.. Thus the casts. * * They have to be macros in order to do the constant folding @@ -146,9 +146,14 @@ * Do the prototypes. Somebody might want to take the * address or some such sick thing.. */ +#if defined(__KERNEL__) || (defined (__GLIBC__) && __GLIBC__ >= 2) +extern __u32 ntohl(__u32); +extern __u32 htonl(__u32); +#else extern unsigned long int ntohl(unsigned long int); -extern unsigned short int ntohs(unsigned short int); extern unsigned long int htonl(unsigned long int); +#endif +extern unsigned short int ntohs(unsigned short int); extern unsigned short int htons(unsigned short int); @@ -159,9 +164,14 @@ extern unsigned short int htons(unsigned #define ___ntohl(x) __be32_to_cpu(x) #define ___ntohs(x) __be16_to_cpu(x) +#if defined(__KERNEL__) || (defined (__GLIBC__) && __GLIBC__ >= 2) +#define htonl(x) ___htonl(x) +#define ntohl(x) ___ntohl(x) +#else #define htonl(x) ((unsigned long)___htonl(x)) -#define htons(x) ___htons(x) #define ntohl(x) ((unsigned long)___ntohl(x)) +#endif +#define htons(x) ___htons(x) #define ntohs(x) ___ntohs(x) #endif /* OPTIMIZE */ Cheers, Jakub ___________________________________________________________________ Jakub Jelinek | jj@sunsite.mff.cuni.cz | http://sunsite.mff.cuni.cz Administrator of SunSITE Czech Republic, MFF, Charles University ___________________________________________________________________ UltraLinux | http://ultra.linux.cz/ | http://ultra.penguin.cz/ Linux version 2.3.18 on a sparc64 machine (1343.49 BogoMips) ___________________________________________________________________ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |