string get_addr_str(struct in_addr in) { inet_ntoa_mut.lock(); string addr = inet_ntoa(in); inet_ntoa_mut.unlock(); return addr; }
unsigned int get_random() { _s_rand_mut.lock(); unsigned int r = rand_r(&_s_rand); _s_rand_mut.unlock(); return r; }
string get_ip_from_name(const string& name) { inet_gethostbyname.lock(); struct hostent *he = gethostbyname(name.c_str()); if(!he) { inet_gethostbyname.unlock(); return ""; } struct in_addr a; bcopy(he->h_addr, (char *) &a, sizeof(a)); inet_gethostbyname.unlock(); return get_addr_str(a); }
/** * Run log hooks */ void run_log_hooks(int level, pid_t pid, pthread_t tid, const char* func, const char* file, int line, char* msg) { log_hooks_mutex.lock(); if (!log_hooks.empty()) { for (vector<AmLoggingFacility*>::iterator it = log_hooks.begin(); it != log_hooks.end(); ++it) { (*it)->log(level, pid, tid, func, file, line, msg); } } log_hooks_mutex.unlock(); }