示例#1
0
int       connect(SocketFd fd, const char *ip, short port)
{
    struct sockaddr_in addr;
    ::memset(&addr, 0, sizeof(addr));
    getSockAddr(ip, port, &addr);

    return connect(fd, addr);
}
示例#2
0
//
// Set the arguments
//
int CTcpServer::setArguments(char* li, char* lp)
{
	if(!lp)
	{
		printf("Error: Missing argument - lp argument required.\n");
		return E_INCORRECTARG;
	}
	
	iLocal_Sock = getSocket();
	iLocal_Addr = getSockAddr(li,lp );	
	connect(iLocal_Sock,iLocal_Addr);	//bind

	return ITS_OK;

}
示例#3
0
文件: util.cpp 项目: guoyu07/lspider
vector<string> getip(const char *host)
{
    vector<string> result;
    vector<unsigned long> addrs = getSockAddr(host);
    if (0 == addrs.size()) {
        fprintf (stderr, "warn: %s:%d getSockAddr %s\n", __FILE__, __LINE__, host);
    } else {
        for (int i = 0; i < addrs.size(); i++) {
            char ipstring[16] = {'\0'};
            if (0 == ip_ntoa(addrs[i], ipstring, 16)) {
                result.push_back(ipstring);
            }
        }
    }
    return result;
}
int
InetSocket::maxIPPayload(void) const throw()
{
  SockAddr addr;
  if (getSockAddr(addr)) {
    switch (addr.family()) {
      case InetAddr::Invalid:
      default:
        break;
      case InetAddr::IPv4:
        return (mtu() - 20);
      case InetAddr::IPv6:
        return (mtu() - 40);
    }
  }
  return 0;
}
示例#5
0
bool IPCServer::listen()
{
	if (m_priv->fd > 0)
		return true;

	m_priv->fd = socket(AF_UNIX, SOCK_STREAM, 0);
	if (m_priv->fd > 0)
	{
		const sockaddr_un sockAddr = getSockAddr(m_priv->fileName);

		if (bind(m_priv->fd, (const sockaddr *)&sockAddr, sizeof sockAddr) == 0 && ::listen(m_priv->fd, 1) == 0)
		{
			m_priv->socketNotifier = new QSocketNotifier(m_priv->fd, QSocketNotifier::Read, this);
			connect(m_priv->socketNotifier, SIGNAL(activated(int)), this, SLOT(socketAcceptActive()));
			return true;
		}

		close();
	}
示例#6
0
bool IPCSocket::open(QIODevice::OpenMode mode)
{
	if (!m_priv->fileName.isEmpty())
	{
		const sockaddr_un sockAddr = getSockAddr(m_priv->fileName);
		m_priv->fd = socket(AF_UNIX, SOCK_STREAM, 0);
		if (m_priv->fd > 0 && ::connect(m_priv->fd, (const sockaddr *)&sockAddr, sizeof sockAddr) != 0)
		{
			::close(m_priv->fd);
			m_priv->fd = -1;
		}
	}

	if (m_priv->fd > 0)
	{
		const unsigned long on = 1;
		ioctl(m_priv->fd, FIONBIO, &on);
		m_priv->socketNotifier = new QSocketNotifier(m_priv->fd, QSocketNotifier::Read, this);
		connect(m_priv->socketNotifier, SIGNAL(activated(int)), this, SLOT(socketReadActive()));
		return QIODevice::open(mode);
	}

	return false;
}