示例#1
0
    // 起動.
    IZ_BOOL Udp::start(const IPv4Endpoint& hostEp)
    {
        if (isValidSocket(m_socket)) {
            return IZ_TRUE;
        }

        IZ_BOOL result = IZ_FALSE;

        // ソケットの生成
        m_socket = socket(
            AF_INET,        // アドレスファミリ
            SOCK_DGRAM,     // ソケットタイプ
            IPPROTO_UDP);   // プロトコル
        VRETURN(isValidSocket(m_socket));

        // 通信ポート・アドレスの設定
        sockaddr_in inAddr;
        {
            FILL_ZERO(&inAddr, sizeof(inAddr));

            inAddr.sin_family = AF_INET;
            inAddr.sin_port = htons(hostEp.getPort());

            auto address = hostEp.getAddress();

            if (address.isAny()) {
                setIp(inAddr, htonl(INADDR_ANY));
            }
            else {
                IZ_CHAR ip[64];
                address.toString(ip, COUNTOF(ip));

                setIp(inAddr, inet_addr(ip));
            }
        }

        // ソケットにアドレスを結びつける
        result = (bind(m_socket, (const sockaddr*)&inAddr, sizeof(inAddr)) >= 0);
        
        if (result) {
            m_isBindAddr = IZ_TRUE;
            m_host = hostEp;
        }
        else {
            IZ_ASSERT(IZ_FALSE);
            stop();
        }

        return result;
    }
示例#2
0
ARecord::ARecord(::std::string i) {
	qtype = 1;
	qclass = 1;
	ttl = 600;
	rdLength = 0;
	setIp(i);
}
示例#3
0
void rspfUrl::setFieldsFromUrl(const rspfString& url)
{
    m_protocol = m_ip = m_port = m_path = m_params = "";
    
    // look for something of the form <protocol>://
    const std::string& s = url.string();
    std::string::size_type pos = s.find_first_of(":");
    
    if(pos == std::string::npos) return;
    
    m_protocol = rspfString(s.begin(), s.begin()+pos);
    
    // now find the ip and then extract port if embedded in IP
    //
    pos = s.find_first_not_of('/', pos+1);
    
    if(pos == std::string::npos) return;
    
    std::string::size_type nextPos = s.find_first_of('/', pos+1);
    
    if(nextPos == std::string::npos)
    {
        setIp(rspfString(s.begin()+pos, s.end()));
        return;
    }
    else
    {
        setIp(rspfString(s.begin()+pos, s.begin()+nextPos));
    }
    // now find the path portion
    //
    pos = s.find_first_of('?', nextPos);
    if(pos == std::string::npos)
    {
        m_path = rspfString(s.begin()+nextPos+1, s.end());
        return;
    }
    else
    {
        m_path = rspfString(s.begin()+nextPos+1, s.begin()+pos);
    }
    
    m_params = rspfString(s.begin()+pos+1, s.end());
    
}
/* important interface functions */
void ArduinoiDigiInterfaceClass::setup(uint8_t *mac, IPAddress ip, uint32_t vendorId)
{
  setMac(mac);
  setIp(ip);
  setVendorId(vendorId);
  
  idigi_handle = idigi_init((idigi_callback_t) &ArduinoiDigiInterfaceClass::appCallback);
  AR_DEBUG_PRINTF("idigi_init complete.\r\n");  
}
示例#5
0
    void IoTCP::setup(const StringMap & settings)
    {
        Io::setup(settings);

        // ----------------------------------
        // TODO: set server credentials
        
        setIp(settings.at("ios.TCPSocket.server").c_str());
        setPort(std::atoi(settings.at("ios.TCPSocket.port").c_str()));
        setMessage(settings.at("ios.TCPSocket.message").c_str());
    }
