diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-10-08 19:35:20 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-10-08 19:35:20 +0000 |
commit | abd02d7387069439373d40c2f9afba93c76df650 (patch) | |
tree | b9d78f9594b542bcdcec04bf6b02b2b726224ddd /libc | |
parent | 027d12aeef4386c638f73a4df7171a5d027604f4 (diff) |
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.
Diffstat (limited to 'libc')
-rw-r--r-- | libc/inet/addr.c | 22 | ||||
-rw-r--r-- | libc/inet/inet_net.c | 6 | ||||
-rw-r--r-- | libc/inet/rpc/rcmd.c | 4 | ||||
-rw-r--r-- | libc/inet/rpc/rexec.c | 2 |
4 files changed, 17 insertions, 17 deletions
diff --git a/libc/inet/addr.c b/libc/inet/addr.c index b4f8c9b87..a75916e69 100644 --- a/libc/inet/addr.c +++ b/libc/inet/addr.c @@ -31,7 +31,7 @@ int inet_aton(cp, addrptr) const char *cp; struct in_addr *addrptr; { - unsigned long addr; + in_addr_t addr; int value; int part; @@ -78,12 +78,12 @@ struct in_addr *addrptr; #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 @@ unsigned long inet_addr(const char *cp) 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 @@ char *inet_ntoa(struct in_addr in) * 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 @@ struct in_addr inet_makeaddr(unsigned long net, unsigned long host) * 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 @@ unsigned long inet_lnaof(struct in_addr in) * 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); diff --git a/libc/inet/inet_net.c b/libc/inet/inet_net.c index b49a4b92d..74fa390ac 100644 --- a/libc/inet/inet_net.c +++ b/libc/inet/inet_net.c @@ -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: diff --git a/libc/inet/rpc/rcmd.c b/libc/inet/rpc/rcmd.c index 618a6f1b2..f1c732d41 100644 --- a/libc/inet/rpc/rcmd.c +++ b/libc/inet/rpc/rcmd.c @@ -192,7 +192,7 @@ int rcmd(ahost, rport, locuser, remuser, cmd, fd2p) } else { char num[8]; int s2 = rresvport(&lport), s3; - size_t len = sizeof(from); + socklen_t len = sizeof(from); if (s2 < 0) goto bad; @@ -541,7 +541,7 @@ __icheckhost (u_int32_t raddr, char *lhost, const char *rhost) } /* Try for raw ip address first. */ - if (isdigit (*lhost) && (long) (laddr = inet_addr (lhost)) != -1) + if (isdigit (*lhost) && (laddr = inet_addr (lhost)) != INADDR_NONE) return negate * (! (raddr ^ laddr)); /* Better be a hostname. */ diff --git a/libc/inet/rpc/rexec.c b/libc/inet/rpc/rexec.c index a084ccde7..7af948991 100644 --- a/libc/inet/rpc/rexec.c +++ b/libc/inet/rpc/rexec.c @@ -135,7 +135,7 @@ retry: port = atoi(servbuff); (void) sprintf(num, "%u", port); (void) write(s, num, strlen(num)+1); - { int len = sizeof (from); + { socklen_t len = sizeof (from); s3 = accept(s2, (struct sockaddr *)&from, &len); close(s2); if (s3 < 0) { |