Merge lp:~schuster/mysql-proxy/PR-268-fix into lp:mysql-proxy

Proposed by Michael Schuster
Status: Merged
Approved by: Kay Roepke
Approved revision: 1034
Merged at revision: not available
Proposed branch: lp:~schuster/mysql-proxy/PR-268-fix
Merge into: lp:mysql-proxy
Diff against target: 145 lines (+64/-14)
3 files modified
CMakeLists.txt (+1/-0)
configure.in (+4/-4)
src/network-address.c (+59/-10)
To merge this branch: bzr merge lp:~schuster/mysql-proxy/PR-268-fix
Reviewer Review Type Date Requested Status
Kay Roepke (community) previously reviewed per email Approve
Review via email: mp+22357@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Kay Roepke (kay-roepke) wrote :

+1

review: Approve (previously reviewed per email)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2010-02-25 12:41:23 +0000
3+++ CMakeLists.txt 2010-03-29 06:20:34 +0000
4@@ -182,6 +182,7 @@
5 CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
6 CHECK_FUNCTION_EXISTS(srandom HAVE_SRANDOM)
7 CHECK_FUNCTION_EXISTS(writev HAVE_WRITEV)
8+CHECK_FUNCTION_EXISTS(getaddrinfo HAVE_GETADDRINFO)
9 # check for gthread actually being present
10 CHECK_LIBRARY_EXISTS(gthread-2.0 g_thread_init ${GTHREAD_LIBRARY_DIRS} HAVE_GTHREAD)
11 #SET(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
12
13=== modified file 'configure.in'
14--- configure.in 2010-03-19 14:43:27 +0000
15+++ configure.in 2010-03-29 06:20:34 +0000
16@@ -97,9 +97,9 @@
17 sys/socket.h \
18 sys/param.h \
19 sys/time.h \
20- sys/un.h \
21- sys/uio.h \
22- sys/ioctl.h \
23+ sys/un.h \
24+ sys/uio.h \
25+ sys/ioctl.h \
26 sys/resource.h \
27 pwd.h \
28 signal.h \
29@@ -341,7 +341,7 @@
30 AM_CONDITIONAL(OS_SOLARIS, test x$ARCH = xsolaris)
31
32 dnl on windows we need wsock32 to get socket support
33-AC_CHECK_FUNCS([inet_ntoa inet_ntop strerror getcwd chdir writev gmtime_r sigaction])
34+AC_CHECK_FUNCS([inet_ntoa inet_ntop strerror getcwd chdir writev gmtime_r sigaction getaddrinfo])
35
36 dnl make sure we off_t is 64bit
37 dnl CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES"
38
39=== modified file 'src/network-address.c'
40--- src/network-address.c 2009-11-20 15:02:36 +0000
41+++ src/network-address.c 2010-03-29 06:20:34 +0000
42@@ -1,5 +1,5 @@
43 /* $%BEGINLICENSE%$
44- Copyright (C) 2007-2009 MySQL AB, 2009 Sun Microsystems, Inc
45+ Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
46
47 This program is free software; you can redistribute it and/or modify
48 it under the terms of the GNU General Public License as published by
49@@ -12,11 +12,8 @@
50
51 You should have received a copy of the GNU General Public License
52 along with this program; if not, write to the Free Software
53- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
54-
55+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
56 $%ENDLICENSE%$ */
57-
58-
59 #ifdef HAVE_CONFIG_H
60 #include "config.h"
61 #endif
62@@ -90,12 +87,62 @@
63 0 == strcmp("0.0.0.0", address)) {
64 /* no ip */
65 addr->addr.ipv4.sin_addr.s_addr = htonl(INADDR_ANY);
66+ addr->addr.ipv4.sin_family = AF_INET; /* "default" family */
67 } else {
68- struct hostent *he;
69+#ifdef HAVE_GETADDRINFO
70+ struct addrinfo *ai = NULL, hint;
71+ int rc, family;
72+
73+ memset(&hint, 0, sizeof (hint));
74+ /*
75+ * FIXME: when we add support for IPv6, we'll have to do one
76+ * PF_INET* after the other
77+ */
78+ hint.ai_family = PF_INET;
79+ if ((rc = getaddrinfo(address, NULL, &hint, &ai)) != 0) {
80+ g_critical("getaddrinfo(%s) failed with %s", address,
81+ gai_strerror(rc));
82+ return -1;
83+ }
84+
85+ do {
86+ family = ai->ai_family;
87+#if 0 /* keep this for when we do IPv6 */
88+ if (family == PF_INET6) {
89+ memcpy(&addr->addr.ipv6,
90+ (struct sockaddr_in6 *) ai->ai_addr,
91+ sizeof (addr->addr.ipv6));
92+ break;
93+ }
94+#endif /* 0 */
95+ if (family == PF_INET) {
96+ memcpy(&addr->addr.ipv4,
97+ (struct sockaddr_in *) ai->ai_addr,
98+ sizeof (addr->addr.ipv4));
99+ break;
100+ }
101+ ai = ai->ai_next;
102+ } while (NULL != ai);
103+
104+ if (ai == NULL) {
105+ /* the family we print here is the *last* ai's */
106+ g_critical("address %s doesn't resolve to a valid/supported "
107+ "address family: %d expected, last found %d", address,
108+ PF_INET, family);
109+ freeaddrinfo(ai);
110+ return -1;
111+ }
112+
113+ freeaddrinfo(ai);
114+#else
115+ struct hostent *he;
116+ static GStaticMutex gh_mutex = G_STATIC_MUTEX_INIT;
117+
118+ g_static_mutex_lock(&gh_mutex);
119
120 he = gethostbyname(address);
121-
122- if (NULL == he) {
123+ if (NULL == he) {
124+ g_static_mutex_unlock(&gh_mutex);
125 return -1;
126 }
127
128@@ -103,13 +150,15 @@
129 g_assert(he->h_length == sizeof(struct in_addr));
130
131 memcpy(&(addr->addr.ipv4.sin_addr.s_addr), he->h_addr_list[0], he->h_length);
132+ g_static_mutex_unlock(&gh_mutex);
133+ addr->addr.ipv4.sin_family = AF_INET;
134+#endif /* HAVE_GETADDRINFO */
135 }
136
137- addr->addr.ipv4.sin_family = AF_INET;
138 addr->addr.ipv4.sin_port = htons(port);
139 addr->len = sizeof(struct sockaddr_in);
140
141- network_address_refresh_name(addr);
142+ (void) network_address_refresh_name(addr);
143
144 return 0;
145 }

Subscribers

People subscribed via source and target branches