- Introduced the use of gethostbyname_r() if available. As siproxd

uses threads it probably is a very good idea (some funny things
  seen with Linux 2.4.18 kernel & RTP proxy - gethostbyname()
  did return a NULL result but has h_errno set to 0 "every fine, thanks")
  Future will show it this helps.
- Had overlooked one inet_aton in register.c - replaced to utils_inet_aton
- Fixed a compiler warning in log.c for Solaris. Siproxd now at least
  builds on Solaris (tested on: SunOS 5.9 sun4u sparc SUNW,Ultra-60)
This commit is contained in:
Thomas Ries
2003-11-22 21:54:21 +00:00
parent ccc0401850
commit 00dfe93a0d
10 changed files with 155 additions and 6 deletions

View File

@@ -205,7 +205,7 @@ void log_dump_buffer(int class, char *file, int line,
for (j=0;(j<16) && (i+j)<length ;j++) {
sprintf(tmp,"%2.2x ",(unsigned char)buffer[i+j]);
strcat(tmplin1, tmp);
sprintf(tmp, "%c",(isprint(buffer[i+j]))? buffer[i+j]: '.');
sprintf(tmp, "%c",(isprint((int)buffer[i+j]))? buffer[i+j]: '.');
strcat(tmplin2, tmp);
}
fprintf(stderr, " %-47.47s %-16.16s\n",tmplin1, tmplin2);

View File

@@ -328,7 +328,7 @@ int register_response(osip_message_t *request, int flag) {
}
/* name resolution needed? */
if (inet_aton (via->host,&addr) == 0) {
if (utils_inet_aton(via->host,&addr) == 0) {
/* yes, get IP address */
sts = get_ip_by_host(via->host, &addr);
if (sts == STS_FAILURE) {

View File

@@ -167,6 +167,12 @@ struct siproxd_config {
#define USERNAME_SIZE 64 /* max string length of a username (auth) */
#define PASSWORD_SIZE 64 /* max string length of a password (auth) */
/* scratch buffer for gethostbyname_r() */
#if defined(PR_NETDB_BUF_SIZE)
#define GETHOSTBYNAME_BUFLEN PR_NETDB_BUF_SIZE
#else
#define GETHOSTBYNAME_BUFLEN 1024
#endif
#define ACCESSCTL_SIP 1 /* for access control - SIP allowed */
#define ACCESSCTL_REG 2 /* --"-- - registr. allowed */

View File

@@ -65,6 +65,7 @@ int get_ip_by_host(char *hostname, struct in_addr *addr) {
int i, j;
time_t t;
struct hostent *hostentry;
int error;
static struct {
time_t timestamp;
struct in_addr addr;
@@ -113,7 +114,50 @@ int get_ip_by_host(char *hostname, struct in_addr *addr) {
}
/* did not find it in cache, so I have to resolve it */
/* need to deal with reentrant versions of gethostbyname_r()
* as we may use threads... */
#if defined(HAVE_GETHOSTBYNAME_R)
{
struct hostent result_buffer;
char tmp[GETHOSTBYNAME_BUFLEN];
/* gethostbyname_r() with 3 arguments (e.g. osf/1) */
#if defined(HAVE_FUNC_GETHOSTBYNAME_R_3)
gethostbyname_r(hostname, /* the FQDN */
&result_buffer, /* the result buffer */
&hostentry
);
if (hostentry == NULL) my_error = h_errno;
/* gethostbyname_r() with 5 arguments (e.g. solaris, linux libc5) */
#elif defined(HAVE_FUNC_GETHOSTBYNAME_R_5)
hostentry = gethostbyname_r(hostname, /* the FQDN */
&result_buffer, /* the result buffer */
tmp,
GETHOSTBYNAME_BUFLEN - 1,
&error);
/* gethostbyname_r() with 6 arguments (e.g. linux glibc) */
#elif defined(HAVE_FUNC_GETHOSTBYNAME_R_6)
gethostbyname_r(hostname, /* the FQDN */
&result_buffer, /* the result buffer */
tmp,
GETHOSTBYNAME_BUFLEN - 1,
&hostentry,
&error);
#else
#error "gethostbyname_s() with 3, 5 or 6 arguments supported only"
#endif
}
#elif defined(HAVE_GETHOSTBYNAME)
#warning "did not find reentrant version of gethostbyname_r()"
#warning "depending of your OS this may or may not work"
hostentry=gethostbyname(hostname);
if (hostentry == NULL) error = h_errno;
#else
#error "need gethostbyname() or gethostbyname_r()"
#endif
if (hostentry==NULL) {
if (h_errno == HOST_NOT_FOUND) {