[ds6-devel] nc6/src connection.c,1.6,1.7 filter.c,1.10,1.11 io_stream.c,1.5,1.6 main.c,1.7,1.8 network.c,1.16,1.17 parser.c,1.13,1.14readwrite.c,1.16,1.17

chris@deepspace6.net chris@deepspace6.net
Tue Dec 24 21:05:39 2002


Update of /cvs/nc6/src

Modified Files:
	connection.c filter.c io_stream.c main.c network.c parser.c 
	readwrite.c 
Log Message:
Reworked some lines to get below 80 chars


Index: connection.c
===================================================================
RCS file: /cvs/nc6/src/connection.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- connection.c	24 Dec 2002 19:50:56 -0000	1.6
+++ connection.c	24 Dec 2002 21:05:37 -0000	1.7
@@ -37,8 +37,10 @@
 	attrs->proto = PROTO_UNSPECIFIED;
 	attrs->type = TCP_SOCKET;
 
-	memset((void*)&(attrs->remote_address), 0, sizeof(attrs->remote_address));
-	memset((void*)&(attrs->local_address), 0, sizeof(attrs->local_address));
+	memset((void*)&(attrs->remote_address), 0,
+	       sizeof(attrs->remote_address));
+	memset((void*)&(attrs->local_address), 0,
+	       sizeof(attrs->local_address));
 
 	io_stream_init(&(attrs->remote_stream));
 	io_stream_init(&(attrs->local_stream));
@@ -86,16 +88,18 @@
 	switch (attrs->type) {
 		case UDP_SOCKET:
 			ainfo->ai_protocol = IPPROTO_UDP;
-			/* strictly speaking, this should not be required since UDP
-			 * implies a DGRAM type socket.  However, on some systems 
-			 * getaddrinfo fails if we set IPPROTO_UDP and don't set this */
+			/* strictly speaking, this should not be required
+			 * since UDP implies a DGRAM type socket.  However, on
+			 * some systems getaddrinfo fails if we set
+			 * IPPROTO_UDP and don't set this */
 			ainfo->ai_socktype = SOCK_DGRAM;
 			break;
 		case TCP_SOCKET:
 			ainfo->ai_protocol = IPPROTO_TCP;
-			/* strictly speaking, this should not be required since TCP
-			 * implies a STREAM type socket.  However, on some systems 
-			 * getaddrinfo fails if we set IPPROTO_TCP and don't set this */
+			/* strictly speaking, this should not be required
+			 * since TCP implies a STREAM type socket.  However,
+			 * on some systems getaddrinfo fails if we set
+			 * IPPROTO_TCP and don't set this */
 			ainfo->ai_socktype = SOCK_STREAM;
 			break;
 		default:
Index: filter.c
===================================================================
RCS file: /cvs/nc6/src/filter.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- filter.c	24 Dec 2002 19:50:56 -0000	1.10
+++ filter.c	24 Dec 2002 21:05:37 -0000	1.11
@@ -44,8 +44,11 @@
 	assert(a != NULL);
 	
 	if ((a->sa_family == AF_INET6) && 
-	    IN6_IS_ADDR_V4MAPPED(&(((const struct sockaddr_in6 *)a)->sin6_addr)))
+	    IN6_IS_ADDR_V4MAPPED(
+	        &(((const struct sockaddr_in6 *)a)->sin6_addr)))
+	{
 		ret = TRUE;
+	}
 			
 	return ret;
 }
@@ -71,10 +74,10 @@
 		ap = (struct sockaddr *)alloca(sizeof(struct sockaddr_in));
 		memset(ap, 0, sizeof(struct sockaddr_in));
 		memcpy(&(((struct sockaddr_in *)ap)->sin_addr.s_addr),
-		       &(((const struct sockaddr_in6 *)a)->sin6_addr.s6_addr[12]),
-		       sizeof(struct in_addr));
+		    &(((const struct sockaddr_in6 *)a)->sin6_addr.s6_addr[12]),
+		    sizeof(struct in_addr));
 		((struct sockaddr_in *)ap)->sin_port =
-			((const struct sockaddr_in6 *)a)->sin6_port;
+		    ((const struct sockaddr_in6 *)a)->sin6_port;
 		aa = ap;
 	}
 
