Bug Tracker – Attachment #237: Probable fix for localhost connect issue for bug #587

View | Details | Raw Unified | Return to bug 587
Collapse All | Expand All

(-)common/i_net.cpp (-2 / +38 lines)
Lines 114-119 Link Here
114
lzo_byte wrkmem[LZO1X_1_MEM_COMPRESS];
114
lzo_byte wrkmem[LZO1X_1_MEM_COMPRESS];
115
115
116
EXTERN_CVAR(port)
116
EXTERN_CVAR(port)
117
EXTERN_CVAR(sv_bindaddress)
117
118
118
msg_info_t clc_info[clc_max];
119
msg_info_t clc_info[clc_max];
119
msg_info_t svc_info[svc_max];
120
msg_info_t svc_info[svc_max];
Lines 132-137 Link Here
132
133
133
	return s;
134
	return s;
134
}
135
}
136
void NetadrToSockadr (netadr_t *a, struct sockaddr_in *s);
137
void SockadrToNetadr (struct sockaddr_in *s, netadr_t *a);
135
138
136
//
139
//
137
// BindToLocalPort
140
// BindToLocalPort
Lines 139-149 Link Here
139
void BindToLocalPort (SOCKET s, u_short wanted)
142
void BindToLocalPort (SOCKET s, u_short wanted)
140
{
143
{
141
	int v;
144
	int v;
145
	struct hostent* h;
142
	struct sockaddr_in address;
146
	struct sockaddr_in address;
147
	netadr_t na;
143
148
144
	memset (&address, 0, sizeof(address));
149
	memset (&address, 0, sizeof(address));
145
	address.sin_family = AF_INET;
150
	address.sin_family = AF_INET;
146
	address.sin_addr.s_addr = INADDR_ANY;
151
	// GhostlyDeath <July 3, 2010> -- Bind to local IP
152
	// [tm512] -- jan 14 2011 -- Don't use this if we're on Windows
153
	#ifndef _WIN32
154
	if (serverside)
155
	{
156
		// Just use our existing function
157
		if (!NET_StringToAdr(sv_bindaddress.cstring(), &na))
158
			address.sin_addr.s_addr = INADDR_ANY;   // Failure
159
		else
160
			NetadrToSockadr(&na, &address);
161
	}
162
	else    // Client should use any address
163
	#endif
164
		address.sin_addr.s_addr = INADDR_ANY;
165
147
	u_short next = wanted;
166
	u_short next = wanted;
148
167
149
	// denis - try several ports
168
	// denis - try several ports
Lines 153-158 Link Here
153
172
154
		v = bind (s, (sockaddr *)&address, sizeof(address));
173
		v = bind (s, (sockaddr *)&address, sizeof(address));
155
174
175
		// GhostlyDeath <July 3, 2010> -- Fallback to any address
176
		#ifndef _WIN32
177
		if (address.sin_addr.s_addr != INADDR_ANY && (errno == EACCES || errno == EADDRNOTAVAIL))
178
		{
179
			Printf (PRINT_HIGH, "BindToLocalPort: %s\n", strerror(errno));
180
			next--;
181
			address.sin_addr.s_addr = INADDR_ANY;
182
			continue;
183
		}
184
		#endif
185
156
		if(next > wanted + 16)
186
		if(next > wanted + 16)
157
		{
187
		{
158
			I_FatalError ("BindToPort: error");
188
			I_FatalError ("BindToPort: error");
Lines 164-170 Link Here
164
	sprintf(tmp, "%d", next - 1);
194
	sprintf(tmp, "%d", next - 1);
165
	port.ForceSet(tmp);
195
	port.ForceSet(tmp);
166
196
167
	Printf(PRINT_HIGH, "Bound to local port %d\n", next - 1);
197
	if (address.sin_addr.s_addr == INADDR_ANY)
198
		Printf(PRINT_HIGH, "Bound to local port %d\n", next - 1);
199
	else
200
	{
201
		SockadrToNetadr(&address, &na);
202
		Printf(PRINT_HIGH, "Bound to local address %s\n", NET_AdrToString(na));
203
	}
168
}
204
}
169
205
170
206
(-)common/c_cvarlist.cpp (+2 lines)
Lines 70-75 Link Here
70
CVAR (sv_speedhackfix,		"0", CVAR_SERVERARCHIVE | CVAR_SERVERINFO)
70
CVAR (sv_speedhackfix,		"0", CVAR_SERVERARCHIVE | CVAR_SERVERINFO)
71
// Weapons stay
71
// Weapons stay
72
CVAR (sv_weaponstay,		"1", CVAR_SERVERARCHIVE | CVAR_SERVERINFO | CVAR_LATCH)
72
CVAR (sv_weaponstay,		"1", CVAR_SERVERARCHIVE | CVAR_SERVERINFO | CVAR_LATCH)
73
// GhostlyDeath <July 3, 2010> -- Bind to host
74
CVAR (sv_bindaddress, "ANY", CVAR_SERVERARCHIVE | CVAR_NOENABLEDISABLE)
73
75
74
// Compatibility options for vanilla
76
// Compatibility options for vanilla
75
// ---------------------------------
77
// ---------------------------------

Return to bug 587