svn commit: trunk/busybox: miscutils networking

vda at busybox.net vda at busybox.net
Mon Jan 29 18:03:55 UTC 2007


Author: vda
Date: 2007-01-29 10:03:54 -0800 (Mon, 29 Jan 2007)
New Revision: 17641

Log:
taskset: fix incorrect rage spec and allow 0xXXX input
ping: shave off 60 bytes


Modified:
   trunk/busybox/miscutils/taskset.c
   trunk/busybox/networking/ping.c


Changeset:
Modified: trunk/busybox/miscutils/taskset.c
===================================================================
--- trunk/busybox/miscutils/taskset.c	2007-01-29 17:52:29 UTC (rev 17640)
+++ trunk/busybox/miscutils/taskset.c	2007-01-29 18:03:54 UTC (rev 17641)
@@ -62,7 +62,7 @@
 		aff = *++argv; /* <aff> <cmd...> */
 	if (aff) {
 		unsigned i = 0;
-		unsigned long l = xstrtol_range(aff, 16, 1, ULONG_MAX);
+		unsigned long l = xstrtol_range(aff, 0, 1, LONG_MAX);
 
 		CPU_ZERO(&new_mask);
 		while (i < CPU_SETSIZE && l >= (1<<i)) {

Modified: trunk/busybox/networking/ping.c
===================================================================
--- trunk/busybox/networking/ping.c	2007-01-29 17:52:29 UTC (rev 17640)
+++ trunk/busybox/networking/ping.c	2007-01-29 18:03:54 UTC (rev 17641)
@@ -28,6 +28,7 @@
 #include <net/if.h>
 #include <netinet/ip_icmp.h>
 #include "busybox.h"
+
 #if ENABLE_PING6
 #include <netinet/icmp6.h>
 /* I see RENUMBERED constants in bits/in.h - !!?
@@ -85,7 +86,7 @@
 	exit(EXIT_FAILURE);
 }
 
-static void ping(len_and_sockaddr *lsa)
+static void ping4(len_and_sockaddr *lsa)
 {
 	struct sockaddr_in pingaddr;
 	struct icmp *pkt;
@@ -222,7 +223,7 @@
 		ping6(lsa);
 	else
 #endif
-		ping(lsa);
+		ping4(lsa);
 	printf("%s is alive!\n", hostname);
 	return EXIT_SUCCESS;
 }
@@ -300,8 +301,26 @@
 	exit(status);
 }
 
-static void sendping(int junk ATTRIBUTE_UNUSED)
+static void sendping_tail(void (*sp)(int), int sz, int sizeof_packet)
 {
+	if (sz < 0)
+		bb_perror_msg_and_die("sendto");
+	if (sz != sizeof_packet)
+		bb_error_msg_and_die("ping wrote %d chars; %d expected", sz,
+			sizeof_packet);
+
+	signal(SIGALRM, sp);
+	if (pingcount == 0 || ntransmitted < pingcount) {	/* schedule next in 1s */
+		alarm(PINGINTERVAL);
+	} else { /* done, wait for the last ping to come back */
+		/* todo, don't necessarily need to wait so long... */
+		signal(SIGALRM, pingstats);
+		alarm(MAXWAIT);
+	}
+}
+
+static void sendping4(int junk ATTRIBUTE_UNUSED)
+{
 	struct icmp *pkt;
 	int i;
 	char packet[datalen + ICMP_MINLEN];
@@ -322,20 +341,7 @@
 	i = sendto(pingsock, packet, sizeof(packet), 0,
 			&pingaddr.sa, sizeof(pingaddr.sin));
 
-	if (i < 0)
-		bb_perror_msg_and_die("sendto");
-	if ((size_t)i != sizeof(packet))
-		bb_error_msg_and_die("ping wrote %d chars; %d expected", i,
-			   (int)sizeof(packet));
-
-	signal(SIGALRM, sendping);
-	if (pingcount == 0 || ntransmitted < pingcount) {	/* schedule next in 1s */
-		alarm(PINGINTERVAL);
-	} else { /* done, wait for the last ping to come back */
-		/* todo, don't necessarily need to wait so long... */
-		signal(SIGALRM, pingstats);
-		alarm(MAXWAIT);
-	}
+	sendping_tail(sendping4, i, sizeof(packet));
 }
 #if ENABLE_PING6
 static void sendping6(int junk ATTRIBUTE_UNUSED)
@@ -359,20 +365,7 @@
 	i = sendto(pingsock, packet, sizeof(packet), 0,
 			&pingaddr.sa, sizeof(pingaddr.sin6));
 
-	if (i < 0)
-		bb_perror_msg_and_die("sendto");
-	if ((size_t)i != sizeof(packet))
-		bb_error_msg_and_die("ping wrote %d chars; %d expected", i,
-			   (int)sizeof(packet));
-
-	signal(SIGALRM, sendping6);
-	if (pingcount == 0 || ntransmitted < pingcount) {	/* schedule next in 1s */
-		alarm(PINGINTERVAL);
-	} else { /* done, wait for the last ping to come back */
-		/* todo, don't necessarily need to wait so long... */
-		signal(SIGALRM, pingstats);
-		alarm(MAXWAIT);
-	}
+	sendping_tail(sendping6, i, sizeof(packet));
 }
 #endif
 
@@ -424,7 +417,7 @@
 }
 #endif
 
-static void unpack(char *buf, int sz, struct sockaddr_in *from)
+static void unpack4(char *buf, int sz, struct sockaddr_in *from)
 {
 	struct icmp *icmppkt;
 	struct iphdr *iphdr;
@@ -560,7 +553,7 @@
 }
 #endif
 
-static void ping(len_and_sockaddr *lsa)
+static void ping4(len_and_sockaddr *lsa)
 {
 	char packet[datalen + MAXIPLEN + MAXICMPLEN];
 	int sockopt;
@@ -588,7 +581,7 @@
 	signal(SIGINT, pingstats);
 
 	/* start the ping's going ... */
-	sendping(0);
+	sendping4(0);
 
 	/* listen for replies */
 	while (1) {
@@ -603,7 +596,7 @@
 				bb_perror_msg("recvfrom");
 			continue;
 		}
-		unpack(packet, c, &from);
+		unpack4(packet, c, &from);
 		if (pingcount > 0 && nreceived >= pingcount)
 			break;
 	}
@@ -730,7 +723,7 @@
 
 	datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
 
-	/* exactly one argument needed, -v and -q don't mix. So do 4, 6 */
+	/* exactly one argument needed, -v and -q don't mix */
 	opt_complementary = "=1:q--v:v--q";
 	getopt32(argc, argv, OPT_STRING, &opt_c, &opt_s, &opt_I);
 	if (option_mask32 & OPT_c) pingcount = xatoul(opt_c); // -c
@@ -758,7 +751,7 @@
 		ping6(lsa);
 	else
 #endif
-		ping(lsa);
+		ping4(lsa);
 	pingstats(0);
 	return EXIT_SUCCESS;
 }




More information about the busybox-cvs mailing list