int CheckHostIPValues(string & ipString, string & hostName, bool * ipExists, bool * nameExists){ char hostNameBuffer[128]; char ipStrBuffer[16]; int ret; bool result = false; memset(ipStrBuffer,0,16); memset(hostNameBuffer,0,128); ret = IsHostName((char *)ipString.c_str(), &result); if(ret != GENERIC_SUCCESS){ printf("CheckHostIPValues(): IsHostName() failed\n"); return GENERIC_ERROR; } // The IP address is actually a host name, so try to fix it if(result == true){ hostName = ipString; ipString = ""; ret = GetIpByHostName((char *)hostName.c_str(), ipStrBuffer); if(ret != GENERIC_SUCCESS){ printf("CheckHostIPValues(): GetIpByHostName() failed\n"); }else{ ipString = ipStrBuffer; } } if(!hostName.empty()){ *nameExists = true; } if(!ipString.empty()){ *ipExists = true; } // if neither exists, error out if(*nameExists == false && *ipExists == false){ printf("CheckHostIPValues(): Both host name and ip string passed were null\n"); return GENERIC_ERROR; } else if(*nameExists == true && *ipExists == false){ ret = GetIpByHostName((char *)hostName.c_str(), ipStrBuffer); if(ret != GENERIC_SUCCESS || ipStrBuffer == NULL){ printf("CheckHostIPValues(): GetIpByHostName() failed\n"); return GENERIC_ERROR; } else{ //sprintf_s(ipString,16,"%s",ipStrBuffer); ipString = ipStrBuffer; *ipExists = true; } } else if(*nameExists == false && *ipExists == true){ ret = GetHostNameByIP((char *)ipString.c_str(), hostNameBuffer); if(ret != GENERIC_SUCCESS || hostNameBuffer == NULL){ printf("CheckHostIPValues(): GetHostNameByIP() failed\n"); return NO_RESULTS_FOUND; } else{ //sprintf_s(hostName,128,"%s",hostNameBuffer); hostName = hostNameBuffer; *nameExists = true; } } return GENERIC_SUCCESS; }
int ResolveIPsAndNames(string * srcIP, string * dstIP, string * srcHostName, string * dstHostName){ int ret; // if the srcIP is defined and valid if(srcIP->length() >= 7 && srcHostName->empty()){ // if the source host is blank, try to get the host name from the ip const char * tempIP = srcIP->c_str(); char tempHostName[128]; ret = GetHostNameByIP(tempIP, tempHostName); if(ret != GENERIC_SUCCESS){ printf("ResolveIPsAndNames: GetHostNameByIP failed\n"); return GENERIC_ERROR; } if(tempHostName != NULL){ *srcHostName = tempHostName; }else{ printf("ResolveIPsAndNames: GetHostNameByIP returned a null host name\n"); return GENERIC_ERROR; } // else if the host name is defined and not blank }else if(! srcHostName->empty() && srcIP->empty()){ const char * tempHostName = srcHostName->c_str(); char tempIP[128]; ret = GetIpByHostName(tempHostName, tempIP); if(ret != GENERIC_SUCCESS){ printf("ResolveIPsAndNames: getIPByHostName failed\n"); return GENERIC_ERROR; } if(tempIP != NULL){ *srcIP = tempIP; }else{ printf("ResolveIPsAndNames: getIPByHostName returned a null ip address\n"); return GENERIC_ERROR; } } // Now doing the same for the destination IP and HostName // if the dstIP is defined and valid if(dstIP->length() >= 7 && dstHostName->empty()){ // if the dst host is blank, try to get the host name from the ip const char * tempIP = dstIP->c_str(); char tempHostName[128]; ret = GetHostNameByIP(tempIP, tempHostName); if(ret != GENERIC_SUCCESS){ printf("ResolveIPsAndNames: GetHostNameByIP failed\n"); return GENERIC_ERROR; } if(tempHostName != NULL){ *dstHostName = tempHostName; }else{ printf("ResolveIPsAndNames: GetHostNameByIP returned a null host name\n"); return GENERIC_ERROR; } // else if the host name is defined and not blank }else if(! dstHostName->empty() && dstIP->empty()){ // if the dst ip is blank, try to get the ip from the hostname const char * tempHostName = dstHostName->c_str(); char tempIP[128]; ret = GetIpByHostName(tempHostName, tempIP); if(ret != GENERIC_SUCCESS){ printf("ResolveIPsAndNames: getIPByHostName failed\n"); return GENERIC_ERROR; } if(tempIP != NULL){ *dstIP = tempIP; }else{ printf("ResolveIPsAndNames: getIPByHostName returned a null ip address\n"); return GENERIC_ERROR; } } return GENERIC_SUCCESS; }
int GetDnsServerIp( char* ipaddr ) { int iRet = 0; switch ( bparam.stDdnsParam.factoryversion ) { case 10: //vstarcam GetDnsIp( bparam.stDdnsParam.serversvr, ipaddr ); break; case 11: //xinhuaan viporg GetDnsIp( bparam.stDdnsParam.serversvr, ipaddr ); break; case 12: //xinhuaan 88safe GetDnsIp( bparam.stDdnsParam.serversvr, ipaddr ); break; case 13: //smarteye GetDnsIp( bparam.stDdnsParam.serversvr, ipaddr ); break; /* BEGIN: Added by wupm, 2013/3/23 */ case 21: //PSD GetDnsIp( bparam.stDdnsParam.serversvr, ipaddr ); Textout1( "PSD Server=[%s], IP=[%s]", bparam.stDdnsParam.serversvr, ipaddr ); break; /* BEGIN: Added by wupm, 2013/4/19 */ //NEO case 22: //GetDnsIp( bparam.stDdnsParam.serversvr, ipaddr ); //GetDnsIp( "www.9299.org", ipaddr ); //GetIpByHostName( "www.baidu.com", ipaddr ); //GetIpByHostName( "www.9299.org", ipaddr ); GetIpByHostName( "www.365home.org", ipaddr ); Textout( "NEO Server=[%s], IP=[%s]", bparam.stDdnsParam.serversvr, ipaddr ); break; /* BEGIN: Added by wupm, 2013/4/25 */ case 23: GetIpByHostName( "www.ipupnp.hk", ipaddr ); Textout( "NEO Server=[%s], IP=[%s]", bparam.stDdnsParam.serversvr, ipaddr ); break; case 24: //GetIpByHostName( "www.ibabycam.net", ipaddr ); GetIpByHostName( "www.ulife.info", ipaddr ); Textout( "NEO Server=[%s], IP=[%s]", bparam.stDdnsParam.serversvr, ipaddr ); break; case 25: GetIpByHostName( "www.ipcpnp.com", ipaddr ); Textout( "NEO Server=[%s], IP=[%s]", bparam.stDdnsParam.serversvr, ipaddr ); break; case 26: GetIpByHostName( "mytenvis.org", ipaddr ); Textout( "NEO Server=[%s], IP=[%s]", bparam.stDdnsParam.serversvr, ipaddr ); break; default: iRet = -1; break; } return iRet; }