Ejemplo n.º 1
0
void CSocketControl::setSocket(char* inputString)
{
  if (inputString == 0) return;
  uint8_t len = strlen(inputString);
  if (len < 2 || len > 10) return;
  // interpret commands
  if (!strcmp(inputString, "alloff"))
    for (int i = 1; i <= 4; i++)
      setSocket(i, 1);
    else
      if (!strcmp(inputString, "allon"))
        for (int i = 1; i <= 4; i++)
          setSocket(i, 0);
      else
        if (!strcmp(inputString, "looptest"))
          test_loop();
        else
        {
          uint8_t socket = 9;
          uint8_t state = 0;
          
          socket = inputString[0] - 48;
          state = inputString[1] - 49;
        
          setSocket(socket, state);
        }
}
Ejemplo n.º 2
0
ClientSocket::ClientSocket( int sock, InfoData *i, QObject *parent, const char *name ) :
    QSocket( parent, name ), info( i )
{
    connect( this, SIGNAL(readyRead()), SLOT(readClient()) );
    connect( this, SIGNAL(connectionClosed()), SLOT(connectionClosed()) );
    setSocket( sock );
}
Ejemplo n.º 3
0
void ProtocolSocket::socketDisconnected()
{
    if (!m_socket)
        return;

    setSocket(0);
}
Ejemplo n.º 4
0
QXmppIncomingClient::QXmppIncomingClient (QSslSocket *socket, const QString &domain, QObject *parent)
    : QXmppStream (parent)
{
    bool check;
    Q_UNUSED (check);

    d = new QXmppIncomingClientPrivate (this);
    d->domain = domain;

    if (socket)
    {
        check = connect (socket, SIGNAL (disconnected()),
                         this, SLOT (onSocketDisconnected()));
        Q_ASSERT (check);

        setSocket (socket);
    }

    info (QString ("Incoming client connection from %1").arg (d->origin()));

    // create inactivity timer
    d->idleTimer = new QTimer (this);
    d->idleTimer->setSingleShot (true);
    check = connect (d->idleTimer, SIGNAL (timeout()),
                     this, SLOT (onTimeout()));
    Q_ASSERT (check);
}
MMulticastSocketDevice::MMulticastSocketDevice(
    QString sAddress, quint16 nPort, u_char ttl) :
    MSocketDevice(MSocketDevice::Datagram),
    m_address(sAddress), m_port(nPort)
{
#if 0
    ttl = UPnp::GetConfiguration()->GetValue( "UPnP/TTL", 4 );
#endif

    if (ttl == 0)
        ttl = 4;

    setProtocol(IPv4);
    setSocket(createNewSocket(), MSocketDevice::Datagram);

    m_imr.imr_multiaddr.s_addr = inet_addr(sAddress.toLatin1().constData());
    m_imr.imr_interface.s_addr = htonl(INADDR_ANY);

    if (setsockopt(socket(), IPPROTO_IP, IP_ADD_MEMBERSHIP,
                   (const char *)&m_imr, sizeof( m_imr )) < 0)
    {
        LOG(VB_GENERAL, LOG_ERR, LOC + "setsockopt - IP_ADD_MEMBERSHIP " + ENO);
    }

    if (setsockopt(socket(), IPPROTO_IP, IP_MULTICAST_TTL,
                   (const char *)&ttl, sizeof(ttl)) < 0)
    {
        LOG(VB_GENERAL, LOG_ERR, LOC + "setsockopt - IP_MULTICAST_TTL " + ENO);
    }

    setAddressReusable(true);

    if (!bind(m_address, m_port))
        LOG(VB_GENERAL, LOG_ERR, LOC + "bind failed");
}
Ejemplo n.º 6
0
void createNode(clientNode ** head, int sock, int * size) {
	clientNode * node =	NULL;
	if (*head == NULL) {
		node = NULL;
	} else {
		node = *head;
	}
	
	
	if (node == NULL) {
		node =			malloc(sizeof(clientNode));
		setSocket(&(node->client), sock);
		setActive(&(node->client), TRUE);
		node->client.name = NULL;
		node->next =	NULL;
		node->prev =	NULL;
		(*size)++;
		*head = node;
	} else {
		createNode(&((*head)->prev->next), sock, size);
		(*head)->prev->next->prev = (*head)->prev;
		(*head)->prev =	node->prev->next;
	}//END IF
	
}//END FUNCTION
Ejemplo n.º 7
0
bool MinosServerConnection::ioConnect ( const std::string &server, int port )
{
   int sock = -1;
   int tmp;
   struct hostent *host;
   struct sockaddr_in sin;

   host = gethostbyname ( server.c_str() );
   if ( !host )
      return false;

   memcpy ( &sin.sin_addr, host->h_addr, host->h_length );
   sin.sin_family = host->h_addrtype;
   sin.sin_port = htons ( port );

   sock = socket ( host->h_addrtype, SOCK_STREAM, 0 );
   if ( sock == -1 )
      return false;

   tmp = connect ( sock, ( struct sockaddr * ) & sin, sizeof ( struct sockaddr_in ) );
   if ( tmp != 0 )
   {
      closesocket( sock );
      return false;
   }

   setSocket( sock );
   txConnection = true;

   return true;
}
Ejemplo n.º 8
0
void SpyMini::connectToTank(){
	WSADATA wsa;
	SOCKET s;
	struct sockaddr_in server;
	if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
	{
		printf("Failed. Error Code : %d", WSAGetLastError());
		return;
	}
	//Create a socket
	if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
	{
		printf("Could not create socket : %d", WSAGetLastError());
	}

	printf("Socket created.\n");

	server.sin_addr.s_addr = inet_addr("10.10.1.1");
	server.sin_family = AF_INET;
	server.sin_port = htons(8150);
	//Connect to remote server
	if (connect(s, (struct sockaddr *)&server, sizeof(server)) < 0)
	{
		puts("connect error");
		return;
	}
	puts("Connected");
	setSocket(s);
	
}
Ejemplo n.º 9
0
      // Client constructor.
      secureHttpTransport::secureHttpTransport(LogWrapperType _logwrapper,
                                               btg::core::externalization::Externalization* _e,
                                               btg::core::os::gtlsClientData* _gcd,
                                               t_int const _bufferSize,
                                               DIRECTION const _direction,
                                               addressPort const & _addressPort,
                                               t_uint const _timeout)
         : httpTransport(_logwrapper, _e, _bufferSize, _direction, _addressPort, false, _timeout)
      {
         try
            {
               btg::core::os::SecureClientSocket* tempClient =
                  new btg::core::os::SecureClientSocket(logWrapper(),
                                                        _gcd, 
                                                        _addressPort.getIp(), 
                                                        _addressPort.getPort()
                                                        );

               // When calling the httpTransport initializer we
               // created a ClientSocket. This will be deleted in
               // this setSocket call.
               setSocket(tempClient);

            }
         catch (btg::core::os::socketException& _se)
            {
               initialized = false;
#if BTG_TRANSPORT_DEBUG
               BTG_NOTICE(logWrapper(), "Failed to init client: " << _se.description());
#endif // BTG_TRANSPORT_DEBUG
            }
      }
