[uClibc-cvs] uClibc/libc/inet addr.c,1.13,1.14 inet_net.c,1.3,1.4

Erik Andersen andersen at uclibc.org
Wed Oct 8 19:35:22 UTC 2003


Update of /var/cvs/uClibc/libc/inet
In directory winder:/tmp/cvs-serv31749/libc/inet

Modified Files:
	addr.c inet_net.c 
Log Message:
Atsushi Nemoto writes:

I found inappropriate data types are used in some places in networking
codes.

* tcp_seq is 32bit (u_long -> u_int32_t)
* in_addt_t should be used for internet address (unsigned long -> in_addr_t)
* socklen_t should be used for accept()

This is a patch against uclibc-0.9.21 (can be applied for current
CVS).  64bit platforms (sizeof(int)!=sizeof(long)) will need this.  I
believe this patch does not harm any 32bit platforms.



Index: inet_net.c
===================================================================
RCS file: /var/cvs/uClibc/libc/inet/inet_net.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- inet_net.c	21 Nov 2001 14:56:41 -0000	1.3
+++ inet_net.c	8 Oct 2003 19:35:16 -0000	1.4
@@ -42,12 +42,12 @@
  * The library routines call this routine to interpret
  * network numbers.
  */
-u_int32_t
+in_addr_t
 inet_network(const char *cp)
 {
-	register u_long val, base, n;
+	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:

Index: addr.c
===================================================================
RCS file: /var/cvs/uClibc/libc/inet/addr.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- addr.c	4 Aug 2003 19:03:33 -0000	1.13
+++ addr.c	8 Oct 2003 19:35:16 -0000	1.14
@@ -31,7 +31,7 @@
 const char *cp;
 struct in_addr *addrptr;
 {
-	unsigned long addr;
+	in_addr_t addr;
 	int value;
 	int part;
 
@@ -78,12 +78,12 @@
 #endif
 
 #ifdef L_inet_addr
-unsigned long inet_addr(const char *cp)
+in_addr_t inet_addr(const char *cp)
 {
 	struct in_addr a;
 
 	if (!inet_aton(cp, &a))
-		return -1;
+		return INADDR_NONE;
 	else
 		return a.s_addr;
 }
@@ -95,7 +95,7 @@
 
 char *inet_ntoa_r(struct in_addr in, char buf[INET_NTOA_MAX_LEN])
 {
-	unsigned long addr = ntohl(in.s_addr);
+	in_addr_t addr = ntohl(in.s_addr);
 	int i;
 	char *p, *q;
    
@@ -125,15 +125,15 @@
  * Formulate an Internet address from network + host.  Used in
  * building addresses stored in the ifnet structure.
  */
-struct in_addr inet_makeaddr(unsigned long net, unsigned long host)
+struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host)
 {
-        unsigned long addr;
+        in_addr_t addr;
 
         if (net < 128)
                 addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
         else if (net < 65536)
                 addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
-        else if (net < 16777216L)
+        else if (net < 16777216UL)
                 addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
         else
                 addr = net | host;
@@ -149,9 +149,9 @@
  * internet address; handles class a/b/c network
  * number formats.
  */
-unsigned long inet_lnaof(struct in_addr in)
+in_addr_t inet_lnaof(struct in_addr in)
 {
-	unsigned long i = ntohl(in.s_addr);
+	in_addr_t i = ntohl(in.s_addr);
 
 	if (IN_CLASSA(i))
 		return ((i)&IN_CLASSA_HOST);
@@ -168,10 +168,10 @@
  * Return the network number from an internet
  * address; handles class a/b/c network #'s.
  */
-u_int32_t
+in_addr_t
 inet_netof(struct in_addr in)
 {
-        u_int32_t i = ntohl(in.s_addr);
+        in_addr_t i = ntohl(in.s_addr);
 
         if (IN_CLASSA(i))
                 return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);




More information about the uClibc-cvs mailing list