MCPcopy Create free account
hub / github.com/MaxBelkov/visualsyslog / Open

Method Open

sourcecommon/tcpserv.cpp:275–348  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

273}
274//---------------------------------------------------------------------------
275bool MTCPServer::Open(char * local, WORD lport)
276{
277 Error = 0;
278 if( handle || !local ) { Error = 1; if( Exceptions ) throw 0; return !Error; }
279 // �� ��������� ����� ���������� ��������� ����� � 10000
280 //if( !lport ) lport = localport++;
281
282 errcode = 0;
283 in_addr l;
284 l.S_un.S_addr = inet_addr(local);
285 if( l.S_un.S_addr==4294967295 ) // host name OR error in IP address
286 {
287 // try to resolve host name and copy to l
288 HOSTENT * hostent = gethostbyname(local);
289 if( hostent )
290 {
291 // hostent->h_name ---> Full local name
292 l.S_un = ((in_addr *)hostent->h_addr_list[0])->S_un;
293 }
294 else
295 {
296 //l.S_un.S_addr = INADDR_ANY; // ��������� ����� ����� ���� �������
297 errcode = WSAGetLastError();
298 Error = 2;
299 if( Exceptions ) throw 0; return !Error;
300 }
301 }
302 SOCKET h;
303 //
304 // Open a TCP socket
305 // h = socket(AF_INET, SOCK_DGRAM, 0);
306 h = socket(AF_INET, SOCK_STREAM, 0);
307 if( h==INVALID_SOCKET)
308 {
309 errcode = WSAGetLastError();
310 Error = 4;
311 }
312 if( Error ) { if( Exceptions ) throw 0; return !Error; }
313 //
314 // Bind our server to the agreed upon port number. See commdef.h for the actual port number
315 memset(&localAddr, 0, sizeof(localAddr));
316 localAddr.sin_family = AF_INET;
317 localAddr.sin_port = htons(lport);
318 localAddr.sin_addr = l;
319 /*
320 WriteToLogMT("S\tOpen(\"%s\" %u.%u.%u.%u:%u",
321 local,
322 l.S_un.S_un_b.s_b1,
323 l.S_un.S_un_b.s_b2,
324 l.S_un.S_un_b.s_b3,
325 l.S_un.S_un_b.s_b4,
326 lport);
327 */
328 if( bind(h, (struct sockaddr *)&localAddr, sizeof(localAddr)) )
329 {
330 errcode = WSAGetLastError();
331 Error = 5;
332 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected