Date: Thu, 15 Mar 2001 01:53:16 +0900 (JST) From: Hajimu UMEMOTO <ume@FreeBSD.org> To: alpha@FreeBSD.org, net@FreeBSD.org Subject: IPv4 address is not unsigned int Message-ID: <20010315.015316.85344842.ume@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
----Next_Part(Thu_Mar_15_01:53:16_2001_677)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, I wish to close PR 9982. This PR suggests that IPv4 address is not unsigned int and fix it to 32bit long. So, I took in_addr_t changes from OpenBSD and made a patch. It may break binary compatibility on Alpha, where u_long is 64 bits but in_addr_t would still be 32 bits. It seems working well on my *Pentium* box. However, I have no 64 bits environment. Please review the changes. ----Next_Part(Thu_Mar_15_01:53:16_2001_677)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Description: in_addr_t.diff Content-Disposition: inline; filename="in_addr_t.diff" Index: include/arpa/inet.h =================================================================== RCS file: /home/ncvs/src/include/arpa/inet.h,v retrieving revision 1.11 diff -u -r1.11 inet.h --- include/arpa/inet.h 1999/08/27 23:45:00 1.11 +++ include/arpa/inet.h 2001/03/13 12:41:29 @@ -84,13 +84,13 @@ __BEGIN_DECLS int ascii2addr __P((int, const char *, void *)); char *addr2ascii __P((int, const void *, int, char *)); -unsigned long inet_addr __P((const char *)); +in_addr_t inet_addr __P((const char *)); int inet_aton __P((const char *, struct in_addr *)); -unsigned long inet_lnaof __P((struct in_addr)); -struct in_addr inet_makeaddr __P((u_long , u_long)); -char * inet_neta __P((u_long, char *, size_t)); -unsigned long inet_netof __P((struct in_addr)); -unsigned long inet_network __P((const char *)); +in_addr_t inet_lnaof __P((struct in_addr)); +struct in_addr inet_makeaddr __P((in_addr_t, in_addr_t)); +char * inet_neta __P((in_addr_t, char *, size_t)); +in_addr_t inet_netof __P((struct in_addr)); +in_addr_t inet_network __P((const char *)); char *inet_net_ntop __P((int, const void *, int, char *, size_t)); int inet_net_pton __P((int, const char *, void *, size_t)); char *inet_ntoa __P((struct in_addr)); Index: lib/libc/net/inet.3 =================================================================== RCS file: /home/ncvs/src/lib/libc/net/inet.3,v retrieving revision 1.11 diff -u -r1.11 inet.3 --- lib/libc/net/inet.3 2000/12/29 14:08:00 1.11 +++ lib/libc/net/inet.3 2001/03/13 12:41:29 @@ -55,9 +55,9 @@ .Fd #include <arpa/inet.h> .Ft int .Fn inet_aton "const char *cp" "struct in_addr *pin" -.Ft unsigned long +.Ft in_addr_t .Fn inet_addr "const char *cp" -.Ft unsigned long +.Ft in_addr_t .Fn inet_network "const char *cp" .Ft char * .Fn inet_ntoa "struct in_addr in" @@ -66,10 +66,10 @@ .Ft int .Fn inet_pton "int af" "const char *src" "void *dst" .Ft struct in_addr -.Fn inet_makeaddr "unsigned long net" "unsigned long lna" -.Ft unsigned long +.Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" +.Ft in_addr_t .Fn inet_lnaof "struct in_addr in" -.Ft unsigned long +.Ft in_addr_t .Fn inet_netof "struct in_addr in" .Sh DESCRIPTION The routines Index: lib/libc/net/inet_addr.c =================================================================== RCS file: /home/ncvs/src/lib/libc/net/inet_addr.c,v retrieving revision 1.12 diff -u -r1.12 inet_addr.c --- lib/libc/net/inet_addr.c 1999/12/27 08:40:40 1.12 +++ lib/libc/net/inet_addr.c 2001/03/13 12:41:29 @@ -72,7 +72,7 @@ * ASCII internet address interpretation routine. * The value returned is in network order. */ -u_long /* XXX should be struct in_addr :( */ +in_addr_t /* XXX should be struct in_addr :( */ inet_addr(cp) register const char *cp; { @@ -96,7 +96,7 @@ struct in_addr *addr; { u_long parts[4]; - u_long val; + in_addr_t val; char *c; char *endptr; int gotend, n; Index: lib/libc/net/inet_lnaof.c =================================================================== RCS file: /home/ncvs/src/lib/libc/net/inet_lnaof.c,v retrieving revision 1.2 diff -u -r1.2 inet_lnaof.c --- lib/libc/net/inet_lnaof.c 1998/09/02 00:53:16 1.2 +++ lib/libc/net/inet_lnaof.c 2001/03/13 12:41:29 @@ -44,11 +44,11 @@ * internet address; handles class a/b/c network * number formats. */ -u_long +in_addr_t inet_lnaof(in) struct in_addr in; { - register u_long i = ntohl(in.s_addr); + register in_addr_t i = ntohl(in.s_addr); if (IN_CLASSA(i)) return ((i)&IN_CLASSA_HOST); Index: lib/libc/net/inet_makeaddr.c =================================================================== RCS file: /home/ncvs/src/lib/libc/net/inet_makeaddr.c,v retrieving revision 1.2 diff -u -r1.2 inet_makeaddr.c --- lib/libc/net/inet_makeaddr.c 1998/09/02 00:53:17 1.2 +++ lib/libc/net/inet_makeaddr.c 2001/03/13 12:41:29 @@ -45,9 +45,9 @@ */ struct in_addr inet_makeaddr(net, host) - u_long net, host; + in_addr_t net, host; { - u_long addr; + in_addr_t addr; if (net < 128) addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); Index: lib/libc/net/inet_neta.c =================================================================== RCS file: /home/ncvs/src/lib/libc/net/inet_neta.c,v retrieving revision 1.6 diff -u -r1.6 inet_neta.c --- lib/libc/net/inet_neta.c 1999/08/28 00:00:11 1.6 +++ lib/libc/net/inet_neta.c 2001/03/13 12:41:29 @@ -38,7 +38,7 @@ /* * char * * inet_neta(src, dst, size) - * format a u_long network number into presentation format. + * format a in_addr_t network number into presentation format. * return: * pointer to dst, or NULL if an error occurred (check errno). * note: @@ -48,7 +48,7 @@ */ char * inet_neta(src, dst, size) - u_long src; + in_addr_t src; char *dst; size_t size; { Index: lib/libc/net/inet_netof.c =================================================================== RCS file: /home/ncvs/src/lib/libc/net/inet_netof.c,v retrieving revision 1.2 diff -u -r1.2 inet_netof.c --- lib/libc/net/inet_netof.c 1998/09/02 00:53:17 1.2 +++ lib/libc/net/inet_netof.c 2001/03/13 12:41:29 @@ -43,11 +43,11 @@ * Return the network number from an internet * address; handles class a/b/c network #'s. */ -u_long +in_addr_t inet_netof(in) struct in_addr in; { - register u_long i = ntohl(in.s_addr); + register in_addr_t i = ntohl(in.s_addr); if (IN_CLASSA(i)) return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); Index: lib/libc/net/inet_network.c =================================================================== RCS file: /home/ncvs/src/lib/libc/net/inet_network.c,v retrieving revision 1.6 diff -u -r1.6 inet_network.c --- lib/libc/net/inet_network.c 1999/11/04 04:30:44 1.6 +++ lib/libc/net/inet_network.c 2001/03/13 12:41:29 @@ -47,13 +47,14 @@ * The library routines call this routine to interpret * network numbers. */ -u_long +in_addr_t inet_network(cp) register const char *cp; { - register u_long val, base, n, i; + register in_addr_t val, base, n; register char c; - u_long parts[4], *pp = parts; + in_addr_t parts[4], *pp = parts; + register int i; again: val = 0; base = 10; Index: sys/netinet/in.h =================================================================== RCS file: /home/ncvs/src/sys/netinet/in.h,v retrieving revision 1.53 diff -u -r1.53 in.h --- sys/netinet/in.h 2001/02/21 06:39:56 1.53 +++ sys/netinet/in.h 2001/03/13 12:41:29 @@ -232,7 +232,7 @@ * Internet address (a structure for historical reasons) */ struct in_addr { - u_int32_t s_addr; + in_addr_t s_addr; }; /* Index: sys/sys/types.h =================================================================== RCS file: /home/ncvs/src/sys/sys/types.h,v retrieving revision 1.41 diff -u -r1.41 types.h --- sys/sys/types.h 2000/10/27 11:45:49 1.41 +++ sys/sys/types.h 2001/03/13 12:41:30 @@ -73,6 +73,7 @@ typedef u_int32_t u_daddr_t; /* unsigned disk address */ typedef u_int32_t fixpt_t; /* fixed point number */ typedef u_int32_t gid_t; /* group id */ +typedef u_int32_t in_addr_t; /* base type for internet address */ typedef u_int32_t ino_t; /* inode number */ typedef long key_t; /* IPC key (for Sys V IPC) */ typedef u_int16_t mode_t; /* permissions */ ----Next_Part(Thu_Mar_15_01:53:16_2001_677)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Description: My Signature Content-Disposition: inline; filename=".signature-world" Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan ume@mahoroba.org ume@bisd.hitachi.co.jp ume@{,jp.}FreeBSD.org http://www.imasy.org/~ume/ ----Next_Part(Thu_Mar_15_01:53:16_2001_677)---- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010315.015316.85344842.ume>