[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Unaligned access fix for netstat



Hi,

In case nobody has already done this, here is a patch to get rid of
unaligned traps in netstat.  I do not know if there is any activity to
synchronise Alpha-patched sources of netbase with those used by the rest
of Debian, so I do not send this patch to the netbase maintainer.  I
hope it will go there together with the complete patchset.

Fixed netstat binary is available from ftp://genie.ucd.ie/pub/alpha/debian/.

	Nikita


--- netbase-2.17/net-tools-1.32-alpha/netstat.c.orig	Mon Sep 15 01:09:24 1997
+++ netbase-2.17/net-tools-1.32-alpha/netstat.c	Mon Sep 15 01:29:23 1997
@@ -54,6 +54,7 @@
 #include <pwd.h>
 #include <getopt.h>
 #include <sys/param.h>
+#include <sys/types.h>
 #if defined(__GLIBC__)
 #define _SOCKETBITS_H
 #endif /* __GLIBC__ */
@@ -289,6 +290,7 @@
   struct aftype *ap;
   unsigned long rxq, txq, time_len, retr;
   int num, local_port, rem_port, d, state;
+  unsigned long local_ip, rem_ip;
   int uid, timer_run, lnr = 0;
   struct passwd *pw;
   
@@ -319,12 +321,14 @@
   while (lnr >= 0) {
 	num = sscanf(line[lnr--],
 		"%d: %lX:%X %lX:%X %X %lX:%lX %X:%lX %lX %d\n",
-		&d, (unsigned long*)&localaddr.sin_addr.s_addr, &local_port,
-		(unsigned long*)&remaddr.sin_addr.s_addr, &rem_port, &state,
+		&d, &local_ip, &local_port,
+		&rem_ip, &rem_port, &state,
 		&txq, &rxq, &timer_run, &time_len, &retr, &uid);
 	if (flag_deb) fprintf(stderr, NLS_CATGETS(catfd, netstatSet, netstat_args,
 						  "%s -> %d args"), line[lnr+1], num);
 	if (num < 11) continue;		/* 13 ? */
+	*(u_int32_t *)&localaddr.sin_addr.s_addr = (u_int32_t)local_ip;
+	*(u_int32_t *)&remaddr.sin_addr.s_addr = (u_int32_t)rem_ip;
 	localaddr.sin_family = AF_INET;
 	remaddr.sin_family = AF_INET;
 	if ((ap = get_afntype(localaddr.sin_family)) == NULL) {
@@ -444,6 +448,7 @@
   char buffer[8192], local_addr[64], rem_addr[64];
   char *udp_state, timer_queued, timers[64], more[512];
   int num, local_port, rem_port, d, state, timer_run, lnr = 0;
+  unsigned long local_ip, rem_ip;
   struct sockaddr_in localaddr, remaddr;
   struct aftype *ap;
   unsigned long rxq, txq, time_len, retr;
@@ -477,10 +482,12 @@
 	timer_queued = '\0';
 	num = sscanf(line[lnr--],
 		"%d: %lX:%X %lX:%X %X %lX:%lX %X:%lX %lX %c %s\n",
-		&d, (unsigned long*)&localaddr.sin_addr.s_addr, &local_port,
-		(unsigned long*)&remaddr.sin_addr.s_addr, &rem_port, &state,
+		&d, &local_ip, &local_port,
+		&rem_ip, &rem_port, &state,
 		&txq, &rxq, &timer_run, &time_len, &retr,
 		&timer_queued, more);
+	*(u_int32_t *)&localaddr.sin_addr.s_addr = (u_int32_t)local_ip;
+	*(u_int32_t *)&remaddr.sin_addr.s_addr = (u_int32_t)rem_ip;
 	localaddr.sin_family = AF_INET;
 	remaddr.sin_family = AF_INET;
 	if ((ap = get_afntype(localaddr.sin_family)) == NULL) {
@@ -566,6 +573,7 @@
   char buffer[8192], local_addr[64], rem_addr[64];
   char *raw_state, timer_queued, timers[64], more[512];
   int num, local_port, rem_port, d, state, timer_run, lnr = 0;
+  unsigned long local_ip, rem_ip;
   struct sockaddr_in localaddr, remaddr;
   struct aftype *ap;
   unsigned long rxq, txq, time_len, retr;
@@ -599,11 +607,13 @@
 	timer_queued = '\0';
 	num = sscanf(line[lnr--],
 		"%d: %lX:%X %lX:%X %X %lX:%lX %X:%lX %lX %c %s\n",
-		&d, (unsigned long*)&localaddr.sin_addr.s_addr, &local_port,
-		(unsigned long*)&remaddr.sin_addr.s_addr, &rem_port, &state,
+		&d, &local_ip, &local_port,
+		&rem_ip, &rem_port, &state,
 		&txq, &rxq, &timer_run, &time_len, &retr,
 		&timer_queued, more);
 		retr = 0L;
+	*(u_int32_t *)&localaddr.sin_addr.s_addr = (u_int32_t)local_ip;
+	*(u_int32_t *)&remaddr.sin_addr.s_addr = (u_int32_t)rem_ip;
 	localaddr.sin_family = AF_INET;
 	remaddr.sin_family = AF_INET;
 	if ((ap = get_afntype(localaddr.sin_family)) == NULL) {


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-alpha-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: