LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-09-2004, 03:21 PM   #1
wickdgin
Member
 
Registered: Apr 2002
Distribution: Gentoo, Slackware
Posts: 63

Rep: Reputation: 15
Iptable Extensions


Hi,



I am trying to play around with Iptable extensions and I have run into a little trouble. I hope somebody can point me in the right direction, or tell me what I am doing wrong.

I was attempting to compile sample code from this tutorial:

http://www.netfilter.org/documentati...000/tut-6.html

to get a feel for how it all works and comes together. However I had trouble compiling the shared library portion of this code. I've tried to use the same compiler flags as I had seen in the iptable makefile for the included extensions. These are the compiler flags I used, and the errors I recieved.

# cc -O2 -Wall -Wunused -I/usr/src/linux/include -I/home/shannon.field/src/iptables-1.2.9/include/ -I/ -DIPTABLES_VERSION=\"1.2.9\" -I/ -DNETFILTER_VERSION=\"1.2.9\" -fPIC -o libipt_length.o -c libipt_length.c


libipt_length.c: In function `parse':
libipt_length.c:48: too few arguments to function `string_to_number'
libipt_length.c:51: `s' undeclared (first use in this function)
libipt_length.c:51: (Each undeclared identifier is reported only once
libipt_length.c:51: for each function it appears in.)
libipt_length.c:39: warning: unused variable `info'
libipt_length.c: In function `print_length':
libipt_length.c:74: structure has no member named `length'

I pasted the code below:

/* Shared library add-on to iptables to add packet length matching support. */
#include <stdio.h>
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include <iptables.h>
#include <linux/netfilter_ipv4/ipt_length.h>

/* Function which prints out usage message. */
static void
help(void)
{
printf("length v%s options:\n"
"--length length Match this packet length\n",
NETFILTER_VERSION);
}

static struct option opts[] = {
{ "length", 1, 0, '1' },
{0}
};

/* Initialize the match. */
static void
init(struct ipt_entry_match *m, unsigned int *nfcache)
{
*nfcache |= NFC_UNKNOWN;
}

/* Function which parses command options; returns true if it
ate an option */
static int
parse(int c, char **argv, int invert, unsigned int *flags,
const struct ipt_entry *entry,
unsigned int *nfcache,
struct ipt_entry_match **match)
{
struct ipt_length_info *info = (struct ipt_length_info *)(*match)->data;
int len;

switch (c) {
case '1':
if (*flags)
exit_error(PARAMETER_PROBLEM,
"length: `--length' may only be "
"specified once");
len = string_to_number(argv[optind-1], 0, 0xFFFF);
if (len == -1)
exit_error(PARAMETER_PROBLEM,
"length invalid: `%s'\n", s);
*flags = 1;
break;

default:
return 0;
}
return 1;
}

/* Final check; must have specified --length. */
static void
final_check(unsigned int flags)
{
if (!flags)
exit_error(PARAMETER_PROBLEM,
"length: You must specify `--length'");
}

/* Common match printing code. */
static void
print_length(struct ipt_length_info *info)
{
printf("%u ", info->length);
}

/* Prints out the matchinfo. */
static void
print(const struct ipt_ip *ip,
const struct ipt_entry_match *match,
int numeric)
{
printf("length ");
print_length((struct ipt_length_info *)match->data);
}

/* Saves the union ipt_matchinfo in parsable form to stdout. */
static void
save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
{
printf("--length ");
print_length((struct ipt_length_info *)match->data);
}

struct iptables_match length
= { NULL,
"length",
NETFILTER_VERSION,
sizeof(struct ipt_length_info),
sizeof(struct ipt_length_info),
&help,
&init,
&parse,
&final_check,
&print,
&save,
opts
};

void _init(void)
{
register_match(&length);
}


--Thanks in advance for any help
 
Old 06-09-2004, 05:07 PM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
guess the code u r looking at is for an older version of iptables perhaps.

libipt_length.c: In function `parse':
libipt_length.c:48: too few arguments to function `string_to_number'
--well, guess this is pretty self explanatory.
libipt_length.c:51: `s' undeclared (first use in this function)
libipt_length.c:51: (Each undeclared identifier is reported only once
libipt_length.c:51: for each function it appears in.)
--this variable is never declared anywhere. it seems to be referring to some string.
libipt_length.c:39: warning: unused variable `info'
--this variable is not used, but it is declared, get rid of it.
libipt_length.c: In function `print_length':
libipt_length.c:74: structure has no member named `length'
from /usr/include/linux/netfilter_ipv4/ipt_length.h :
Code:
struct ipt_length_info {
    u_int16_t   min, max;
    u_int8_t    invert;
};
--there is no member named length.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is an iptable? Baran Linux - Newbie 7 02-07-2005 05:14 PM
iptable summerfish Linux - Networking 1 07-16-2004 02:28 AM
iptable cristi1979 Linux - Networking 4 06-29-2003 05:54 PM
iptable help Neomaster Linux - Security 5 05-29-2003 09:13 PM
Iptable Help cirkut5732 Slackware 4 04-10-2003 11:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration