/* Copyright (c) 2000 RIPE NCC All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ------------------------------------------------------------------------------- Module Header Filename : common.h Purpose : Common functions used by all scripts of the application Author : Manuel Valente Date : 20000510 Revised : 20020815 Rene Wilhelm, changes related to added ASpaths Revised : 20021210 Florian Frotzler, added IPv6 compatibility Description : Language Version : gcc version 2.95.2 OSs Tested : Solaris 2.6 Command Line : Input Files : Output Files : External Programs : mysqld Problems : To Do : Comments : $Id: common.h,v 1.6 2003/11/07 13:32:01 wilhelm Exp $ ------------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* Constants */ /* Time Limit for querying records (seconds) */ #define TIME_LIMIT 3600 /* UID that the application must run with */ #define ADMIN_UID 140 /* Time Limit for moving records to the old table */ #define DAYS_LIMIT 183 /* Time Limit for deleting records from the old table */ #define OLD_DAYS_LIMIT 1095 /* Max Number of Lines returned by routequery */ #define MAX_QUERY_LINES 1000 /* Max Number of hops seen in a traceroute */ #define MAX_HOPS 32 /* Max Size of an IP num in ascii integer reprentation */ #define MAX_IP_SIZE 15 /* 4*3 + 3 dots */ #define MAX_IP6_SIZE 46 /* = INET6_ADDRSTRLEN */ /* Max Size of one hop in AS space in ascii reprentation */ #define MAX_AS_SIZE 30 /* conservative, enough for 5 different 5 digit ASnums seperated by / */ /* Path to LIST_OF_TESTBOXES file */ #define PATHBOXES "./LIST_OF_TESTBOXES" /* Path to RBYT file */ #define RBYT "/ncc/ttpro/routes/RBYT" /* Path to VBYE file */ #define VBYE "/ncc/ttpro/routes/VBYE" /* MySQL Host */ /* #define MYSQL_HOST "localhost" */ #define MYSQL_HOST "kauri.ripe.net" /* MySQL DB name */ #define MYSQL_DB_v4 "TTM" #define MYSQL_DB_v6 "TTM_IPv6" /* MySQL Admin Name */ #define ADMIN_NAME_v4 "" #define ADMIN_NAME_v6 "" /* MySQL Admin Password */ #define ADMIN_PWD_v4 "" #define ADMIN_PWD_v6 "" /* MySQL User Name */ #define USER_NAME "ttmuser" /* MySQL User Password */ #define USER_PWD "" /* convert ascii string to unsigned int; can't use atoi() since IPnums > MAX_LONG */ #define ATOUI(s) strtoul(s, (char **)NULL, 10) /* Define structs that will be used */ struct rangestruct { int id; int ip1; int ipid1; int ip2; int ipid2; }; struct routestruct { int id; int len; char crc[30]; }; struct recstruct { int src; int dst; int routeid; int aspathid; int timestamp; }; struct recordstruct { int id; int src; int dst; int routeid; int aspathid; int tstart; int tend; int numrec; }; struct procstruct { MYSQL *mysql; struct recordstruct *rec; }; struct datastruct { unsigned int src; unsigned int dst; unsigned int tstart; unsigned int tend; unsigned int routeid; unsigned int nhops; struct datastruct* next; }; struct querystruct { unsigned int nhops; unsigned int routeid; unsigned int aspathid; unsigned int tstart; unsigned int tend; unsigned int numrec; unsigned int ashops; char route[(MAX_IP6_SIZE+1)*MAX_HOPS]; char aspath[(MAX_AS_SIZE+1)*MAX_HOPS]; struct querystruct* next; }; struct vectorstruct { unsigned int nhops; unsigned int routeid; unsigned int tstart; unsigned int tend; struct vectorstruct* next; }; /* Public functions */ int open_admin_connection (MYSQL *mysql, char *mysql_host); int open_admin_connection_ip6 (MYSQL *mysql, char *mysql_host); int open_user_connection (MYSQL *mysql, char *mysql_host); int open_user_connection_ip6 (MYSQL *mysql, char *mysql_host); int get_table (MYSQL *mysql, GHashTable *hash, char *table); int get_ranges (GHashTable *ranges, char *path_boxes, int ip6flag); int get_ranges_by_boxname (GHashTable *ranges,char *path_boxes); int get_filenames (char *path, char **files,int flag); int get_filenames_recursive (char *path, char **files); char* route_ip_to_int (const char *route); char* route_int_to_ip (const char *route);