strace/net.c:printsock() case AF_PACKET fix

Stefan Petri petri at panmedium.de
Wed Oct 10 04:39:11 UTC 2001


Hi!

(I tried to get this bug report and patch into the WWW interface at 
sourceforge, but didnt succeed due to internal errors at that site,
so I retry via plain mail...)

The addresses contained in AF_PACKET messages were not printed correctly.
I append a patch, which also adds some pretty printing for
the packet type codes.

							Stefan

--- strace-4.4/net.c-orig	Sat Jul 14 00:07:45 2001
+++ strace-4.4/net.c	Wed Oct 10 13:10:25 2001
@@ -570,6 +570,33 @@
 };
 #endif /* SOL_RAW */
 
+#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
+static struct xlat af_packet_types[] = {
+#if defined(PACKET_HOST)
+	{ PACKET_HOST,			"PACKET_HOST"		},
+#endif
+#if defined(PACKET_BROADCAST)
+	{ PACKET_BROADCAST,		"PACKET_BROADCAST"	},
+#endif
+#if defined(PACKET_MULTICAST)
+	{ PACKET_MULTICAST,		"PACKET_MULTICAST"	},
+#endif
+#if defined(PACKET_OTHERHOST)
+	{ PACKET_OTHERHOST,		"PACKET_OTHERHOST"	},
+#endif
+#if defined(PACKET_OUTGOING)
+	{ PACKET_OUTGOING,		"PACKET_OUTGOING"	},
+#endif
+#if defined(PACKET_LOOPBACK)
+	{ PACKET_LOOPBACK,		"PACKET_LOOPBACK"	},
+#endif
+#if defined(PACKET_FASTROUTE)
+	{ PACKET_FASTROUTE,		"PACKET_FASTROUTE"	},
+#endif
+	{ 0,				NULL			},
+};
+#endif /* defined(AF_PACKET) */
+
 
 void
 printsock(tcp, addr, addrlen)
@@ -682,13 +709,14 @@
 	case AF_PACKET:
 		{
 			int i;
-			tprintf("proto=%#04x, if%d, pkttype=%d, addr(%d)={%d, ",
+			tprintf("proto=%#04x, if%d, pkttype=",
 					ntohs(addrbuf.ll.sll_protocol),
-					addrbuf.ll.sll_ifindex,
-					addrbuf.ll.sll_pkttype,
+					addrbuf.ll.sll_ifindex);
+			printxval(af_packet_types, addrbuf.ll.sll_pkttype, "?");
+			tprintf(", addr(%d)={%d, ",
 					addrbuf.ll.sll_halen,
 					addrbuf.ll.sll_hatype);
-			for (i=0; i<addrbuf.ll.sll_addr[i]; i++) 
+			for (i=0; i<addrbuf.ll.sll_halen; i++) 
 				tprintf("%02x", addrbuf.ll.sll_addr[i]);
 		}
 		break;




More information about the Strace-devel mailing list