Ejemplo n.º 10
0
ConfigInterface::ConfigInterface(const std::string &sockfile, const LogSink &logInstance) : ConnectionTCPServer(this, logInstance, "localhost", -1) {
	// Create UNIX socket
	int m_socket;
	socklen_t length;
	struct sockaddr_un local;
	m_loaded = false;
	m_socketId = 0;
	
	m_admin = new AdhocAdmin();
	registerHandler(m_admin);
	
	if ((m_socket = getUnixSocket()) == -1)
		Log("ConfigInterface", "Could not create UNIX socket: " << strerror(errno));
	
	local.sun_family = AF_UNIX;
	
	strcpy(local.sun_path, sockfile.c_str());
	unlink(local.sun_path);
	
	length = offsetof(struct sockaddr_un, sun_path) + strlen(sockfile.c_str());

	if (bind(m_socket, (struct sockaddr *) &local, length) == -1) {
		Log("ConfigInterface", "Could not bind to UNIX socket: " << sockfile << " " << strerror(errno));
		return;
	}
	
	if (listen(m_socket, 5) == -1) {
		Log("ConfigInterface", "Could not listen to UNIX socket: " << sockfile << " " << strerror(errno));
		return;
	}

	setSocket(m_socket);
	m_socketId = purple_input_add(m_socket, PURPLE_INPUT_READ, gotData, this);
	m_loaded = true;
}
Ejemplo n.º 11
0
      // Server constructor.
      secureHttpTransport::secureHttpTransport(LogWrapperType _logwrapper,
                                               btg::core::externalization::Externalization* _e,
                                               btg::core::os::gtlsGlobalServerData* _ggsd,
                                               t_int const _bufferSize,
                                               DIRECTION const _direction,
                                               addressPort const & _addressPort,
                                               t_uint const _timeout)
         : httpTransport(_logwrapper, _e, _bufferSize, _direction, _addressPort, false, _timeout)
      {
         try
            {
               btg::core::os::SecureServerSocket* tempServer =
                  new btg::core::os::SecureServerSocket(logWrapper(),
                                                        _ggsd,
                                                        _addressPort.getIp(),
                                                        _addressPort.getPort());

               setSocket(tempServer);
            }
         catch (btg::core::os::socketException& _se)
            {
               initialized = false;
#if BTG_TRANSPORT_DEBUG
               BTG_NOTICE(logWrapper(), "Failed to init server: " << _se.description() );
#endif // BTG_TRANSPORT_DEBUG
            }
      }
