[ previous ] [ next ] [ threads ]
 
 From:  Justin Ellison <justin at techadvise dot com>
 To:  m0n0wall dash dev at lists dot m0n0 dot ch
 Subject:  My first C program
 Date:  Tue, 28 Jun 2005 13:30:00 -0500
Hey guys,

I'm writing an snmp plugin for m0n0, and php takes way too long to
execute.  So, I took my simple script and converted it to C to make my
very first ever C program (scary!).

I run Gentoo on my laptop, and GCC compiles it fine there (version
3.3.5).  However, when I transfer the file to my FreeBSD 4.11 box,
running 2.95 gcc, it bombs out with a syntax error before '*' where I
have the 'FILE *in;' declaration.

Does anyone with more C foo than me have any ideas on how to fix my
problem?

Please keep in mind this is my first C program ever....

Justin

------------------------
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

/*  Be sure to add: pass .1.3.6.1.4.1.2021.255 /usr/local/bin/ipfw_snmp
\
   .1.3.6.1.4.1.2021.255 
   to snmpd.conf
   usage: ipfw_snmp mibtree [-g|-n] mibleaf 
*/

int main (int argc, char *argv[]) {
  int next = 0;
  int found = 0;
  char leaf[20] = "";
  if (argc != 4)
	return(1); 
  if (strcmp(argv[2],"-n") == 0)
	next = 1;	
  else if (strcmp(argv[2],"-g") == 0)
	next = 0;
  else
  	return(0);

  if (next && strcmp(argv[3],argv[1]) == 0) {
	found = 1;
	next = 0;
  }
  else if (strstr(argv[3],argv[1])) {

strncpy(leaf,argv[3]+(strlen(argv[1])+1),(strlen(argv[3])-strlen(argv[1])+1));
  	found = 0; 
  }
  else
  	return(0);


  // Setup for output of ipfw show
  FILE *in;
  extern FILE *popen();
  char buff[512];
  if (!(in = popen("cat /home/justintime/tmp/ipfw","r")))
  //FIXME  if (!(in = popen("ipfw show","r")))
	  exit(1);
  
  //Process output of ipfw show
  while (fgets(buff, sizeof(buff), in) != NULL ) {
	  char rulenum[20];
	  char packets[20];
	  char bytes[20];
	  sscanf(buff,"%s %s %s",rulenum,packets,bytes);
	  if (strcmp(leaf,rulenum) == 0) {
		  puts("Matched if\n");
		  found = 1;
	  }
	  if (found == 0)
		  continue;
	  if (next == 0) {
		  printf("%s.%s\ncounter\n%s\n",argv[1],rulenum,bytes);
		  break;
	  }
	  next = 0;
  }
return(0);
}
----------------------------------------------------------------------
--