Exemple #1
0
int SetupSSMPing() {
	address addr(beaconUnicastAddr.family());

	if (!addr.set_port(4321))
		return -1;

	ssmPingSocket = SetupSocket(addr, true, false);
	if (ssmPingSocket < 0)
		return -1;

	if (!SetHops(ssmPingSocket, addr, 64)) {
		close(ssmPingSocket);
		return -1;
	}

	if (!RequireToAddress(ssmPingSocket, addr)) {
		close(ssmPingSocket);
		return -1;
	}

	assert(SSMPingV4Addr.set_addr(SSMPingV4ResponseChannel));
	assert(SSMPingV6Addr.set_addr(SSMPingV6ResponseChannel));

	ListenTo(ssmPingSocket, handle_ssmping);

	return 0;
}
Exemple #2
0
WebSocketWorker::WebSocketWorker(WebSocketServer& webSocketServer,
                                 qt_socket_fd_t sock, PoolServerType type
#ifndef QT_NO_OPENSSL
                                 , QSslConfiguration sslConfig
#endif
                                 )
                : m_eventLoop(new QEventLoop()),
                  m_webSocketServer(webSocketServer),
                  m_socketFD(sock), m_socket(nullptr),
                  m_connectionType(type), m_webSocketMode(false),
                  m_errorCount(0), m_isRunning(false),
                  m_heartBeat(new QTimer()),
#ifndef QT_NO_OPENSSL
                  m_sslConfig(sslConfig),
#endif
                  m_fuzzTesting(false)
{
    setObjectName(QString("WebSocketWorker(%1)")
                        .arg(m_socketFD));
    LOG(VB_HTTP, LOG_INFO, QString("WebSocketWorker(%1): New connection")
                                        .arg(m_socketFD));

    // For now, until it's refactored, register the only extension here
    RegisterExtension(new WebSocketMythEvent());

    SetupSocket();

    m_isRunning = true;
}
Exemple #3
0
void SocketServer::RunListener()
{
    std::cout << "Initializing server on port " << c_port << std::endl;
    SetupSocket();
    
    std::cout << "Waiting for connections..." << std::endl;
    while (m_isRunning)
    {
        AcceptConnection();
    }

    std::cout << "Socket closed by SocketServer." << std::endl;
}
void F2M_MinerConnection::Disconnect()
{
    if( mConnectionState != F2M_MinerConnection::Disconnected )
    {
        // close the connection
        SOCKET_CLOSE(mSocket);
        
        // Reset socket to be used again
        SetupSocket();

        // Change state
        mConnectionState = F2M_MinerConnection::Disconnected;
    }
}
F2M_MinerConnection::F2M_MinerConnection(unsigned int hashChunkSize, const char* agent, const char* platform, const char* location)
{
    mWorkBlock = 0;

    mHashChunkSize = hashChunkSize;
    mAgent = agent;
    mPlatform = platform;
    mLocation = location;
    mStopWork = false;

    // Starup network subsystem
    F2M_NetInit();

    // Initially set connection state to disconnected
    mConnectionState = F2M_MinerConnection::Disconnected;

    // Create the underlying socket
    SetupSocket();
}
void main(void)
{
    svr_fd = SetupSocket();
    accept_loop(svr_fd);
}
Exemple #7
0
// Creates a PosixNetworkInterface for the interface whose IP address is
// intfAddr and whose name is intfName and registers it with mDNS core.
static int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, const char *intfName)
	{
	int err = 0;
	PosixNetworkInterface *intf;
	PosixNetworkInterface *alias = NULL;

	assert(m != NULL);
	assert(intfAddr != NULL);
	assert(intfName != NULL);

	// Allocate the interface structure itself.
	intf = malloc(sizeof(*intf));
	if (intf == NULL) { assert(0); err = ENOMEM; }

	// And make a copy of the intfName.
	if (err == 0)
		{
		intf->intfName = strdup(intfName);
		if (intf->intfName == NULL) { assert(0); err = ENOMEM; }
		}

	if (err == 0)
		{
		// Set up the fields required by the mDNS core.
		SockAddrTomDNSAddr(intfAddr, &intf->coreIntf.ip, NULL);
		intf->coreIntf.Advertise = m->AdvertiseLocalAddresses;
		intf->coreIntf.TxAndRx   = mDNStrue;

		// Set up the extra fields in PosixNetworkInterface.
		assert(intf->intfName != NULL);         // intf->intfName already set up above
		intf->index                = if_nametoindex(intf->intfName);
		intf->multicastSocket      = -1;
		intf->multicastSocketv6    = -1;
		alias                      = SearchForInterfaceByName(m, intf->intfName);
		if (alias == NULL) alias   = intf;
		intf->coreIntf.InterfaceID = (mDNSInterfaceID)alias;

		if (alias != intf)
			debugf("SetupOneInterface: %s %#a is an alias of %#a", intfName, &intf->coreIntf.ip, &alias->coreIntf.ip);
		}

	// Set up the multicast socket
	if (err == 0)
		{
		if (alias->multicastSocket == -1 && intfAddr->sa_family == AF_INET)
			err = SetupSocket(intfAddr, MulticastDNSPort, intf->index, &alias->multicastSocket);
#ifdef mDNSIPv6Support
		else if (alias->multicastSocketv6 == -1 && intfAddr->sa_family == AF_INET6)
			err = SetupSocket(intfAddr, MulticastDNSPort, intf->index, &alias->multicastSocketv6);
#endif
		}

	// The interface is all ready to go, let's register it with the mDNS core.
	if (err == 0)
		err = mDNS_RegisterInterface(m, &intf->coreIntf);

	// Clean up.
	if (err == 0)
		{
		num_registered_interfaces++;
		debugf("SetupOneInterface: %s %#a Registered", intf->intfName, &intf->coreIntf.ip);
		if (gMDNSPlatformPosixVerboseLevel > 0)
			fprintf(stderr, "Registered interface %s\n", intf->intfName);
		}
	else
		{
		// Use intfName instead of intf->intfName in the next line to avoid dereferencing NULL.
		debugf("SetupOneInterface: %s %#a failed to register %d", intfName, &intf->coreIntf.ip, err);
		if (intf) { FreePosixNetworkInterface(intf); intf = NULL; }
		}

	assert( (err == 0) == (intf != NULL) );

	return err;
	}