void CommunicationTcpSocketServer::newConnection()
{
    QTcpSocket *newSocket = serverSocket.nextPendingConnection();
    if (newSocket)
    {
        if (newSocket->isOpen()) {
            connect(newSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
        }
        setSocket(newSocket);
        qWarning() << "Új kapcsolat létesült.\n";


        QByteArray ba;
        ba[0]=0x00;
        ba[1]=0x55;
        ba[2]=100;
        ba[3]=122;
        send(ba);

        ba[0]=0x00;
        ba[1]=0xAA;
        ba[2]=128;
        ba[3]=14;
        send(ba);

        ba[0]=0x00;
        ba[1]=0xCB;
        ba[2]=15;
        ba[3]=192;
        send(ba);

    }
}
Ejemplo n.º 13
0
int eServerSocket::startListening(struct addrinfo *addr)
{
	struct addrinfo *ptr = addr;
	for (ptr = addr; ptr != NULL; ptr = ptr->ai_next)
	{
		if (setSocket(socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol), 1) < 0)
		{
			continue;
		}

		int val = 1;
		setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));

		if (bind(getDescriptor(), ptr->ai_addr, ptr->ai_addrlen) < 0)
		{
			eDebug("[eServerSocket] ERROR on bind: %m");
			close();
			continue;
		}
	}

	if (getDescriptor() < 0)
	{
		return -1;
	}

	if (listen(getDescriptor(), 0) < 0)
	{
		close();
		return -1;
	}
	return 0;
}
Ejemplo n.º 14
0
//! \brief Creates a Connecting Peer
Peer::Peer(PeerWireSocket *socket)
    : address(socket->getPeerAddress()), port(socket->getPeerPort()), socket(0),
      state(UnconnectedState), suspended(false)
{
    setSocket(socket);
    setState(ConnectingState);
}
Ejemplo n.º 15
0
NetworkLink::NetworkLink(QTcpSocket *socket)
    : QObject(NULL),m_mainWindow(NULL)
{
    m_mainWindow = MainWindow::getInstance();
    m_networkManager = m_mainWindow->getNetWorkManager();
    m_socketTcp = socket;
    receptionEnCours = false;
	ReceiveEvent::registerNetworkReceiver(NetMsg::PictureCategory,m_mainWindow);
    ReceiveEvent::registerNetworkReceiver(NetMsg::MapCategory,m_mainWindow);
    ReceiveEvent::registerNetworkReceiver(NetMsg::NPCCategory,m_mainWindow);
    ReceiveEvent::registerNetworkReceiver(NetMsg::DrawCategory,m_mainWindow);
    ReceiveEvent::registerNetworkReceiver(NetMsg::CharacterCategory,m_mainWindow);
    ReceiveEvent::registerNetworkReceiver(NetMsg::ConnectionCategory,m_mainWindow);
    ReceiveEvent::registerNetworkReceiver(NetMsg::CharacterPlayerCategory,m_mainWindow);
#ifndef NULL_PLAYER
    m_audioPlayer = AudioPlayer::getInstance();
    ReceiveEvent::registerNetworkReceiver(NetMsg::MusicCategory,m_audioPlayer);
#endif

    setSocket(socket);

    if (PreferencesManager::getInstance()->value("isClient",true).toBool())
    {
		m_networkManager->ajouterNetworkLink(this);
    }
}
Ejemplo n.º 16
0
Socket::Socket(const Socket &orig) : ucommon::Socket()
{
    setSocket();
    so = dupSocket(orig.so,orig.state);
    if(so == INVALID_SOCKET)
        error(errCopyFailed,(char *)"Could not duplicate socket handle",socket_errno);
    state = orig.state;
}
Ejemplo n.º 17
0
eSocket::eSocket(eMainloop *ml, int domain): readbuffer(32768), writebuffer(32768), rsn(0), mainloop(ml)
{
	int s=socket(domain, SOCK_STREAM, 0);
#if 0
	eDebug("[SOCKET]: initalized socket %d", socketdesc);
#endif
	mystate=Idle;
	setSocket(s, 1, ml);
}
Ejemplo n.º 18
0
QtTelnetPrivate::QtTelnetPrivate(QtTelnet *parent)
    : q(parent), socket(0), notifier(0),
      connected(false), nocheckp(false),
      triedlogin(false), triedpass(false), firsttry(true),
      curauth(0), nullauth(false),
      loginp("ogin:\\s*$"), passp("assword:\\s*$")
{
    setSocket(new QTcpSocket(this));
}
Ejemplo n.º 19
0
	CARIBOU::CUdpSocket& CUdpSession::takeSocket()
	{
		lock();
		if ( socketQueue().count() )
		{
			setSocket(socketQueue().takeFirst());
		}
		unlock();
		return mSocket;
	}