@@ -83,10 +86,10 @@
 		bp = (struct sockaddr *)alloca(sizeof(struct sockaddr_in));
 		memset(bp, 0, sizeof(struct sockaddr_in));
 		memcpy(&(((struct sockaddr_in *)bp)->sin_addr.s_addr),
-		       &(((const struct sockaddr_in6 *)b)->sin6_addr.s6_addr[12]),
-		       sizeof(struct in_addr));
+		    &(((const struct sockaddr_in6 *)b)->sin6_addr.s6_addr[12]),
+		    sizeof(struct in_addr));
 		((struct sockaddr_in *)bp)->sin_port =
-			((const struct sockaddr_in6 *)b)->sin6_port;
+		    ((const struct sockaddr_in6 *)b)->sin6_port;
 		bb = bp;
 	}
 #endif
@@ -102,7 +105,7 @@
 #ifdef ENABLE_IPV6
 	if (aa->sa_family == AF_INET6) {
 		/* compare address part 
-		 * either address may be IN6ADDR_ANY, resulting in a good match */
+		 * either may be IN6ADDR_ANY, resulting in a good match */
 		if ((memcmp(&((const struct sockaddr_in6 *)aa)->sin6_addr,
 		            &in6addr_any, sizeof(struct in6_addr)) != 0) &&
 		    (memcmp(&((const struct sockaddr_in6 *)bb)->sin6_addr,
@@ -118,13 +121,14 @@
 		return ((((const struct sockaddr_in6 *)aa)->sin6_port == 0) ||
 		        (((const struct sockaddr_in6 *)bb)->sin6_port == 0) ||
 		        (((const struct sockaddr_in6 *)aa)->sin6_port ==
-		         ((const struct sockaddr_in6 *)bb)->sin6_port))? TRUE : FALSE;
+		         ((const struct sockaddr_in6 *)bb)->sin6_port))?
+		         TRUE : FALSE;
 	}
 #endif
 
 	if (aa->sa_family == AF_INET) { 
 		/* compare address part
-		 * either address may be INADDR_ANY, resulting in a good match */
+		 * either may be INADDR_ANY, resulting in a good match */
 		if ((((const struct sockaddr_in *)aa)->sin_addr.s_addr != INADDR_ANY) &&
 		    (((const struct sockaddr_in *)bb)->sin_addr.s_addr != INADDR_ANY) &&
 		    (((const struct sockaddr_in *)aa)->sin_addr.s_addr != 
@@ -137,7 +141,8 @@
 		return ((((const struct sockaddr_in *)aa)->sin_port == 0) ||
 		        (((const struct sockaddr_in *)bb)->sin_port == 0) ||
 		        (((const struct sockaddr_in *)aa)->sin_port == 
-		         ((const struct sockaddr_in *)bb)->sin_port))? TRUE : FALSE;
+		         ((const struct sockaddr_in *)bb)->sin_port))?
+		         TRUE : FALSE;
 	}
 	
 	/* for all other socket types, return false */
Index: io_stream.c
===================================================================
RCS file: /cvs/nc6/src/io_stream.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- io_stream.c	24 Dec 2002 20:20:31 -0000	1.5
+++ io_stream.c	24 Dec 2002 21:05:37 -0000	1.6
@@ -42,7 +42,7 @@
 
 	ios->fd_in = -1;
 	ios->fd_out = -1;
-	ios->socktype = 0; /* unknown */
+	ios->socktype = 0;  /* unknown */
 	ios->hold_time = 0; /* instant */
 	timerclear(&(ios->read_closed));
 }
@@ -85,7 +85,8 @@
 	/* nonblock(ios->fd_in); */
 	/* nonblock(ios->fd_out); */
 
-	ios->socktype = SOCK_STREAM;   /* pretend stdio is a stream socket */
+	/* pretend stdio is a stream socket */
+	ios->socktype = SOCK_STREAM;
 }
 
 
@@ -170,12 +171,13 @@
 {
 	int arg;
 	if ((arg = fcntl(fd, F_GETFL, 0)) < 0)
-		fatal("error reading file descriptor flags: %s", strerror(errno));
+		fatal("error reading file descriptor flags: %s",
+		      strerror(errno));
 
 	arg |= O_NONBLOCK;
 
 	if (fcntl(fd, F_SETFL, arg) < 0)
 		fatal("error setting flag O_NONBLOCK on file descriptor",
-			strerror(errno));
+		      strerror(errno));
 }
 */
