00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00039 #ifndef THREADSAFE_DB_H
00040 #define THREADSAFE_DB_H
00041
00042 #include <sys/types.h>
00043 #include <pthread.h>
00044 #include <netinet/in.h>
00045 #include <string>
00046
00047 #include "protlib_types.h"
00048
00049 namespace protlib {
00050
00055
00056
00059 class tsdb {
00060 private:
00062 static bool is_init;
00064 static bool resolvenames;
00065
00067 static pthread_mutex_t mutex;
00068
00070 static uint32 id32;
00071 static uint64 id64;
00072
00073
00074
00075 static protocol_t udp_id;
00076 static protocol_t tcp_id;
00077 static protocol_t sctp_id;
00078
00079 public:
00081 static void init(bool noresolving= false);
00083 static void end();
00085 static uint32 get_new_id32();
00087 static uint64 get_new_id64();
00089 static string getprotobynumber(protocol_t proto, bool *res = NULL);
00091 static protocol_t getprotobyname(const string &pname, bool *res = NULL);
00093 static protocol_t getprotobyname(const char* pname, bool *res = NULL);
00095 static protocol_t get_udp_id() { return udp_id; }
00096 static protocol_t get_tcp_id() { return tcp_id; }
00097 static protocol_t get_sctp_id() { return sctp_id; }
00098
00100 static string get_username(uid_t uid, bool *res = NULL);
00102 static uid_t get_userid(const char* uname, bool *res = NULL);
00104 static uid_t get_userid(const string& uname, bool *res = NULL);
00106 static string get_portname(port_t port, protocol_t prot, bool *res = NULL);
00108 static port_t get_portnumber(const char* pname, protocol_t prot, bool *res = NULL);
00110 static port_t get_portnumber(const string& pname, protocol_t prot, bool *res = NULL);
00112 static string get_hostname(const struct sockaddr* sa, bool *res);
00113 static string get_hostname(const in_addr& in, bool *res = NULL);
00114 static string get_hostname(const in6_addr& in, bool *res = NULL);
00115
00116 };
00117
00119
00120 }
00121
00122 #endif