summaryrefslogtreecommitdiff
path: root/www/mozilla/patches/patch-ax
blob: 5bf0d63e0920177cbe07b202afca9dc6a29abd94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
$NetBSD: patch-ax,v 1.6 2001/12/27 15:02:41 taya Exp $

diff -ru ../Orig/mozilla/netwerk/base/src/nsSocketTransport.cpp ./netwerk/base/src/nsSocketTransport.cpp
--- ../Orig/mozilla/netwerk/base/src/nsSocketTransport.cpp	Tue Dec  4 11:47:19 2001
+++ ./netwerk/base/src/nsSocketTransport.cpp	Sat Dec 22 13:02:36 2001
@@ -186,8 +186,7 @@
     //
     // Set up Internet defaults...
     //
-    memset(&mNetAddress, 0, sizeof(mNetAddress));
-    PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET6, 0, &mNetAddress);
+    mNetAddressList = nsnull;
     
     //
     // Initialize the global connect timeout value if necessary...
@@ -236,6 +235,13 @@
         nsAutoMonitor::DestroyMonitor(mMonitor);
         mMonitor = nsnull;
     }
+
+    nsNetAddrList *p, *next;
+    for (p = mNetAddressList; p; ){
+        next = p->next;
+        delete p;
+        p = next;
+    }
 }
 
 
@@ -640,15 +646,7 @@
     //
     // The hostname has not been resolved yet...
     //