Index: main.c
===================================================================
RCS file: /cvs/nc6/src/main.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- main.c	24 Dec 2002 20:08:43 -0000	1.7
+++ main.c	24 Dec 2002 21:05:37 -0000	1.8
@@ -110,7 +110,7 @@
 
 	/* run the main read/write loop */
 	retval = readwrite(&(connection_attrs.remote_stream),
-	          &(connection_attrs.local_stream));
+	                   &(connection_attrs.local_stream));
 
 	/* cleanup */
 	connection_attributes_destroy(&connection_attrs);
Index: network.c
===================================================================
RCS file: /cvs/nc6/src/network.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- network.c	24 Dec 2002 20:20:31 -0000	1.16
+++ network.c	24 Dec 2002 21:05:37 -0000	1.17
@@ -144,8 +144,11 @@
 	for (ptr = res; ptr != NULL; ptr = ptr->ai_next) {
 
 		/* only accept socktypes we can handle */
-		if (ptr->ai_socktype != SOCK_STREAM && ptr->ai_socktype != SOCK_DGRAM)
+		if (ptr->ai_socktype != SOCK_STREAM &&
+		    ptr->ai_socktype != SOCK_DGRAM)
+		{
 			continue;
+		}
 
 #if defined(PF_INET6) && !defined(ENABLE_IPV6)
 		/* skip IPv6 if disabled */
@@ -158,8 +161,9 @@
 
 		/* get the numeric name for this destination as a string */
 		err = getnameinfo(ptr->ai_addr, ptr->ai_addrlen,
-		                  hbuf_num, sizeof(hbuf_num), sbuf_num, 
-		                  sizeof(sbuf_num), NI_NUMERICHOST | NI_NUMERICSERV);
+		                  hbuf_num, sizeof(hbuf_num),
+				  sbuf_num, sizeof(sbuf_num),
+				  NI_NUMERICHOST | NI_NUMERICSERV);
 
 		/* this should never happen */
 		if (err != 0)
@@ -171,8 +175,8 @@
 		{
 			/* get the real name for this destination as a string */
 			err = getnameinfo(ptr->ai_addr, ptr->ai_addrlen,
-			                  hbuf_rev, sizeof(hbuf_rev), sbuf_rev, 
-			                  sizeof(sbuf_rev), 0);
+			                  hbuf_rev, sizeof(hbuf_rev),
+					  sbuf_rev, sizeof(sbuf_rev), 0);
 
 			if (err != 0)
 				warn("inverse lookup failed for %s: %s",
@@ -200,8 +204,8 @@
 		if (ptr->ai_family == PF_INET6) {
 			int on = 1;
 			/* in case of error, we will go on anyway... */
-			err = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
-					 sizeof(on));
+			err = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
+			                 &on, sizeof(on));
 			if (err < 0) warn("error with sockopt IPV6_V6ONLY");
 		}
 #endif 
@@ -220,8 +224,9 @@
 			if (is_flag_set(NUMERIC_MODE) == TRUE) 
 				hints.ai_flags |= AI_NUMERICHOST;
 		
-			/* get the IP address of the local end of the connection */
-			err = getaddrinfo(local->address, local->service, &hints, &src_res);
+			/* get the local IP address of the connection */
+			err = getaddrinfo(local->address, local->service,
+			                  &hints, &src_res);
 			if (err != 0)
 				fatal("forward host lookup failed for source address %s: %s",
 				      local->address, gai_strerror(err));
@@ -229,23 +234,28 @@
 			/* check the results of getaddrinfo */
 			assert(src_res != NULL);
 
