All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pedro Lamarão" <pedro.lamarao@globo.com>
To: netfilter-devel@lists.netfilter.org
Subject: why don't we use /etc/protocols ?
Date: Thu, 18 Mar 2004 15:54:39 -0300	[thread overview]
Message-ID: <4059F06F.1050306@globo.com> (raw)

[-- 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);
+		}
 	}
 }
 

             reply	other threads:[~2004-03-18 18:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-18 18:54 Pedro Lamarão [this message]
2004-03-28 18:45 ` why don't we use /etc/protocols ? Harald Welte
2004-04-02  0:54   ` Pedro Lamarão

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4059F06F.1050306@globo.com \
    --to=pedro.lamarao@globo.com \
    --cc=netfilter-devel@lists.netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.