-    if (PR_IsNetAddrType(&mNetAddress, PR_IpAddrAny)) {
-        //
-        // Initialize the port used for the connection...
-        //
-        // XXX: The list of ports must be restricted - see net_bad_ports_table[] in 
-        //      mozilla/network/main/mkconect.c
-        //
-        mNetAddress.ipv6.port = PR_htons(((mProxyPort != -1 && !mProxyTransparent) ? mProxyPort : mPort));
-
+    if (mNetAddressList == nsnull) {
         PR_ExitMonitor(mMonitor);
 
         nsIDNSService* pDNSService = mService->GetCachedDNSService();
@@ -673,7 +671,7 @@
             //
             // The DNS lookup has finished...  It has either failed or succeeded.
             //
-            if (NS_FAILED(mStatus) || !PR_IsNetAddrType(&mNetAddress, PR_IpAddrAny)) {
+            if (NS_FAILED(mStatus) || mNetAddressList) {
                 mDNSRequest = 0;
                 rv = mStatus;
             } 
@@ -833,7 +831,8 @@
         //    This is only done the first time doConnection(...) is called.
         //
         if (NS_SUCCEEDED(rv)) {
-            status = PR_Connect(mSocketFD, &mNetAddress, gConnectTimeout);
+try_again:
+            status = PR_Connect(mSocketFD, &(mNetAddressList->addr), gConnectTimeout);
             if (PR_SUCCESS != status) {
                 PRErrorCode code = PR_GetError();
                 //
@@ -858,6 +857,12 @@
                 //
                 else {
                     // Connection refused...
+                    nsNetAddrList *p = mNetAddressList;
+                    mNetAddressList = mNetAddressList->next;
+                    delete p;
+                    if (mNetAddressList){
+                        goto try_again;
+                    }
                     LOG(("nsSocketTransport: Connection Refused [%s:%d %x].  PRErrorCode = %x\n",
                         mHostName, mPort, this, code));
                     rv = NS_ERROR_CONNECTION_REFUSED;
@@ -871,11 +876,23 @@
     //
     else if (aSelectFlags) {
         if (PR_POLL_EXCEPT & aSelectFlags) {
+            nsNetAddrList *p = mNetAddressList;
+            mNetAddressList = mNetAddressList->next;
+            delete p;
+            if (mNetAddressList){
+                goto try_again;
+            }
             LOG(("nsSocketTransport: Connection Refused via PR_POLL_EXCEPT. [%s:%d %x].\n", 
                 mHostName, mPort, this));
             rv = NS_ERROR_CONNECTION_REFUSED;
         }
         else if (PR_POLL_HUP & aSelectFlags) {
+            nsNetAddrList *p = mNetAddressList;
+            mNetAddressList = mNetAddressList->next;
+            delete p;
+            if (mNetAddressList){
+                goto try_again;
+            }
             LOG(("nsSocketTransport: Connection Refused via PR_POLL_HUP. [%s:%d %x].\n", 
                 mHostName, mPort, this));
             rv = NS_ERROR_CONNECTION_REFUSED;
@@ -918,7 +935,7 @@
     //
     // The hostname has not been resolved yet...
     //
-    if (PR_IsNetAddrType(&mNetAddress, PR_IpAddrAny)) {
+    if (mNetAddressList == nsnull) {
         nsIDNSService* pDNSService = mService->GetCachedDNSService();
         if (!pDNSService) {
             return NS_ERROR_UNEXPECTED;
@@ -939,16 +956,18 @@
             return NS_ERROR_FAILURE;
         }
 
+        mNetAddressList = new nsNetAddrList;
+        mNetAddressList->next = nsnull;
         if (addr.raw.family == PR_AF_INET)
-            PR_ConvertIPv4AddrToIPv6(addr.inet.ip, &mNetAddress.ipv6.ip);
+            PR_ConvertIPv4AddrToIPv6(addr.inet.ip, &(mNetAddressList->addr.ipv6.ip));
         else
-            memcpy(&mNetAddress.ipv6.ip, &addr.ipv6.ip, sizeof(mNetAddress.ipv6.ip));
+            memcpy(&(mNetAddressList->addr.ipv6.ip), &addr.ipv6.ip, sizeof(mNetAddressList->addr.ipv6.ip));
 
-        mNetAddress.ipv6.port
+        mNetAddressList->addr.ipv6.port
             = PR_htons(((mProxyPort != -1 && !mProxyTransparent) ? mProxyPort : mPort));
 
         LOG(("address { family=%hu, port=%hu }\n",
-            mNetAddress.ipv6.family, PR_ntohs(mNetAddress.ipv6.port)));
+            mNetAddressList->addr.ipv6.family, PR_ntohs(mNetAddressList->addr.ipv6.port)));
     }
 
     //
@@ -1470,21 +1489,27 @@
     // Enter the socket transport lock...
     nsAutoMonitor mon(mMonitor);
     nsresult rv = NS_OK;
+    char **p;
+    nsNetAddrList **addrp = &mNetAddressList;
 
     if (aHostEnt->hostEnt.h_addr_list && aHostEnt->hostEnt.h_addr_list[0]) {
-        if (aHostEnt->hostEnt.h_addrtype == PR_AF_INET6)
-            memcpy(&mNetAddress.ipv6.ip, aHostEnt->hostEnt.h_addr_list[0], sizeof(mNetAddress.ipv6.ip));
-        else
-            PR_ConvertIPv4AddrToIPv6(*(PRUint32*)aHostEnt->hostEnt.h_addr_list[0], &mNetAddress.ipv6.ip);
+        for (p = aHostEnt->hostEnt.h_addr_list; *p; p++){
+            *addrp = new nsNetAddrList;
+            (*addrp)->next = nsnull;
+            (*addrp)->addr.ipv6.port = PR_htons(((mProxyPort != -1 && !mProxyTransparent) ? mProxyPort : mPort));
+            (*addrp)->addr.raw.family = PR_AF_INET6;
+            memcpy(&((*addrp)->addr.ipv6.ip), *p, sizeof((*addrp)->addr.ipv6.ip));
 #if defined(PR_LOGGING)
-        char addrbuf[50];
-        PR_NetAddrToString(&mNetAddress, addrbuf, sizeof(addrbuf));
-        LOG(("nsSocketTransport: OnFound(...) [%s:%d %x]."
-            "  DNS lookup succeeded => %s (%s)\n",
-            mHostName, mPort, this,
-            aHostEnt->hostEnt.h_name,
-            addrbuf));
+            char addrbuf[50];
+            PR_NetAddrToString(&((*addrp)->addr), addrbuf, sizeof(addrbuf));
+            LOG(("nsSocketTransport: OnFound(...) [%s:%d %x]."
+              "  DNS lookup succeeded => %s (%s)\n",
+              mHostName, mPort, this,
+              aHostEnt->hostEnt.h_name,
+              addrbuf));
 #endif
+            addrp = &((*addrp)->next);
+        }
     } else {
         // XXX: What should happen here?  The GetHostByName(...) succeeded but 
         //      there are *no* A records...
@@ -1517,7 +1542,7 @@
     // If the lookup failed, set the status...
     if (NS_FAILED(aStatus))
         mStatus = aStatus;
-    else if (PR_IsNetAddrType(&mNetAddress, PR_IpAddrAny))
+    else if (mNetAddressList == nsnull)
         mStatus = NS_ERROR_ABORT;
 
     // Start processing the transport again - if necessary...
@@ -1838,7 +1863,7 @@
     *_retval = (char*)nsMemory::Alloc(aLen);
     if (!*_retval) return NS_ERROR_FAILURE;
 
-    PRStatus status = PR_NetAddrToString(&mNetAddress, *_retval, aLen);
+    PRStatus status = PR_NetAddrToString(&mNetAddressList->addr, *_retval, aLen);
 
     if (PR_FAILURE == status) {
         nsMemory::Free(*_retval);