Changeset 247
- Timestamp:
- 10/22/04 21:52:20 (9 years ago)
- Location:
- trunk/wifidog
- Files:
-
- 5 modified
-
ChangeLog (modified) (1 diff)
-
src/centralserver.c (modified) (7 diffs)
-
src/ping_thread.c (modified) (4 diffs)
-
src/util.c (modified) (3 diffs)
-
src/util.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog/ChangeLog
r246 r247 1 1 # $Header$ 2 2004-10-22 Alexandre Carmel-Veilleux <acv@acv.ca> 3 * src/various: Added wd_gethostbyname, a thread-safe (serialized) 4 version of gethostbyname. 5 2 6 2004-10-15 Alexandre Carmel-Veilleux <acv@acv.ca> 3 7 * src/auth.c: Fixed hard coded port. -
trunk/wifidog/src/centralserver.c
r241 r247 34 34 #include <errno.h> 35 35 #include <unistd.h> 36 #include <netdb.h>37 36 #include <string.h> 38 37 #include <syslog.h> … … 40 39 #include "common.h" 41 40 41 #include "util.h" 42 42 #include "auth.h" 43 43 #include "conf.h" … … 61 61 size_t numbytes, totalbytes; 62 62 char buf[MAX_BUF]; 63 struct hostent *he;63 struct in_addr *h_addr; 64 64 struct sockaddr_in their_addr; 65 65 char *tmp; … … 78 78 done = 0; 79 79 while (!done && ((auth_server = get_auth_server()) != NULL)) { 80 if ((h e =gethostbyname(auth_server->authserv_hostname)) == NULL) {80 if ((h_addr = wd_gethostbyname(auth_server->authserv_hostname)) == NULL) { 81 81 debug(LOG_ERR, "Failed to resolve %s via gethostbyname" 82 82 "(): %s", auth_server->authserv_hostname, … … 88 88 their_addr.sin_family = AF_INET; 89 89 their_addr.sin_port = htons(auth_server->authserv_http_port); 90 their_addr.sin_addr = * ((struct in_addr *)he->h_addr);90 their_addr.sin_addr = *h_addr; 91 91 memset(&(their_addr.sin_zero), '\0', sizeof(their_addr.sin_zero)); 92 92 … … 104 104 mark_auth_server_bad(auth_server); 105 105 debug(LOG_ERR, "Aborting request"); 106 free(h_addr); 106 107 close(sockfd); 107 108 return(-1); /* non-fatal */ … … 110 111 done = 1; 111 112 } 113 free(h_addr); 112 114 } 113 115 /** -
trunk/wifidog/src/ping_thread.c
r239 r247 93 93 t_auth_serv *auth_server; 94 94 char request[MAX_BUF]; 95 struct hostent *he;95 struct in_addr *h_addr; 96 96 struct sockaddr_in their_addr; 97 97 … … 108 108 auth_server->authserv_hostname); 109 109 110 if ((h e =gethostbyname(auth_server->authserv_hostname)) == NULL) {110 if ((h_addr = wd_gethostbyname(auth_server->authserv_hostname)) == NULL) { 111 111 debug(LOG_ERR, "Failed to resolve %s via gethostbyname" 112 112 "(): %s", auth_server->authserv_hostname, … … 120 120 their_addr.sin_family = AF_INET; 121 121 their_addr.sin_port = htons(auth_server->authserv_http_port); 122 their_addr.sin_addr = * ((struct in_addr *)he->h_addr);122 their_addr.sin_addr = *h_addr; 123 123 memset(&(their_addr.sin_zero), '\0', sizeof(their_addr.sin_zero)); 124 124 … … 133 133 mark_auth_server_bad(auth_server); 134 134 close(sockfd); 135 free(h_addr); 135 136 return; 136 137 } 138 free(h_addr); 137 139 138 140 snprintf(request, sizeof(request) - 1, "GET %sping/?gw_id=%s HTTP/1.0\n" -
trunk/wifidog/src/util.c
r242 r247 20 20 21 21 /* 22 * $Header: /cvsroot/wifidog/wifidog/src/firewall.c,v 1.32 2004/04/23 23 * 11:37:43 aprilp Exp $ 22 * $Header$ 24 23 */ 25 24 /** … … 41 40 42 41 #include <string.h> 42 #include <pthread.h> 43 #include <netdb.h> 43 44 44 45 #include "util.h" 45 46 #include "conf.h" 46 47 #include "debug.h" 48 49 static pthread_mutex_t ghbn_mutex = PTHREAD_MUTEX_INITIALIZER; 47 50 48 51 /** Fork a child and execute a shell command, the parent … … 82 85 return (WEXITSTATUS(status)); 83 86 } 87 88 struct in_addr * 89 wd_gethostbyname(const char *name) 90 { 91 struct hostent *he; 92 struct in_addr *h_addr, *in_addr_temp; 93 94 /* XXX Calling function is reponsible for free() */ 95 96 h_addr = (struct in_addr *)malloc(sizeof(struct in_addr)); 97 98 if (h_addr == NULL) 99 return NULL; 100 101 pthread_mutex_lock(&ghbn_mutex); 102 103 he = gethostbyname(name); 104 105 if (he == NULL) { 106 free(h_addr); 107 pthread_mutex_unlock(&ghbn_mutex); 108 return NULL; 109 } 110 111 in_addr_temp = (struct in_addr *)he->h_addr_list[0]; 112 h_addr->s_addr = in_addr_temp->s_addr; 113 114 pthread_mutex_unlock(&ghbn_mutex); 115 116 return h_addr; 117 } -
trunk/wifidog/src/util.h
r136 r247 31 31 */ 32 32 int execute(char *cmd_line, int quiet); 33 struct in_addr *wd_gethostbyname(const char *name); 33 34 34 35 #endif /* _UTIL_H_ */