示例#6
0
void TabbedWebView::slotLoadFinished()
{
    m_tabWidget->stopTabAnimation(tabIndex());

    showIcon();
    QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));

    if (isCurrent()) {
        p_QupZilla->updateLoadingActions();
    }
}
示例#7
0
bool NetworkDevice::loadFromDomElement(const QDomElement &domElement)
{
    if (Device::loadFromDomElement(domElement)) {
        QDomElement ipElement = domElement.firstChildElement("ip");
        if (!ipElement.isNull()) {
            setIp(ipElement.text());
        } else {
            setIp("");
        }

        QDomElement portElement = domElement.firstChildElement("port");
        if (!portElement.isNull()) {
            setPort(portElement.text());
        } else {
            setPort("");
        }

        return true;
    }
    return false;
}
示例#8
0
文件: globalopt.c 项目: stanxii/hfc
static void setDevip(HttpConn *conn) {
    char str[16] = {0};
    cchar *role = getSessionVar("role");
    if(role == NULL){
        rendersts(str, 9);
        render(str);
        return;
    }
    if((strcmp(role, "root") !=0) && (strcmp(role, "admin") !=0)){
        rendersts(str, 5);//无权限设置Ip
        render(str);
        return;
    }
	cchar *param = espGetQueryString(conn);

	char newip[16] = {0};
	char newgatway[16] = {0};
	char submask[16] = {0};
	char* ptr = strchr(param, '&');
    int pos = ptr-param;
	substr(param, 0, pos, newip);
	char *ptr1 = strrchr (param, '&');
	int flag = ptr1 - param;
	substr(param, pos + 1, flag, newgatway);
	substr(param, flag + 1, strlen(param), submask);
	unsigned int vip = ntohl( inet_addr( newip ) );
	unsigned int tmpgatway = ntohl( inet_addr( newgatway ) );
	unsigned int tmpsubmask = ntohl( inet_addr( submask ) );
	if(0 == setIp(tmpip, vip)){
		setGateway(tmpip, tmpgatway);
		getSubMask(tmpip, tmpsubmask);
	}
	rendersts(str, 1);
	render(str);
	//add optlog
    Edi *db = ediOpen("db/muxnms.mdb", "mdb", EDI_AUTO_SAVE);
    EdiRec *optlog = ediCreateRec(db, "optlog");
    if(optlog == NULL){
       printf("================>>>optlog is NULL!!\n");
       return;
    }
    time_t curTime;
    time(&curTime);
    memset(optstr, 0, 256);
    sprintf(optstr, "{'user': '******', 'desc': '设备修改IP【IP:%s】.', 'level': '2', 'logtime':'%d'}", getSessionVar("userName"),newip, curTime);
    MprJson  *row = mprParseJson(optstr);
    if(ediSetFields(optlog, row) == 0){
       printf("================>>>ediSetFields Failed!!\n");
    }
    ediUpdateRec(db, optlog);
    //ediClose(db);
}
示例#9
0
void TabbedWebView::slotLoadFinished()
{
    QMovie* mov = animationLoading(tabIndex(), false)->movie();
    if (mov) {
        mov->stop();
    }

    showIcon();
    QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));

    if (isCurrent()) {
        p_QupZilla->updateLoadingActions();
    }
}
示例#10
0
    IZ_BOOL Udp::connectTo(const IPv4Endpoint& remoteEp)
    {
        VRETURN(isValidSocket(m_socket));

        IZ_BOOL result = IZ_FALSE;

        // 通信ポート・アドレスの設定
        sockaddr_in destAddr;
        {
            memset(&destAddr, 0, sizeof(destAddr));

            destAddr.sin_family = AF_INET;
            destAddr.sin_port = htons(remoteEp.getPort());

            auto address = remoteEp.getAddress();
            
            result = !address.isAny();
            VGOTO(result, __EXIT__);

            char ip[64];
            address.toString(ip, COUNTOF(ip));

            setIp(destAddr, inet_addr(ip));
        }

        // 接続
        result = (connect(m_socket, (const sockaddr*)&destAddr, sizeof(destAddr)) >= 0);
        
        if (result) {
            if (!m_isBindAddr) {
                // ホスト名取得
                sockaddr_in inAddr;
                int32_t inAddrSize = sizeof(inAddr);
                result = (getsockname(m_socket, (sockaddr*)&inAddr, &inAddrSize) >= 0);
                VGOTO(result, __EXIT__);

                m_isBindAddr = IZ_TRUE;
                m_host.set(inAddr);
            }
        }

    __EXIT__:
        if (!result) {
            IZ_ASSERT(IZ_FALSE);

            stop();
        }

        return result;
    }
示例#11
0
void handleMessage() {
	BYTE name[20] = "";

	if (!LMTakeString(&name, sizeof(name))) {
		printf("Could not handle message (to long?)\r\n");
		return;
	}
	if (strcmp(name, "reglistener") == 0) {
		registerListener();
	} else if (strcmp(name, "send") == 0) {
			send();
	} else if (strcmp(name, "setip") == 0) {
		setIp();
	} else if (strcmp(name, "saveip") == 0) {
		saveIp();
	} else if (strcmp(name, "disconnect") == 0) {
		Reset();
	}
}
示例#12
0
void DJGameServerItem::assign( const DJGameServerItem* serverItem )
{
	setIp( serverItem->ip() );
	setPort( serverItem->port() );
	setDescription( serverItem->name(), serverItem->numberOfUsers() );
}
示例#13
0
Address::Address(char* ip, int port){
		setIp(ip);
		setPort(port);
}
示例#14
0
void NetworkDevice::reset()
{
    Device::reset();
    setIp("");
    setPort("");
}