2
Description: Fixes connecting odbcserver back to Erlang VM in IPv6-only
4
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=598525
6
Last-updated: Sun, 14 Nov 2010 12:20:41 +0300
8
--- erlang-14.a-dfsg.orig/lib/odbc/src/odbc.erl
9
+++ erlang-14.a-dfsg/lib/odbc/src/odbc.erl
10
@@ -441,10 +441,12 @@ init(Args) ->
12
{ok, ListenSocketSup} =
13
gen_tcp:listen(0, [Inet, binary, {packet, ?LENGTH_INDICATOR_SIZE},
14
- {active, false}, {nodelay, true}]),
15
+ {active, false}, {nodelay, true},
17
{ok, ListenSocketOdbc} =
18
gen_tcp:listen(0, [Inet, binary, {packet, ?LENGTH_INDICATOR_SIZE},
19
- {active, false}, {nodelay, true}]),
20
+ {active, false}, {nodelay, true},
23
%% Start the port program (a c program) that utilizes the odbc driver
24
case os:find_executable(?SERVERPROG, ?SERVERDIR) of
25
--- erlang-14.a-dfsg.orig/lib/odbc/c_src/odbcserver.c
26
+++ erlang-14.a-dfsg/lib/odbc/c_src/odbcserver.c
27
@@ -1727,74 +1727,48 @@ static byte * receive_erlang_port_msg(void)
30
/* ------------- Socket communication functions --------------------------*/
36
-#if defined WIN32 || defined USE_IPV4
37
-/* Currently only an old windows compiler is supported so we do not have ipv6
40
static SOCKET connect_to_erlang(const char *port)
43
- struct sockaddr_in sin;
45
- sock = socket(AF_INET, SOCK_STREAM, 0);
47
- memset(&sin, 0, sizeof(sin));
48
- sin.sin_port = htons ((unsigned short)atoi(port));
49
- sin.sin_family = AF_INET;
50
- sin.sin_addr.s_addr = inet_addr("127.0.0.1");
52
- if (connect(sock, (struct sockaddr*)&sin, sizeof(sin)) != 0) {
54
- DO_EXIT(EXIT_SOCKET_CONNECT);
59
static int connect_to_erlang(const char *port)
64
- struct addrinfo hints;
65
- struct addrinfo *erlang_ai, *first;
67
- memset(&hints, 0, sizeof(hints));
68
- hints.ai_family = PF_UNSPEC; /* PF_INET or PF_INET6 */
69
- hints.ai_socktype = SOCK_STREAM;
70
- hints.ai_protocol = IPPROTO_TCP;
72
- if (getaddrinfo("localhost", port, &hints, &first) != 0) {
73
- DO_EXIT(EXIT_FAILURE);
80
+ struct sockaddr_in sin;
82
+#if defined(AF_INET6)
83
+ struct sockaddr_in6 sin6;
85
+ sock = socket(AF_INET6, SOCK_STREAM, 0);
87
+ memset(&sin6, 0, sizeof(sin6));
88
+ sin6.sin6_port = htons ((unsigned short)atoi(port));
89
+ sin6.sin6_family = AF_INET6;
90
+ sin6.sin6_addr = in6addr_loopback;
92
- for (erlang_ai = first; erlang_ai; erlang_ai = erlang_ai->ai_next) {
93
+ if (connect(sock, (struct sockaddr*)&sin6, sizeof(sin6)) == 0) {
98
+ sock = socket(AF_INET, SOCK_STREAM, 0);
100
+ memset(&sin, 0, sizeof(sin));
101
+ sin.sin_port = htons ((unsigned short)atoi(port));
102
+ sin.sin_family = AF_INET;
103
+ sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
105
- sock = socket(erlang_ai->ai_family, erlang_ai->ai_socktype,
106
- erlang_ai->ai_protocol);
109
- if (connect(sock, (struct sockaddr*)erlang_ai->ai_addr,
110
- erlang_ai->ai_addrlen) < 0) {
116
+ if (connect(sock, (struct sockaddr*)&sin, sizeof(sin)) != 0) {
117
+ close_socket(sock);
118
+ DO_EXIT(EXIT_SOCKET_CONNECT);
121
- freeaddrinfo(first);
124
- close_socket(sock);
125
- DO_EXIT(EXIT_SOCKET_CONNECT);
134
static void close_socket(SOCKET socket)