Subject: bin/24862: use socklen_t in talk(1)
To: None <gnats-bugs@gnats.NetBSD.org>
From: Peter Postma <peter@pointless.nl>
List: netbsd-bugs
Date: 03/20/2004 17:39:27
>Number:         24862
>Category:       bin
>Synopsis:       use socklen_t in talk(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 20 16:40:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Peter Postma
>Release:        NetBSD 1.6ZK
>Organization:
>Environment:
System: NetBSD mercury.pointless.nl 1.6ZK NetBSD 1.6ZK (mercury) #27: Sat Mar 13 14:35:22 CET 2004 peter@mercury.pointless.nl:/usr/obj/sys/arch/sparc64/compile/mercury sparc64
Architecture: sparc64
Machine: sparc64
>Description:
	From Andrey Matveev via OpenBSD:

	- for storage of lengths of structures of addresses of
	  sockets we use type socklen_t instead of int
	  (and suppress pointer signedness warn's when compile
	  with CFLAGS+=-pedantic);

	- correct check on socket() failure (in case of error
	  socket() returns `-1', otherwise the the return value
	  is non-negative number).

>How-To-Repeat:
>Fix:

Index: ctl.c
===================================================================
RCS file: /cvsroot/src/usr.bin/talk/ctl.c,v
retrieving revision 1.6
diff -u -r1.6 ctl.c
--- ctl.c	7 Aug 2003 11:16:03 -0000	1.6
+++ ctl.c	20 Mar 2004 16:35:51 -0000
@@ -66,7 +66,7 @@
 void
 open_sockt()
 {
-	int length;
+	socklen_t length;
 
 	
 	(void)memset(&my_addr, 0, sizeof(my_addr));
@@ -77,7 +77,7 @@
 	my_addr.sin_addr = my_machine_addr;
 	my_addr.sin_port = 0;
 	sockt = socket(AF_INET, SOCK_STREAM, 0);
-	if (sockt <= 0)
+	if (sockt == -1)
 		p_error("Bad socket");
 	if (bind(sockt, (struct sockaddr *)&my_addr, sizeof(my_addr)) != 0)
 		p_error("Binding local socket");
@@ -90,7 +90,7 @@
 void
 open_ctl() 
 {
-	int length;
+	socklen_t length;
 
 	(void)memset(&ctl_addr, 0, sizeof(ctl_addr));
 	ctl_addr.sin_family = AF_INET;
@@ -100,7 +100,7 @@
 	ctl_addr.sin_port = 0;
 	ctl_addr.sin_addr = my_machine_addr;
 	ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
-	if (ctl_sockt <= 0)
+	if (ctl_sockt == -1)
 		p_error("Bad socket");
 	if (bind(ctl_sockt,
 	    (struct sockaddr *)&ctl_addr, sizeof(ctl_addr)) != 0)
>Release-Note:
>Audit-Trail:
>Unformatted: