~ubuntu-branches/ubuntu/natty/ntop/natty

« back to all changes in this revision

Viewing changes to utils/addMacAddress.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-01-30 21:59:13 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050130215913-xc3ke963bw49b3k4
Tags: 2:3.0-5
* Updated README.Debian file so users will understand what to do at
  install, closes: #291794, #287802.
* Updated ntop init script to give better output.
* Also changed log directory from /var/lib/ntop to /var/log/ntop,
  closes: #252352.
* Quoted the interface list to allow whitespace, closes: #267248.
* Added a couple of logcheck ignores, closes: #269321, #269319.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 1998-2000 Luca Deri <deri@ntop.org>
 
3
 *                      
 
4
 *                        http://www.ntop.org/
 
5
 *                                      
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 */
 
20
#include <stdio.h>
 
21
#include <gdbm.h>
 
22
 
 
23
void usage(char *progName) {
 
24
  printf("Usage: %s <MAC ADDRESS [17 chars]> "
 
25
         "<symbolic name> <ntop.db file>\n", progName);
 
26
  printf("Example: %s 08:00:09:B4:AA:81 \"Luca's Macintosh\" "
 
27
         "/usr/people/luca/ntop/ntop.db\n", progName);
 
28
  exit(-1);
 
29
}
 
30
 
 
31
int main(int argc, char *argv[])
 
32
{
 
33
  GDBM_FILE gdbm_file;
 
34
  datum key_data, data_data;
 
35
 
 
36
  if(argc != 4) {
 
37
    usage(argv[0]);
 
38
  }
 
39
 
 
40
  if((strlen(argv[1]) != 17)
 
41
     || (argv[1][2] != ':')
 
42
     || (argv[1][5] != ':')
 
43
     || (argv[1][8] != ':')
 
44
     || (argv[1][11] != ':')
 
45
     || (argv[1][14] != ':')) {
 
46
    printf("Wrong MAC Address format. Example: 08:00:09:B4:AA:81\n");
 
47
    exit(-1);
 
48
  }
 
49
 
 
50
  gdbm_file = gdbm_open (argv[3], 0, GDBM_WRCREAT, 00664, NULL);
 
51
  
 
52
  if(gdbm_file == NULL) {
 
53
    printf("Database open failed: %s\n", gdbm_strerror(gdbm_errno));
 
54
    exit(-1);    
 
55
  }
 
56
 
 
57
  key_data.dptr = argv[1];
 
58
  key_data.dsize = strlen(key_data.dptr)+1;
 
59
  data_data.dptr = argv[2];
 
60
  data_data.dsize = strlen(data_data.dptr)+1;
 
61
 
 
62
  if(gdbm_store(gdbm_file, key_data, data_data, GDBM_REPLACE) != 0)
 
63
    printf("Error while adding data: %s\n", gdbm_strerror(gdbm_errno));
 
64
 
 
65
  gdbm_close(gdbm_file);
 
66
 
 
67
  return(0);
 
68
}