From c68576857a55c53b9e1a3b3e6d9cc09cd46296c4 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Wed, 23 Feb 2011 08:03:53 +0000 Subject: [PATCH] backported fix for server_host_name setting in odbc --- ChangeLog | 6 +++++- include/tds.h | 5 +++-- src/odbc/connectparams.c | 14 +++++++++++--- src/tds/config.c | 21 ++++++++++++--------- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c3093ab8f..7e42977bd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Feb 23 09:03:11 CET 2011 Frediano Ziglio + * include/tds.h src/odbc/connectparams.c src/tds/config.c: + - backported fix for server_host_name setting in odbc + Tue Aug 10 09:38:59 CEST 2010 Frediano Ziglio * configure.ac m4/acx_pthread.m4: backport patch for HP-UX compiler @@ -311,4 +315,4 @@ Wed Jan 9 19:54:43 EST 2008 JK Lowden * ChangeLog truncated because of release * ChangeLog-0.82 added because of release -$Id: ChangeLog,v 1.2454.2.78 2010-08-10 07:39:13 freddy77 Exp $ +$Id: ChangeLog,v 1.2454.2.79 2011-02-23 08:03:53 freddy77 Exp $ diff --git a/include/tds.h b/include/tds.h index 28be319352..8c8a2a330e 100644 --- a/include/tds.h +++ b/include/tds.h @@ -1,5 +1,6 @@ /* FreeTDS - Library of routines accessing Sybase and Microsoft databases * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Brian Bruns + * Copyright (C) 2011 Frediano Ziglio * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,7 +21,7 @@ #ifndef _tds_h_ #define _tds_h_ -/* $Id: tds.h,v 1.284.2.4 2009-04-03 09:40:05 freddy77 Exp $ */ +/* $Id: tds.h,v 1.284.2.5 2011-02-23 08:03:53 freddy77 Exp $ */ #include #include @@ -1395,7 +1396,7 @@ int tds_read_conf_file(TDSCONNECTION * connection, const char *server); TDSCONNECTION *tds_read_config_info(TDSSOCKET * tds, TDSLOGIN * login, TDSLOCALE * locale); void tds_fix_connection(TDSCONNECTION * connection); void tds_config_verstr(const char *tdsver, TDSCONNECTION * connection); -void tds_lookup_host(const char *servername, char *ip); +int tds_lookup_host(const char *servername, char *ip); int tds_set_interfaces_file_loc(const char *interfloc); TDSLOCALE *tds_get_locale(void); diff --git a/src/odbc/connectparams.c b/src/odbc/connectparams.c index 000e0cc6d4..6d5108bd1e 100644 --- a/src/odbc/connectparams.c +++ b/src/odbc/connectparams.c @@ -1,6 +1,6 @@ /* FreeTDS - Library of routines accessing Sybase and Microsoft databases * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Brian Bruns - * Copyright (C) 2005 Frediano Ziglio + * Copyright (C) 2005-2011 Frediano Ziglio * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -37,7 +37,7 @@ #include #endif -TDS_RCSID(var, "$Id: connectparams.c,v 1.72 2007-07-01 10:10:52 freddy77 Exp $"); +TDS_RCSID(var, "$Id: connectparams.c,v 1.72.2.1 2011-02-23 08:03:53 freddy77 Exp $"); #if !HAVE_SQLGETPRIVATEPROFILESTRING @@ -105,9 +105,17 @@ parse_server(char *server, TDSCONNECTION * connection) if (!tds_dstr_copy(&connection->instance_name, p+1)) return 0; *p = 0; + } else { + p = (char *) strchr(server, ','); + if (p && atoi(p+1) > 0) { + connection->port = atoi(p+1); + *p = 0; + } } - tds_lookup_host(server, ip); + if (tds_lookup_host(server, ip) == TDS_SUCCEED) + tds_dstr_copy(&connection->server_host_name, server); + if (!tds_dstr_copy(&connection->ip_addr, ip)) return 0; diff --git a/src/tds/config.c b/src/tds/config.c index 2ca13ae1c3..6b3a9c6028 100644 --- a/src/tds/config.c +++ b/src/tds/config.c @@ -1,6 +1,6 @@ /* FreeTDS - Library of routines accessing Sybase and Microsoft databases * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Brian Bruns - * Copyright (C) 2006, 2007 Frediano Ziglio + * Copyright (C) 2006-2011 Frediano Ziglio * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -76,7 +76,7 @@ #include #endif -TDS_RCSID(var, "$Id: config.c,v 1.132.2.1 2009-04-03 09:40:06 freddy77 Exp $"); +TDS_RCSID(var, "$Id: config.c,v 1.132.2.2 2011-02-23 08:03:53 freddy77 Exp $"); static void tds_config_login(TDSCONNECTION * connection, TDSLOGIN * login); static void tds_config_env_tdsdump(TDSCONNECTION * connection); @@ -724,14 +724,15 @@ tds_set_interfaces_file_loc(const char *interf) } /** - * Given a servername lookup the hostname. The server ip will be stored - * in the string 'ip' in dotted-decimal notation. + * Get the IP address for a hostname. Store server's IP address + * in the string 'ip' in dotted-decimal notation. (The "hostname" might itself + * be a dotted-decimal address. * * If we can't determine the IP address then 'ip' will be set to empty * string. */ /* TODO callers seem to set always connection info... change it */ -void +int tds_lookup_host(const char *servername, /* (I) name of the server */ char *ip /* (O) dotted-decimal ip address of server */ ) @@ -745,14 +746,14 @@ tds_lookup_host(const char *servername, /* (I) name of the server int h_errnop; /* - * Only call gethostbyname if servername is not an ip address. - * This call take a while and is useless for an ip address. + * Call gethostbyname(3) only if servername is not an ip address. + * This call takes a while and is useless for an ip address. * mlilback 3/2/02 */ ip_addr = inet_addr(servername); if (ip_addr != INADDR_NONE) { tds_strlcpy(ip, servername, 17); - return; + return TDS_SUCCEED; } host = tds_gethostbyname_r(servername, &result, buffer, sizeof(buffer), &h_errnop); @@ -762,8 +763,10 @@ tds_lookup_host(const char *servername, /* (I) name of the server struct in_addr *ptr = (struct in_addr *) host->h_addr; tds_inet_ntoa_r(*ptr, ip, 17); + return TDS_SUCCEED; } -} /* tds_lookup_host() */ + return TDS_FAIL; +} /** * Given a portname lookup the port.