示例#1
0
		my_hostent(const hostent * hent)
		{
			h_addrtype = hent->h_addrtype;
			h_length   = hent->h_length;

			// Hostname
			h_name = strcopy(hent->h_name);

			// Host aliases
			h_aliases = NULL;
			if (hent->h_aliases != NULL)
			{
				int	aliasCount = 0;
				for (char ** c = hent->h_aliases; *c != NULL; c++)
					aliasCount++;
				aliasCount++;

				h_aliases = new char*[aliasCount];
				memset(h_aliases, 0, sizeof(char *) * aliasCount);
				
				int i = 0;
				for (char ** c = hent->h_aliases; *c != NULL; i++, c++)
				{
					h_aliases[i] = strcopy(*c);
				}
			}

			// Address list
			h_addr_list = NULL;
			if (hent->h_addr_list != NULL)
			{
				int	addrCount = 0;
				for (char ** c = hent->h_addr_list; *c != NULL; c++)
					addrCount++;

				addrCount += 2;

				h_addr_list = new char*[addrCount];
				memset(h_addr_list, 0, sizeof(char *) * addrCount);

				// Insert our fake address
				h_addr_list[addrCount-2] = new char[h_length];
				u_long * pAddr = (u_long *)h_addr_list[addrCount-2];
				*pAddr = LocalAddress().S_un.S_addr;

				int i = 0;
				for (char ** c = hent->h_addr_list; *c != NULL; i++,c++)
				{
					h_addr_list[i] = new char[h_length];
					memcpy(h_addr_list[i], *c, h_length);
				}
			}
		}
示例#2
0
void socketStream::setUp()
{
    // create the socket threads and wait until they are ready to accept
    // connections (if we called Connect() before this happens, it would fail)
    {
        wxMutexLocker lock(gs_mutex);

        m_writeThread =
            new SocketServerThread(TEST_PORT_READ, &socketStream::WriteSocket);
        CPPUNIT_ASSERT_EQUAL( wxCOND_NO_ERROR, gs_cond.Wait() );

        m_readThread =
            new SocketServerThread(TEST_PORT_WRITE, &socketStream::ReadSocket);
        CPPUNIT_ASSERT_EQUAL( wxCOND_NO_ERROR, gs_cond.Wait() );
    }

    m_readSocket = new wxSocketClient(ms_flags);
    CPPUNIT_ASSERT( m_readSocket->Connect(LocalAddress(TEST_PORT_READ)) );

    m_writeSocket = new wxSocketClient(ms_flags);
    CPPUNIT_ASSERT( m_writeSocket->Connect(LocalAddress(TEST_PORT_WRITE)) );
}
示例#3
0
	void	Initialize()
	{
		// Clean fake address buffer
		for (DWORD i = 0; i < FAKEIPCOUNT; i++)
			theFakeAddresses[i].m_Active = false;

		if (theGame.GetActiveGame()->AddFakeAddress())
		{
			theLocalAddrByte = theConfig.GetLocalAddressByte();

			hk::GetLogManager().Printf("[FakeAddr] Using local address '%s'\n", inet_ntoa(LocalAddress()));

			theFakeAddresses[theLocalAddrByte].m_Active = TRUE;
			theFakeAddresses[theLocalAddrByte].m_Address.S_un.S_addr = INADDR_ANY;
			theFakeAddresses[theLocalAddrByte].m_LastUpdate = GetTickCount();
		}
	}
