~vlad-lesin/mysqlsniffer/trunk

« back to all changes in this revision

Viewing changes to src/mysqlsniffer.c

  • Committer: Vlad Lesin
  • Date: 2012-05-16 11:44:17 UTC
  • Revision ID: vlad_lesin@mail.ru-20120516114417-k09e9c35drh2j5tm
Read input from file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
   else
103
103
      show_help();
104
104
 
105
 
   if(pcap_lookupnet(dev, &net, &mask, errbuf) == -1) {
106
 
      printf("Couldn't get netmask for device %s: %s\n", dev, errbuf);
107
 
      net = mask = 0;
108
 
        }
 
105
   if (op.file)
 
106
   {
 
107
     handle = pcap_open_offline(dev, errbuf);
 
108
     if (handle == NULL)
 
109
     {
 
110
        printf("Couldn't open file %s: %s\n", dev, errbuf);
 
111
        exit(-1);
 
112
     }
 
113
   }
 
114
   else
 
115
   {
 
116
     if(pcap_lookupnet(dev, &net, &mask, errbuf) == -1) {
 
117
       printf("Couldn't get netmask for device %s: %s\n", dev, errbuf);
 
118
       net = mask = 0;
 
119
     }
109
120
 
110
 
   handle = pcap_open_live(dev, SNAP_LEN, 1, 0, errbuf);
111
 
   if(handle == NULL) {
112
 
      printf("Couldn't open device %s: %s\n", dev, errbuf);
113
 
      exit(-1);
 
121
     handle = pcap_open_live(dev, SNAP_LEN, 1, 0, errbuf);
 
122
     if(handle == NULL) {
 
123
       printf("Couldn't open device %s: %s\n", dev, errbuf);
 
124
       exit(-1);
 
125
     }
114
126
   }
115
127
 
116
128
   if(pcap_compile(handle, &fp, filter_exp, 0, net) == -1) {
146
158
   printf("mysqlsniffer v1.2 - Watch MySQL traffic on a TCP/IP network\n\n");
147
159
   printf("Usage: mysqlsniffer [OPTIONS] INTERFACE\n\n");
148
160
   printf("OPTIONS:\n");
 
161
   printf("   --file          parse packages from tcpdump file\n");
149
162
   printf("   --port N        Listen for MySQL on port number N (default 3306)\n");
150
163
   printf("   --verbose       Show extra packet information\n");
151
164
   printf("   --tcp-ctrl      Show TCP control packets (SYN, FIN, RST, ACK)\n");
163
176
void proc_ops(int argc, char *argv[])
164
177
{
165
178
   struct option ops[] = {
 
179
      {"file",          0,  NULL,  'f'},
166
180
      {"port",          1,  NULL,  'p'},
167
181
      {"verbose",       0,  NULL,  'v'},
168
182
      {"tcp-ctrl",      0,  NULL,  't'},
176
190
   };
177
191
 
178
192
   int o;
 
193
   memset(&op, 0, sizeof(op));
179
194
 
180
195
   while((o = getopt_long(argc, argv, "p:qvthsd", ops, NULL)) != -1) {
181
196
      switch(o) {
 
197
         case 'f': op.file = 1; break;
182
198
         case 'p': op.port = 1;
183
199
                   strncpy(filter_exp + 5, optarg, (strlen(optarg) < 6 ? strlen(optarg) : 5));
184
200
                   filter_exp[10] = 0;