-			/* try binding to any of the addresses returned by getaddrinfo */
-			for (src_ptr = src_res; src_ptr; src_ptr = src_ptr->ai_next) {
-				err = bind(fd, src_ptr->ai_addr, src_ptr->ai_addrlen);
+			/* try binding to any of the addresses */
+			for (src_ptr = src_res;
+			     src_ptr;
+			     src_ptr = src_ptr->ai_next)
+			{
+				err = bind(fd,
+				           src_ptr->ai_addr,
+					   src_ptr->ai_addrlen);
 				if (err == 0)
 					break;
 			}
 			
 			if (err != 0) {
-				/* make sure we have tried all the addresses returned by 
-				 * getaddrinfo */
+				/* make sure we have tried all addresses */
 				assert(src_ptr == NULL);
 				
 				if (is_flag_set(VERBOSE_MODE) == TRUE) {
 					warn("bind to source addr/port failed "
-				             "when connecting %s [%s] %s (%s): %s",
-					     hbuf_rev, hbuf_num, sbuf_num, sbuf_rev,
-					     strerror(errno));
+					     "when connecting %s [%s] %s (%s): %s",
+					      hbuf_rev, hbuf_num,
+					      sbuf_num, sbuf_rev,
[...223 lines suppressed...]
Index: parser.c
===================================================================
RCS file: /cvs/nc6/src/parser.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- parser.c	24 Dec 2002 20:20:31 -0000	1.13
+++ parser.c	24 Dec 2002 21:05:37 -0000	1.14
@@ -60,12 +60,12 @@
  		switch(c) {
 		case '4':
 			if (attrs->proto != PROTO_UNSPECIFIED) 
-				fatal("cannot specify the address family twice");
+			    fatal("cannot specify the address family twice");
 			attrs->proto = PROTO_IPv4;
 			break;
 		case '6':	
 			if (attrs->proto != PROTO_UNSPECIFIED) 
-				fatal("cannot specify the address family twice");
+			    fatal("cannot specify the address family twice");
 			attrs->proto = PROTO_IPv6;
 			set_flag(STRICT_IPV6);
 			break;
@@ -119,9 +119,8 @@
 	set_flag((listen_mode)? LISTEN_MODE : CONNECT_MODE);
 
 	/* setup file transfer depending on the mode */
-	if (file_transfer == TRUE) {
+	if (file_transfer == TRUE)
 		set_flag((listen_mode)? RECV_DATA_ONLY : SEND_DATA_ONLY);
-	}
 
 	/* additional arguments are the remote address/service */
 	switch(argc) {
@@ -186,22 +185,22 @@
 	const char *program_name = get_program_name();
 
 	fprintf(fp, "\nUsage:\n"
-		"\t%s [-46hnux] [-p port] [-s addr] hostname port\n"
-		"\t%s -l -p port [-s addr] [-46dhnux] [hostname] [port]\n\n"
-		"Recognized options are:\n", program_name, program_name);
+"\t%s [-46hnux] [-p port] [-s addr] hostname port\n"
+"\t%s -l -p port [-s addr] [-46dhnux] [hostname] [port]\n\n"
+"Recognized options are:\n", program_name, program_name);
 	fprintf(fp,	
-		"    -4         Use only IPv4\n"
-		"    -6         Use only IPv6\n"
-		"    -d         Disable SO_REUSEADDR socket option (only in listen mode)\n"
-		"    -h         Display help\n"
-		"    -l         Listen mode, for inbound connects\n"
-		"    -n         Numeric-only IP addresses, no DNS\n" 
-		"    -p port    Local source port\n"
-		"    -q n1[:n2] Hold timeouts\n"
-		"    -s addr    Local source address\n"
-		"    -u         Require use of UDP\n"
-		"    -v         Increase program verbosity (call twice for max verbosity)\n"
-		"    -x         File transfer mode\n\n");
+"    -4         Use only IPv4\n"
+"    -6         Use only IPv6\n"
+"    -d         Disable SO_REUSEADDR socket option (only in listen mode)\n"
+"    -h         Display help\n"
+"    -l         Listen mode, for inbound connects\n"
+"    -n         Numeric-only IP addresses, no DNS\n" 
+"    -p port    Local source port\n"
+"    -q n1[:n2] Hold timeouts\n"
+"    -s addr    Local source address\n"
+"    -u         Require use of UDP\n"
+"    -v         Increase program verbosity (call twice for max verbosity)\n"
+"    -x         File transfer mode\n\n");
 }
 
 
Index: readwrite.c
===================================================================
RCS file: /cvs/nc6/src/readwrite.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- readwrite.c	24 Dec 2002 20:20:31 -0000	1.16
+++ readwrite.c	24 Dec 2002 21:05:37 -0000	1.17
@@ -88,7 +88,7 @@
 	FD_ZERO(&read_fdset);
 	FD_ZERO(&write_fdset);
 
-	/* calculate max_fd and add initial fd's to be read from to read_fdset */
+	/* calculate max_fd and add initial fd's to read from to read_fdset */
 	if (is_read_open(ios1)) {
 		/* read from ios1 */
 		FD_SET(ios_readfd(ios1), &read_fdset);
@@ -122,8 +122,8 @@
 	 * a write error occurs
 	 *
 	 * note: by default, when the remote read side (ios1) is closed, it
-	 * triggers a hold timeout immediately - which closes the local read side
-	 * as well.
+	 * triggers a hold timeout immediately - which closes the local read
+	 * side as well.
 	 */
 	while (is_read_open(ios1) || is_read_open(ios2) ||
 	       is_empty(buf1) == FALSE || is_empty(buf2) == FALSE)
@@ -132,16 +132,21 @@
 		/* sanity checks */
 		/* writefd should be set iff the buffer contains data */
 		assert(XOR(is_empty(buf1) == TRUE,
-		       is_write_open(ios2) && FD_ISSET(ios_writefd(ios2), &write_fdset)));
+		       is_write_open(ios2) &&
+		         FD_ISSET(ios_writefd(ios2), &write_fdset)));
 		assert(XOR((is_empty(buf2) == TRUE),
-		       is_write_open(ios1) && FD_ISSET(ios_writefd(ios1), &write_fdset)));
+		       is_write_open(ios1) &&
+		         FD_ISSET(ios_writefd(ios1), &write_fdset)));
 		/* readfd should be set (or closed) iff the buffer is not full
 		 * or tbuf1 is in use and it still contains data */
 		assert(XOR(
-		       (tbuf1 && tbuf1_bytes > 0) || (!tbuf1 && is_full(buf1) == TRUE),
-		       !is_read_open(ios1) || FD_ISSET(ios_readfd(ios1), &read_fdset)));
+		       (tbuf1 && tbuf1_bytes > 0) ||
+		         (!tbuf1 && is_full(buf1) == TRUE),
+		       !is_read_open(ios1) ||
+		         FD_ISSET(ios_readfd(ios1), &read_fdset)));
 		assert(XOR(is_full(buf2) == TRUE,
-		       !is_read_open(ios2) || FD_ISSET(ios_readfd(ios2), &read_fdset)));
+		       !is_read_open(ios2) ||
+		         FD_ISSET(ios_readfd(ios2), &read_fdset)));
 		/* if tbuf1 is not being used, tbuf1_bytes must be 0 */
 		assert(tbuf1 || tbuf1_bytes == 0);
 
