File: parse_cl.c.bak

package info (click to toggle)
ipgrab 0.5-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 268 kB
  • ctags: 169
  • sloc: sh: 1,507; ansic: 1,234; makefile: 56
file content (104 lines) | stat: -rw-r--r-- 1,883 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**************************************************************************** 
**
** File: parse_cl.c
**
** Author: Mike Borella
**
** Comments: Command line parsing
**
*****************************************************************************/

#include "config.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

/*----------------------------------------------------------------------------
 *
 * parse_cl()
 *
 *----------------------------------------------------------------------------
 */

void parse_cl(int argc, char *argv[])
{
  extern char *optarg;
  extern int optind;
  extern int cnt;
  extern int p_flag;
  extern char *dev;
  extern char *pcap_cmd;
  char c;
  void ftlerr(char *, ...);
  char *copy_argv(char **);

  while ((c=getopt(argc, argv, "c:i:p")) != EOF)
    {
      switch(c)
	{
	case 'c':
	  cnt = atoi(optarg);
	  break;

	case 'i': 
	  dev = optarg;
	  break;

	case 'p':
	  p_flag++;
	  break;

	default:
	  ftlerr("Unknown option -%c\n", c);
	  /* NOT REACHED */
	}

    } /* while */

  /* 
   * Copy filter command into a string 
   */

  pcap_cmd = copy_argv(&argv[optind]);
}



/*----------------------------------------------------------------------------
 *
 * copy_argv()
 *
 * Copy arg vector into a new buffer, concatenating arguments with spaces.
 * Lifted from tcpdump.
 *
 *----------------------------------------------------------------------------
 */

char *copy_argv(char **argv)
{
  char **p;
  u_int len = 0;
  char *buf;
  char *src, *dst;
  void ftlerr(char *, ...);
  
  p = argv;
  if (*p == 0) return 0;

  while (*p)
    len += strlen(*p++) + 1;

  buf = (char *) malloc (len);
  if (buf == NULL) ftlerr("copy_argv: malloc() failed");
      
  p = argv;
  dst = buf;
  while ((src = *p++) != NULL) 
    {
      while ((*dst++ = *src++) != '\0');
      dst[-1] = ' ';
    }
  dst[-1] = '\0';
  
  return buf;
}