示例#4
0
oexBOOL CVfsFtpSession::CmdPasv()
{
    oexBOOL bStarted = oexFALSE;

    // Loop through port numbers
    if ( m_uPasvPort >= 3900 )
        m_uPasvPort = 3110;

    while ( m_uPasvPort < 4000 && !bStarted )
    {
        // Next port
        m_uPasvPort++;

        // Ensure the thread is running
        if ( !m_nsData.IsRunning() )
            m_nsData.Start();

        // Reset server
        m_nsData.Queue( 0, oexCall( oexT( "Reset" ) ) );

        // Bind to port
        if ( m_nsData.Queue( 0, oexCall( oexT( "Bind" ), m_uPasvPort ) )
                .Wait( oexDEFAULT_TIMEOUT ).GetReply().ToInt()

             && m_nsData.Queue( 0, oexCall( oexT( "Listen" ), 0 ) )
                .Wait( oexDEFAULT_TIMEOUT ).GetReply().ToInt() )

            bStarted = oexTRUE;

    } // end while

    // Did we get a server?
    if ( bStarted )
    {
        // Tell the client where the server is
        CStr8 sAddress = oexStrToStr8( LocalAddress().GetDotAddress().Replace( '.', ',' ) );
        Write( CStr8().Fmt( "227 Entering Passive Mode (%s,%u,%u).\n",
                            sAddress.Ptr(), m_uPasvPort >> 8 & 0xff, m_uPasvPort & 0xff ) );
    } // end if

    else
示例#5
0
    virtual void *Entry()
    {
        wxSocketServer srv(LocalAddress(m_port), wxSOCKET_REUSEADDR);
        CPPUNIT_ASSERT( srv.IsOk() );

        // FIXME: this is still not atomic, of course and the main thread could
        //        call Connect() before we have time to Accept() but there is
        //        no way to fix it with current API
        {
            wxMutexLocker lock(gs_mutex);
            gs_cond.Signal();
        }

        wxSocketBase *socket = srv.Accept();
        if ( socket )
        {
            (*m_accept)(*socket);
            delete socket;
        }

        return NULL;
    }
示例#6
0
void Execute(void)
{
   Instruction I;
   int temp, temp1, temp2,temp3, Addr;
   char tempc;


    /* Start  here */
   I = StartInstruction;
   while (OpCodeOf(I) != HALTOP) 
   {
      if (TraceSpecified)
         TraceExecution(I);

      if (ValidOpCode(I)) 
      {
         switch (OpCodeOf(I)) 
         {
            case NOP     : break;

	    case LITOP   : PushLf(Operand1Of(I));
                           break;

	    case LLVOP   : PushLf(Lf(Operand1Of(I)));
                           break;

	    case LGVOP   : PushLf(Gf(Operand1Of(I)));
                           break;

            case SLVOP   : UpdateLf(Operand1Of(I),PopLf());
                           break;
 
            case SGVOP   : UpdateGf(Operand1Of(I),PopLf());
                           break;
 
            case LLIVOP  : PushLf(Gf(Lf(Operand1Of(I))));
                           break;
 
            case LGIVOP  : PushLf(Gf(Gf(Operand1Of(I))));
		    	   break;
 
            case SLIVOP  : UpdateGf(Lf(Operand1Of(I)),PopLf());
			   break;
 
            case SGIVOP  : UpdateGf(Gf(Operand1Of(I)),PopLf());
			   break;
 
            case LLAOP   : PushLf(LocalAddress(Operand1Of(I)));
			   break;
 
            case LGAOP   : PushLf(GlobalAddress(Operand1Of(I)));
			   break;

            case LUVOP   : Addr = LocalAddress(0);
                           for (temp = 1; temp <= Operand1Of(I); temp++) 
                           { 
                              if (Addr == 0) 
                              {
                                 fprintf(output,
                                         "TOO MANY FRAMES SPECIFIED IN LUV\n");
                                 FatalError();
	                      }
                              Addr = Gf(Addr);
                           }
                           PushLf(Gf(Addr + Operand2Of(I)));
		           break;

            case SUVOP   : Addr = LocalAddress(0);
                           for (temp = 1; temp <= Operand1Of(I); temp++) 
                           { 
                              if (Addr == 0)
                              {
                                 fprintf(output,
                                         "TOO MANY FRAMES SPECIFIED IN SUV\n");
                                 FatalError();
                              }
                              Addr = Gf(Addr);
                            }
                            UpdateGf (Addr+Operand2Of(I),PopLf());
                            break;

            case UOPOP   : temp = PopLf();
                           switch (Operand1Of(I)) 
                           {
                              case UNOT  : PushLf(1 - temp); 
                                           break;

                              case UNEG  : PushLf(- temp);
                                           break;

                              case USUCC : PushLf(temp + 1);
                                           break;

                              case UPRED : PushLf(temp - 1);
                                           break;
			    }
			    break;

	     case BOPOP   : temp2 = PopLf(); 
                            temp1 = PopLf();
                            if (ValidBinOp(I)) 
                            {
                               switch (Operand1Of(I)) 
                               {
                                  case BAND   : PushLf(temp1 * temp2);
                                                break;

                                  case BOR    : if ((temp1+temp2) > 0)
                                                   PushLf (1);
                                                else 
                                                   PushLf(0);
                                                break;

                                  case BPLUS  : PushLf(temp1 + temp2);
                                                break;

                                  case BMINUS : PushLf(temp1 - temp2);
                                                break;

                                  case BMULT  : PushLf(temp1 * temp2);
                                                break;

                                  case BDIV   : if (temp2 == 0) 
                                                {
                                                   fprintf(output,
                                                    "<<< MACHINE ERROR >>>: ");
                                                   fprintf(output,
                                                    "DIVISION BY ZERO.\n");
                                                   DumpMemory(output);
                                                   FatalError();
					        } 
                                                else 
                                                   PushLf(temp1 / temp2);
                                              
                                                break;

                                  case BEXP   : if (temp2 < 0) 
                                                {
                                                   fprintf(output,
                                                    "<<< MACHINE ERROR >>>: ");
                                                   fprintf(output,
                                                    "NEGATIVE EXPONENT. \n");
                                                   DumpMemory(output);
                                                   FatalError();
                                                } 
                                                else 
                                                {
                                                   temp = 1;
                                                   for (temp3=1; temp3<=temp2; temp3++)
                                                      temp = temp * temp1;
                                                   PushLf(temp);
					        }
					        break;

                                  case BMOD   : PushLf(temp1 % temp2);
                                                break;

                                  case BEQ    : if (temp1 ==  temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

                                  case BNE    : if (temp1 != temp2) 
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

                                  case BLE    : if (temp1 <= temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf (0);
                                                break;

                                  case BGE    : if (temp1 >= temp2)
                                                   PushLf (1);
                                                else
                                                   PushLf (0);
                                                break;

                                  case BLT    : if (temp1 <  temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

                                  case BGT    : if (temp1 >  temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

			       } /* switch(Operand1Of(I)) */

			    } 
                            else 
                            {
                               fprintf(output,"<<< MACHINE ERROR >>>: ");
                               fprintf(output,"UNKNOWN OPERAND NAME: ");
    		               fprintf(TraceFile," %d ",Operand1Of(I));
                               fprintf(output,"\n");
                               DumpMemory(output);
                               FatalError();
		            }
		            break;

             case POPOP   : PopOffLf(Operand1Of(I));
                            break;
 
             case DUPOP   : PushLf(TopLf());
                            break;
 
             case SWAPOP  : temp1 = PopLf();
                            temp2 = PopLf();
                            PushLf(temp1);
                            PushLf(temp2);
		            break;

             case CALLOP  : PushReturnStack(I);
                            OpenFrame(Operand1Of(I));
                            I = PopLf() - 1;
		            break;
 
             case RTNOP   : temp = DepthLf() - Operand1Of(I);
                            if (temp > 0) 
                            {
                             for (temp1 = 0; temp1 <= (Operand1Of(I) - 1); temp1++)
                                UpdateLf(temp1, Lf(temp + temp1));

                             PopOffLf(temp);
		            }
                            I = PopReturnStack();
                            CloseFrame (Operand1Of(I));
			    break;
 
             case GOTOOP  : I = Operand1Of(I) - 1;
		  	    break;

             case CONDOP  : temp = PopLf();
                            if (temp == 0)
                               I = Operand2Of(I) - 1;
                            else
                               I = Operand1Of(I) - 1;
                            break;
 
             case CODEOP  : PushLf(Operand1Of(I));
                            break;
 
             case LIMITOP : temp2 = PopLf();  /* U */
                            temp1 = PopLf();  /* L */
                            temp  = PopLf();  /* X */
                            if ((temp >= temp1) && (temp <= temp2))
                               PushLf(temp);
                            else 
                            {
                               fprintf(output,"<<< MACHINE ERROR >>>: ");
                               fprintf(output,"VALUE OUT OF RANGE\n");
                               DumpMemory(output);
                               FatalError();
			    }
			    break;

             case SOSOP   : if (ValidOsOp(I)) 
                            {
                                switch (Operand1Of(I)) 
                                {
                                   case TRACEX  : if (TraceSpecified)
                                                     TraceSpecified = false;
                                                  else
                                                     TraceSpecified = true;
					          break;

                                   case DUMPMEM : DumpMemory(output);
                                                  break;

                                   case OSINPUT : fscanf(input," ");
					          if (feof(input)) { 
                                                     fprintf(output,
                                                      "<<< MACHINE ERROR >>>: ");
                                                     fprintf(output,
                                                      "TRIED TO READ PAST <EOF>\n");
                                                     DumpMemory(output);
                                                     FatalError();
                                                  } 
                                                  else 
                                                  {
                                                     fscanf(input,"%d",&temp);
                                                     PushLf(temp);
					          }
					          break;
 
                                  case OSINPUTC : fscanf(input," ");
					          if (feof(input)) 
                                                  {
                                                     fprintf(output,
                                                      "<<< MACHINE ERROR >>>: ");
                                                     fprintf(output,
                                                      "TRIED TO READ PAST <EOF>\n");
                                                     DumpMemory(output);
                                                     FatalError();
                                                  } 
                                                  else 
                                                  {
                                                     fscanf(input,"%c",&tempc);
                                                     PushLf(tempc);
					          }
					          break;
 
                                  case OSOUTPUT : temp = PopLf();
                                                  fprintf(output,"%d ",temp);
					          break;
 
                                  case OSOUTPUTC: tempc = PopLf();
                                                  fprintf(output,"%c",tempc);
					          break;
 
                                  case OSOUTPUTL: fprintf(output,"\n");
						  break;
 
                                  case OSEOF    : fscanf(input," ");
					          if (feof(input))
                                                     PushLf(1);
                                                  else
                                                     PushLf(0);
					          break;
                                }
			     } 
                             else 
                             {
                                fprintf(output,"%s","<<< MACHINE ERROR >>>: ");
                                fprintf(output,"%s%1d `",
                                        "UNKNOWN OPERAND NAME: ",Operand1Of(I));
    		                fprintf(TraceFile," %d ",Operand1Of(I));
                                fprintf(output, "` \n");
                                DumpMemory(output);
                                FatalError();
                             }
                             break;
	 } /* switch (OpCodeOf(I)) */
              
      } 
      else 
      {
         fprintf(output,"%s","<<< MACHINE ERROR >>>: ");
         fprintf(output,"%s","UNKNOWN OP CODE NAME: ");
    	 fprintf(output," %d ",OpCodeOf(I));
         fprintf(output,"\n");
         FatalError();
      }
 
      I++;
 
   }
}