@@ -152,14 +157,16 @@
 #ifndef NDEBUG
 		if (is_flag_set(VERY_VERBOSE_MODE) == TRUE) {
 			if (tvp1)
-				warn("ios1 timer expires in %d.%06d", tv1.tv_sec, tv1.tv_usec);
+				warn("ios1 timer expires in %d.%06d",
+				     tv1.tv_sec, tv1.tv_usec);
 			if (tvp2)
-				warn("ios2 timer expires in %d.%06d", tv2.tv_sec, tv2.tv_usec);
+				warn("ios2 timer expires in %d.%06d",
+				     tv2.tv_sec, tv2.tv_usec);
 		}
 #endif
 
 		/* stop if either ios has timed out */
-		if ((tvp1 && !timerisset(tvp1)) || (tvp2 && !timerisset(tvp2))) {
+		if ((tvp1 && !timerisset(tvp1))||(tvp2 && !timerisset(tvp2))) {
 			retval = -1;
 			break;
 		}
@@ -178,23 +185,28 @@
 		memcpy(&tmp_wr_fdset, &write_fdset, sizeof(fd_set));
 
 		/* blocking select with timeout */		
-		rr = select(max_fd + 1, &tmp_rd_fdset, &tmp_wr_fdset, NULL, tvp);
+		rr = select(
+		        max_fd + 1, &tmp_rd_fdset, &tmp_wr_fdset, NULL, tvp);
 
-		/* handle select errors. if errno == EINTR we just retry select */
+		/* handle select errors.
+		 * if errno == EINTR we just retry select */
 		if (rr < 0) {
 			if (errno == EINTR) 
 				continue;
 			fatal("select error: %s", strerror(errno));
 		}
 		
-		if (is_read_open(ios1) && FD_ISSET(ios_readfd(ios1), &tmp_rd_fdset)) {
+		if (is_read_open(ios1) &&
+		    FD_ISSET(ios_readfd(ios1), &tmp_rd_fdset))
+		{
 			assert((tbuf1 && tbuf1_bytes == 0) ||
 			       (!tbuf1 && is_full(buf1) == FALSE));
 
 			/* something is ready to read on ios1 (remote) */
[...205 lines suppressed...]



More information about the ds6-devel mailing list