Ejemplo n.º 20
0
Socket::Socket(socket_t fd) : ucommon::Socket()
{
    setSocket();
    if (fd == INVALID_SOCKET) {
        error(errCreateFailed,(char *)"Invalid socket handle passed",0);
        return;
    }
    so = fd;
    state = AVAILABLE;
}
Ejemplo n.º 21
0
void Session::setSecure(bool secure)
{
#ifdef QT_NO_OPENSSL
    Q_UNUSED(secure)
#else
    QSslSocket* sslSocket = qobject_cast<QSslSocket*>(socket());
    if (secure && !sslSocket)
    {
        sslSocket = new QSslSocket(this);
        sslSocket->setPeerVerifyMode(QSslSocket::VerifyNone);
        sslSocket->ignoreSslErrors();
        setSocket(sslSocket);
    }
    else if (!secure && sslSocket)
    {
        setSocket(new QTcpSocket(this));
    }
#endif // QT_NO_OPENSSL
}
Ejemplo n.º 22
0
ClientSocket::ClientSocket( int sock, QObject *parent, const char *name ) :
  Q3Socket( parent, name )
{
      connect( this, SIGNAL(readyRead()), SLOT(readClient()) );
      connect( this, SIGNAL(connectionClosed()), SLOT(connectionClosed()) );
      connect(graspItGUI->getIVmgr(), SIGNAL( processWorldPlanner(int) ), this, SLOT( outputPlannerResults(int)));
      connect(graspItGUI->getIVmgr(), SIGNAL( runObjectRecognition() ), this, SLOT( runObjectRecognition() ));
      connect(graspItGUI->getIVmgr(), SIGNAL( sendString(const QString &) ), this, SLOT( sendString(const QString &) ));      
      setSocket( sock );
}
LocalSocketConnection::LocalSocketConnection(QObject *parentObject,
                                             const QString &serverName)
  : Connection(parentObject),
    m_connectionString(serverName),
    m_socket(NULL),
    m_dataStream(new QDataStream),
    m_holdRequests(true)
{
  setSocket(new QLocalSocket);
}
LocalSocketConnection::LocalSocketConnection(QObject *parentObject,
                                             QLocalSocket *socket)
  : Connection(parentObject),
    m_connectionString(socket->serverName()),
    m_socket(NULL),
    m_dataStream(new QDataStream),
    m_holdRequests(true)
{
  setSocket(socket);
}
Ejemplo n.º 25
0
/*!
    Creates a QSocketDevice object for a stream or datagram socket.

    The \a type argument must be either \c QSocketDevice::Stream for a
    reliable, connection-oriented TCP socket, or \c
    QSocketDevice::Datagram for an unreliable UDP socket.

    The \a protocol indicates whether the socket should be of type IPv4
    or IPv6. Passing \c Unknown is not meaningful in this context and you
    should avoid using (it creates an IPv4 socket, but your code is not easily
    readable).

    The argument \a dummy is necessary for compatibility with some
    compilers.

    \sa blocking() protocol()
*/
QSocketDevice::QSocketDevice( Type type, Protocol protocol, int )
    : fd( -1 ), t( type ), p( 0 ), pp( 0 ), e( NoError ),
      d(new QSocketDevicePrivate(protocol))
{
#if defined(QSOCKETDEVICE_DEBUG)
    qDebug( "QSocketDevice: Created QSocketDevice object %p, type %d",
	    this, type );
#endif
    init();
    setSocket( createNewSocket(), type );
}
Ejemplo n.º 26
0
/*!
    Creates a Q3SocketDevice object for a stream or datagram socket.

    The \a type argument must be either Q3SocketDevice::Stream for a
    reliable, connection-oriented TCP socket, or \c
    Q3SocketDevice::Datagram for an unreliable UDP socket.

    The socket is created as an IPv4 socket.

    \sa blocking() protocol()
*/
Q3SocketDevice::Q3SocketDevice( Type type )
    : fd( -1 ), t( type ), p( 0 ), pp( 0 ), e( NoError ),
      d(new Q3SocketDevicePrivate(IPv4))
{
#if defined(Q3SOCKETDEVICE_DEBUG)
    qDebug( "Q3SocketDevice: Created Q3SocketDevice object %p, type %d",
	    this, type );
#endif
    init();
    setSocket( createNewSocket(), type );
}
Ejemplo n.º 27
0
/*!
    Creates a QSocketDevice object for the existing socket \a socket.

    The \a type argument must match the actual socket type; use \c
    QSocketDevice::Stream for a reliable, connection-oriented TCP
    socket, or \c QSocketDevice::Datagram for an unreliable,
    connectionless UDP socket.
*/
QSocketDevice::QSocketDevice( int socket, Type type )
    : fd( socket ), t( type ), p( 0 ), pp( 0 ), e( NoError ),
      d(new QSocketDevicePrivate(Unknown))
{
#if defined(QSOCKETDEVICE_DEBUG)
    qDebug( "QSocketDevice: Created QSocketDevice %p (socket %x, type %d)",
	   this, socket, type );
#endif
    init();
    setSocket( socket, type );
}
Ejemplo n.º 28
0
/*!
    Creates a MSocketDevice object for a stream or datagram socket.

    The \a type argument must be either MSocketDevice::Stream for a
    reliable, connection-oriented TCP socket, or \c
    MSocketDevice::Datagram for an unreliable UDP socket.
    The socket protocol type is defaulting to unknown leaving it to
    connect() to determine if an IPv6 or IPv4 type is required.

    \sa blocking() protocol()
*/
MSocketDevice::MSocketDevice(Type type)
        : fd(-1), t(type), p(0), pp(0), e(NoError),
        d(new MSocketDevicePrivate(Unknown))
{
#if defined(MSOCKETDEVICE_DEBUG)
    qDebug("MSocketDevice: Created MSocketDevice object %p, type %d",
           this, type);
#endif
    init();
    setSocket(createNewSocket(), type);
}
Ejemplo n.º 29
0
QXmppOutgoingClient::QXmppOutgoingClient(QObject *parent)
    : QXmppStream(parent),
    d(new QXmppOutgoingClientPrivate(this))
{
    bool check;
    Q_UNUSED(check);

    // initialise socket
    QSslSocket *socket = new QSslSocket(this);
    setSocket(socket);

    check = connect(socket, SIGNAL(disconnected()),
                    this, SLOT(_q_socketDisconnected()));
    Q_ASSERT(check);

    check = connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
                    this, SLOT(socketSslErrors(QList<QSslError>)));
    Q_ASSERT(check);

    check = connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
                    this, SLOT(socketError(QAbstractSocket::SocketError)));
    Q_ASSERT(check);

    // DNS lookups
    check = connect(&d->dns, SIGNAL(finished()),
                    this, SLOT(_q_dnsLookupFinished()));
    Q_ASSERT(check);

    // XEP-0199: XMPP Ping
    d->pingTimer = new QTimer(this);
    check = connect(d->pingTimer, SIGNAL(timeout()),
                    this, SLOT(pingSend()));
    Q_ASSERT(check);

    // ping timeout timer
    d->pingTimeoutTimer = new QTimer(this);
    d->pingTimeoutTimer->setSingleShot(true);
    check = connect(d->pingTimeoutTimer, SIGNAL(timeout()),
                    this, SLOT(connectTimeout()));
    Q_ASSERT(check);

    // connect timeout timer
    d->connectTimeoutTimer = new QTimer(this);
    d->connectTimeoutTimer->setSingleShot(true);
    check = connect(d->connectTimeoutTimer, SIGNAL(timeout()),
                    this, SLOT(pingTimeout()));




    check = connect(this, SIGNAL(disconnected()),
                    this, SLOT(pingStop()));
    Q_ASSERT(check);
}
Ejemplo n.º 30
0
void BufferedSocket::connect(const string& aAddress, uint16_t aPort, bool secure, bool allowUntrusted, bool proxy) throw(SocketException) {
	dcdebug("BufferedSocket::connect() %p\n", (void*)this);
	std::auto_ptr<Socket> s(secure ? CryptoManager::getInstance()->getClientSocket(allowUntrusted) : new Socket);

	s->create();
	s->bind(0, SETTING(BIND_ADDRESS));
	
	setSocket(s);
	
	Lock l(cs);
	addTask(CONNECT, new ConnectInfo(aAddress, aPort, proxy && (SETTING(OUTGOING_CONNECTIONS) == SettingsManager::OUTGOING_SOCKS5)));
}