Exemplo n.º 1
0
std::string NetworkSocket::debugString() const {
	if(!isOpen()) return "Closed";
	std::string ret = TypeStr(m_type) + "/" + StateStr(m_state);
	{
		std::string localStr = "INVALIDLOCAL";
		NetworkAddr addr;
		if(nlGetLocalAddr(m_socket->sock, getNLaddr(addr)) != NL_FALSE)
			NetAddrToString(addr, localStr);
		else {
			localStr = "ERRORLOCALADDR(" + GetLastErrorStr() + ")";
			ResetSocketError();
		}
		ret += " " + localStr;
	}
	if(m_state == NSS_CONNECTED) {
		ret += " connected to ";
		std::string remoteStr = "INVALIDREMOTE";
		NetworkAddr addr;
		if(nlGetRemoteAddr(m_socket->sock, getNLaddr(addr)) != NL_FALSE)
			NetAddrToString(remoteAddress(), remoteStr);
		else {
			remoteStr = "ERRORREMOTEADDR(" + GetLastErrorStr() + ")";
			ResetSocketError();
		}
		ret += remoteStr;
	}
	return ret;
}
Exemplo n.º 2
0
bool NetworkSocket::setRemoteAddress(const NetworkAddr& addr) {
	if(!isOpen()) {
		errors << "NetworkSocket::setRemoteAddress: socket is closed" << endl;
		return false;
	}
	
	if(getNLaddr(addr) == NULL) {
		errors << "NetworkSocket::setRemoteAddress " << debugString() << ": given address is invalid" << endl;
		return false;
	}
	if( GetNetAddrPort(addr) == 0 )
	{
		errors << "NetworkSocket::setRemoteAddress " << debugString() << ": port is set to 0" << endl;
	}
	
	if(nlSetRemoteAddr(m_socket->sock, getNLaddr(addr)) == NL_FALSE) {
		std::string addrStr = "INVALIDADDR";
		NetAddrToString(addr, addrStr);
		errors << "NetworkSocket::setRemoteAddress " << debugString() << ": failed to set destination " << addrStr << ": " << GetLastErrorStr() << endl;
		ResetSocketError();
		return false;
	}
	
	return true;
}
NS_IMETHODIMP
HttpBaseChannel::GetRemoteAddress(nsACString& addr)
{
  if (mPeerAddr.raw.family == PR_AF_UNSPEC)
    return NS_ERROR_NOT_AVAILABLE;

  addr.SetCapacity(kIPv6CStrBufSize);
  NetAddrToString(&mPeerAddr, addr.BeginWriting(), kIPv6CStrBufSize);
  addr.SetLength(strlen(addr.BeginReading()));

  return NS_OK;
}
Exemplo n.º 4
0
static
bool PACResolveToString(const nsCString &aHostName,
                        nsCString &aDottedDecimal,
                        unsigned int aTimeout)
{
  NetAddr netAddr;
  if (!PACResolve(aHostName, &netAddr, aTimeout))
    return false;

  char dottedDecimal[128];
  if (!NetAddrToString(&netAddr, dottedDecimal, sizeof(dottedDecimal)))
    return false;

  aDottedDecimal.Assign(dottedDecimal);
  return true;
}
Exemplo n.º 5
0
static int CopyUserData(USERDATAOPT *pUserData, SysAddress *Akas, CONFIG *pConfig)
{
   int i=0, j=0;

   while (i < MAX_AKAS && j < MAX_ADDRESSES)
   {
      if (Akas[i].main.zone  ||
          Akas[i].main.net   ||
          Akas[i].main.node  ||
          Akas[i].main.point)
      {
         NetAddrToString(pUserData->address[j], (PFTNADDRESS) &Akas[i].main);
         j++;
      }
      i++;
   }
   strncpy(pUserData->defaultorigin, pConfig->OriginLine[0], LEN_ORIGIN);
   return 0;
}
Exemplo n.º 6
0
///////////////////////
// Connecting process, returns true if finished
bool IRCClient::processConnecting()
{
	// If connected, just quit
	if (m_authorizedState != AUTH_NONE)
		return true;

	// Check for DNS resolution
	if (!IsNetAddrValid(m_chatServerAddr))
		return false;

	// Convert the address to string
	std::string addrStr;
	NetAddrToString(m_chatServerAddr, addrStr);
	
	// Add IRC port
	SetNetAddrPort(m_chatServerAddr, IRC_PORT );

	// Connect
	if (!m_socketConnected)  {
		if (!m_chatSocket.Connect(m_chatServerAddr))  {
			errors("IRC error: could not connect to the server " + addrStr);
			disconnect();
			return true;
		}

		// Connected
		m_socketConnected = true;
		m_socketIsReady = false;
		m_netBuffer.clear();
		m_authorizedState = AUTH_NONE;
	}

	// Check for socket readiness
	if (!m_chatSocket.isReady())
		return false;
	else
		m_socketIsReady = true;

	return true;
}
Exemplo n.º 7
0
static int ReadAreas(FILE *pfConfig, PAREALIST pRetList)
{
   int i;
   Area FEArea;
   AREADEFOPT AreaDef;
   SysAddress *pAddr;

   /* Netmail-Area gesondert behandeln */
   AddNMArea(Config.NetMPath, pRetList, Config.sysops[0].name, (PFTNADDRESS) &Akas[0].main);

   /* Extensions ueberspringen */
   fseek(pfConfig, sizeof(Config)+Config.offset, SEEK_SET);

   /* Nodes ueberspringen */
   if (Config.NodeCnt)
      fseek(pfConfig, Config.NodeCnt*sizeof(Node), SEEK_CUR);

   /* Areas einlesen */
   for (i=0; i<Config.AreaCnt; i++)
   {
      if (1==fread(&FEArea, sizeof(FEArea), 1, pfConfig))
      {
#ifdef DEBUG
         printf("INF: Area %s\n", FEArea.name);
         printf("     Type ");
#endif
         switch(FEArea.type)
         {
            case AREA_ECHOMAIL:
#ifdef DEBUG
               printf("Echo\n");
#endif
               break;

            case AREA_NETMAIL:
#ifdef DEBUG
               printf("Net\n");
#endif
               break;

            case AREA_LOCAL:
#ifdef DEBUG
               printf("Local\n");
#endif
               break;

            case AREA_BADMAILBOARD:
#ifdef DEBUG
               printf("Bad\n");
#endif
               break;

            case AREA_DUPEBOARD:
#ifdef DEBUG
               printf("Dupe\n");
#endif
               break;

            default:
#ifdef DEBUG
               printf("Unknown\n");
#endif
               continue;
         }
#ifdef DEBUG
         printf("     Format ");
#endif
         switch(FEArea.flags.type)
         {
            case QBBS:
#ifdef DEBUG
               printf("Hudson\n");
#endif
               continue;

            case FIDO:
#ifdef DEBUG
               printf("*.MSG\n");
#endif
               break;

            case SQUISH:
#ifdef DEBUG
               printf("Squish\n");
#endif
               break;

            case JAM:
#ifdef DEBUG
               printf("JAM\n");
#endif
               break;

            case PT_BOARD:
#ifdef DEBUG
               printf("PT\n");
#endif
               continue;

            default:
#ifdef DEBUG
               printf("Unknown\n");
#endif
               continue;
         }
#ifdef DEBUG
         printf("     Aka #%d\n", FEArea.flags.aka);
         printf("     Path %s\n", FEArea.path);
         printf("     Desc %s\n", FEArea.desc);
#endif
      }
      else
      {
#ifdef DEBUG
         printf("ERROR: Read error Area (%d)\n", errno);
#endif
         return CFGFILE_READ;
      }
      /* Hier kommen wir nur hin, wenn wir eine gueltige Area gefunden haben */
      memset(&AreaDef, 0, sizeof(AreaDef));
      strncpy(AreaDef.areatag, FEArea.name, LEN_AREATAG);
      if (FEArea.desc[0])
         strncpy(AreaDef.areadesc, FEArea.desc, LEN_AREADESC);
      else
         strncpy(AreaDef.areadesc, FEArea.name, LEN_AREADESC);
      CopyAreaPath(AreaDef.pathfile, FEArea.path);
      strcpy(AreaDef.username, Config.sysops[0].name);
      pAddr = &Akas[FEArea.flags.aka];
      NetAddrToString(AreaDef.address, (PFTNADDRESS) &pAddr->main);

      switch(FEArea.flags.type)
      {
         case FIDO:
            AreaDef.areaformat = AREAFORMAT_FTS;
            break;

         case SQUISH:
            AreaDef.areaformat = AREAFORMAT_SQUISH;
            break;

         case JAM:
            AreaDef.areaformat = AREAFORMAT_JAM;
            break;

         default:
            /* oben schon abgefangen */
            break;
      }

      switch(FEArea.type)
      {
         case AREA_ECHOMAIL:
            AreaDef.areatype = AREATYPE_ECHO;
            break;

         case AREA_NETMAIL:
         case AREA_DUPEBOARD:
         case AREA_BADMAILBOARD:
            AreaDef.areatype = AREATYPE_NET;
            AreaDef.ulDefAttrib = ATTRIB_PRIVATE;
            break;

         case AREA_LOCAL:
            AreaDef.areatype = AREATYPE_LOCAL;
            break;

         default:
            /* oben schon abgefangen */
            break;
      }
      AreaDef.ulAreaOpt = AREAOPT_FROMCFG;

      /* Area eintragen */
      AM_AddArea(pRetList, &AreaDef, ADDAREA_TAIL | ADDAREA_UNIQUE);
   }
   return CFGFILE_OK;
}
Exemplo n.º 8
0
std::string NetAddrToString(const NetworkAddr& addr) { 
	std::string ret; 
	NetAddrToString(addr, ret); 
	return ret; 
};