All of lore.kernel.org
 help / color / mirror / Atom feed
* why don't we use /etc/protocols ?
@ 2004-03-18 18:54 Pedro Lamarão
  2004-03-28 18:45 ` Harald Welte
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Lamarão @ 2004-03-18 18:54 UTC (permalink / raw)
  To: netfilter-devel

[-- Attachment #1: Type: text/plain, Size: 473 bytes --]

Hello.

I've just subscribed to the list, so, uhm, hello.

I tried to look for some older discussion about this section of 
iptables-save.c, but I'm not that good at searching mailing list 
archives, so here it goes.

Browsing the code I stumbled at this FIXME in iptables-save.c and 
produced the following patch. Please review it and send me comments. 
I'll be over this code for some time, so, if there is more of this kind 
of FIXME, I'd gladly work on it.

--
  Pedro

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1276 bytes --]

Index: iptables-save.c
===================================================================
RCS file: /cvspublic/iptables/iptables-save.c,v
retrieving revision 1.27
diff -u -r1.27 iptables-save.c
--- iptables-save.c	21 Feb 2004 09:20:34 -0000	1.27
+++ iptables-save.c	18 Mar 2004 18:53:54 -0000
@@ -62,36 +62,18 @@
 	printf(" ");
 }
 
-/* These are hardcoded backups in iptables.c, so they are safe */
-struct pprot {
-	char *name;
-	u_int8_t num;
-};
-
-/* FIXME: why don't we use /etc/protocols ? */
-static const struct pprot chain_protos[] = {
-	{ "tcp", IPPROTO_TCP },
-	{ "udp", IPPROTO_UDP },
-	{ "icmp", IPPROTO_ICMP },
-	{ "esp", IPPROTO_ESP },
-	{ "ah", IPPROTO_AH },
-	{ "sctp", IPPROTO_SCTP },
-};
-
 static void print_proto(u_int16_t proto, int invert)
 {
 	if (proto) {
-		unsigned int i;
 		const char *invertstr = invert ? "! " : "";
 
-		for (i = 0; i < sizeof(chain_protos)/sizeof(struct pprot); i++)
-			if (chain_protos[i].num == proto) {
-				printf("-p %s%s ",
-				       invertstr, chain_protos[i].name);
-				return;
-			}
-
-		printf("-p %s%u ", invertstr, proto);
+		struct protoent* pent = getprotobynumber(proto)
+		if (proto) {
+			printf("-p %s%s ", invertstr, pent->p_name);
+		}
+		else {
+			printf("-p %s%u", invertstr, proto);
+		}
 	}
 }
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-04-02  0:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-18 18:54 why don't we use /etc/protocols ? Pedro Lamarão
2004-03-28 18:45 ` Harald Welte
2004-04-02  0:54   ` Pedro Lamarão

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.