コード例 #1
0
ファイル: diablo.cpp プロジェクト: Alim-Oezdemir/devilution
int __fastcall diablo_init_menu(int a1, int bSinglePlayer)
{
	int v2; // esi
	int v3; // edi
	int v4; // ecx
	int pfExitProgram; // [esp+Ch] [ebp-4h]

	v2 = bSinglePlayer;
	v3 = a1;
	byte_678640 = 1;
	while ( 1 )
	{
		pfExitProgram = 0;
		dword_5256E8 = 0;
		if ( !NetInit(v2, &pfExitProgram) )
			break;
		byte_678640 = 0;
		if ( (v3 || !*(_DWORD *)&gbValidSaveFile)
		  && (InitLevels(), InitQuests(), InitPortals(), InitDungMsgs(myplr), !*(_DWORD *)&gbValidSaveFile)
		  || (v4 = WM_DIABLOADGAME, !dword_5256E8) )
		{
			v4 = WM_DIABNEWGAME;
		}
		run_game_loop(v4);
		NetClose();
		pfile_create_player_description(0, 0);
		if ( !gbRunGameResult )
			goto LABEL_11;
	}
	gbRunGameResult = pfExitProgram == 0;
LABEL_11:
	SNetDestroy();
	return gbRunGameResult;
}
コード例 #2
0
ファイル: network.c プロジェクト: appleorange1/bitrig
int
netflush(void)
{
    int n, n1;

#if	defined(ENCRYPTION)
    if (encrypt_output)
	ring_encrypt(&netoring, encrypt_output);
#endif
    if ((n1 = n = ring_full_consecutive(&netoring)) > 0) {
	if (!ring_at_mark(&netoring)) {
	    n = send(net, (char *)netoring.consume, n, 0); /* normal write */
	} else {
	    /*
	     * In 4.2 (and 4.3) systems, there is some question about
	     * what byte in a sendOOB operation is the "OOB" data.
	     * To make ourselves compatible, we only send ONE byte
	     * out of band, the one WE THINK should be OOB (though
	     * we really have more the TCP philosophy of urgent data
	     * rather than the Unix philosophy of OOB data).
	     */
	    n = send(net, (char *)netoring.consume, 1, MSG_OOB);/* URGENT data */
	}
    }
    if (n < 0) {
	if (errno != ENOBUFS && errno != EWOULDBLOCK) {
	    setcommandmode();
	    perror(hostname);
	    NetClose(net);
	    ring_clear_mark(&netoring);
	    longjmp(peerdied, -1);
	    /*NOTREACHED*/
	}
	n = 0;
    }
    if (netdata && n) {
	Dump('>', netoring.consume, n);
    }
    if (n) {
	ring_consumed(&netoring, n);
	/*
	 * If we sent all, and more to send, then recurse to pick
	 * up the other half.
	 */
	if ((n1 == n) && ring_full_consecutive(&netoring)) {
	    netflush();
	}
	return 1;
    } else {
	return 0;
    }
}
コード例 #3
0
int
ttyflush(int drop)
{
    int n, n0, n1;

    n0 = ring_full_count(&ttyoring);
    if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) {
	if (drop) {
	    TerminalFlushOutput();
	    /* we leave 'n' alone! */
	} else {
	    n = TerminalWrite(ttyoring.consume, n);
	}
    }
    if (n > 0) {
	if (termdata && n) {
	    Dump('>', ttyoring.consume, n);
	}
	/*
	 * If we wrote everything, and the full count is
	 * larger than what we wrote, then write the
	 * rest of the buffer.
	 */
	if (n1 == n && n0 > n) {
		n1 = n0 - n;
		if (!drop)
			n1 = TerminalWrite(ttyoring.bottom, n1);
		if (n1 > 0)
			n += n1;
	}
	ring_consumed(&ttyoring, n);
    }
    if (n < 0) {
	if (errno == EAGAIN || errno == EINTR) {
	    return -1;
	} else {
	    ring_consumed(&ttyoring, ring_full_count(&ttyoring));
	    setconnmode(0);
	    setcommandmode();
	    NetClose(net);
	    fprintf(stderr, "Write error on local output.\n");
	    exit(1);
	}
	return -1;
    }
    if (n == n0) {
	if (n0)
	    return -1;
	return 0;
    }
    return n0 - n + 1;
}
コード例 #4
0
ファイル: player.cpp プロジェクト: afriza/GSPlayer
void CPlayer::Close()
{
	CAutoLock lock(&m_csecInterface);
	Stop();
	
	PlugInClose();
	MpgClose();
	OvClose();
	WavClose();
	NetClose();

	memset(&m_Info, 0, sizeof(m_Info));
	m_szFile[0] = NULL;
	m_nDuration = 0;

	m_fOpen = OPEN_NONE;
	m_StreamingStatus = MAP_STREAMING_DISABLED;
}
コード例 #5
0
ファイル: spo_syslog_full.c プロジェクト: dogbert2/barnyard2
/* Inverse of the setup function, free memory allocated in Setup 
 * can't free the outputPlugin since it is also the list node itself
 */
void OpSyslog_Exit(int signal,void *pSyslogContext)
{
    OpSyslog_Data *iSyslogContext = NULL;
    
    if( pSyslogContext == NULL)
    {
	FatalError("OpSyslog_Exit(): Called with a NULL argument .... bailing \n");
    }

    iSyslogContext =(OpSyslog_Data *)pSyslogContext;
    
    if(iSyslogContext->payload)
    {
	free(iSyslogContext->payload);
	iSyslogContext->payload = NULL;
    }
    
    if(iSyslogContext->formatBuffer)
    {
	free(iSyslogContext->formatBuffer);
	iSyslogContext->formatBuffer = NULL;
    }
    
    if(iSyslogContext->server)
    {
	free(iSyslogContext->server);
	iSyslogContext->server = NULL;
    }
    
    if(iSyslogContext->sensor_name)
    {
	free(iSyslogContext->sensor_name);
	iSyslogContext->sensor_name = NULL;
    }
    
    NetClose(iSyslogContext);
    
    return;
}
コード例 #6
0
ファイル: log_io.cpp プロジェクト: rauls/iReporter
/*

FormatMessage(     FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
    NULL,    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPTSTR) &lpMsgBuf,    0,    NULL );

  */
long LogClose( long logref, char *filename )
{
	long ret = 0;
	if ( logref )
	{
		// It would be easy to support ZIP/BZIP2 for mac...  
#ifndef DEF_MAC
		if ( IsURL( filename ) )
			NetClose( (void*)logref );
		else
		if ( IsPKZIP( filename ) )
			UnzipClose( (void*)logref );
		else
 #ifdef _BZLIB_H
		if ( IsBZIP( filename ) )
			BZ2_bzclose( (void*)logref );
		else
 #endif
#endif
			ret = gzclose( (gzFile)logref );
	}
	return ret;
}
コード例 #7
0
ファイル: minernet.c プロジェクト: ellierye/Bee2Miner
// TODO: add input buffer
int main(int argc, char *argv[]) { 
  int q;
  int ppc_fd = 0; 
  int  num_q = 4;
  miner_t miner[4];
  int start_port = 8087;

  unsigned int nonce;
  unsigned char bufferin[64];  // 512 bits
  unsigned char bufferout[4];  // 32 bits

  // Initialize HW interface and reset
  ppc_fd = InitQuadInterface();

  if (argc == 2){
    num_q = atoi(argv[1]);
    if (num_q <= 0 || num_q > 4){
      printf("Num Quads must be 1-4\n");
      print_usage(argv);
      exit(1);
    }
  }
  
  for (q = 0; q < num_q; q++){
    SetQuad(q, ppc_fd);
    ResetRW(ppc_fd);
  }

  // Initialize miners: numQ consecutive ports
  for (q = 0; q < num_q; ++q) {
    NetGetConnection(start_port + q,
		     &miner[q].connection);
    miner[q].state = STATE_IDLE;
  }

  while (1) {
    // feed / consume FPGA data
    // Note: several potential sources of lockups here.
    for (q = 0; q < num_q; ++q) {
      SetQuad(q, ppc_fd);
      if (miner[q].state == STATE_WORKING) {
	// Check for available data and read if available.
	if (ReadByteNB(&bufferout[0], ppc_fd)) {
	  ReadByte(&bufferout[1], ppc_fd);
	  ReadByte(&bufferout[2], ppc_fd);
	  ReadByte(&bufferout[3], ppc_fd);
	  // Send
	  NetWrite(&miner[q].connection, bufferout, 4);
	  miner[q].state = STATE_IDLE;
	  // Debug
	  nonce = BufferToNonce(bufferout);
	  printf("Miner(%d) TX nonce: %d  (0x%08x)\n", q, nonce, nonce); 
	}
      } 
      //else if (miner[q].state == STATE_READY) {
      // Just always do this.
      // RX net data and forward to FPGA
      if (NetRead(&miner[q].connection, bufferin, 64) == 64) {
	WriteBuffer(bufferin, 64, ppc_fd);
	miner[q].state = STATE_WORKING;
	printf("Miner(%d) RX data\n", q); 
      }
    } // quad iterator
    
    // TODO: Check sideband for commands.
    
  } // while (1)
  
  // Close connections
  for (q = 0; q < num_q; ++q) {
    NetClose(&miner[q].connection);
  }

  return 0;
} 
コード例 #8
0
ファイル: spo_syslog_full.c プロジェクト: dogbert2/barnyard2
void  OpSyslog_Alert(Packet *p, void *event, uint32_t event_type, void *arg)
{
    OpSyslog_Data *syslogContext = NULL;    
    Unified2EventCommon *iEvent = NULL;

    SigNode                         *sn = NULL;
    ClassType                       *cn = NULL;

    
    char sip[16] = {0};
    char dip[16] = {0};
    
    if( (p == NULL) ||
	(event == NULL) ||
	(arg == NULL))
    {
	LogMessage("OpSyslog_Alert(): Invoked with Packet[0x%x] Event[0x%x] Event Type [%u] Context pointer[0x%x]\n",
		   p,
		   event,
		   event_type,
		   arg);
	return;
    }
    
    if(event_type != UNIFIED2_IDS_EVENT)
    {
        LogMessage("OpSyslog_Alert(): Is currently unable to handle Event Type [%u] \n",
                   event_type);
	return;
    }
    
    
    syslogContext = (OpSyslog_Data *)arg;
    iEvent = event;
    
    memset(syslogContext->payload,'\0',(SYSLOG_MAX_QUERY_SIZE));
    memset(syslogContext->formatBuffer,'\0',(SYSLOG_MAX_QUERY_SIZE));
    syslogContext->payload_current_pos = 0;
    syslogContext->format_current_pos = 0;

    
    switch(syslogContext->operation_mode)
    {

    case 0:  /* Ze Classic (Requested) */

	if(IPH_IS_VALID(p))
	{	
	    if (strlcpy(sip, inet_ntoa(GET_SRC_ADDR(p)), sizeof(sip)) >= sizeof(sip))
	    {
		FatalError("[%s()], strlcpy() error , bailing \n",
			   __FUNCTION__);
		return;
	    }
	    
	    
	    if (strlcpy(dip, inet_ntoa(GET_DST_ADDR(p)), sizeof(dip)) >= sizeof(dip))
	    {
		FatalError("[%s()], strlcpy() error , bailing \n",
		       __FUNCTION__);
		return;
	    }
	}
	
	sn = GetSigByGidSid(ntohl(iEvent->generator_id),
			    ntohl(iEvent->signature_id));
	
	cn = ClassTypeLookupById(barnyard2_conf,
				 ntohl(iEvent->classification_id));
	
	if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
							"[%u:%u:%u] ",
							ntohl(iEvent->generator_id),
							ntohl(iEvent->signature_id),
							ntohl(iEvent->signature_revision))) >=  SYSLOG_MAX_QUERY_SIZE)
	{
	    /* XXX */
	    FatalError("[%s()], failed call to snprintf \n",
		       __FUNCTION__);
	}
	
	if( OpSyslog_Concat(syslogContext))
        {
            /* XXX */
            FatalError("OpSyslog_Concat(): Failed \n");
        }
	
	if(sn != NULL)
	{
	    if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
							    "%s ",
							    sn->msg)) >=  SYSLOG_MAX_QUERY_SIZE)
	    {
		/* XXX */
		FatalError("[%s()], failed call to snprintf \n",
			   __FUNCTION__);
	    }
	}
	else
	{
	    if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
							       "ALERT ")) >=  SYSLOG_MAX_QUERY_SIZE)
            {
                /* XXX */
                FatalError("[%s()], failed call to snprintf \n",
                           __FUNCTION__);
            }
	    
	}
	
	if( OpSyslog_Concat(syslogContext))
        {
            /* XXX */
            FatalError("OpSyslog_Concat(): Failed \n");
        }


	
	if(cn != NULL)
        {
            if( cn->name )
            {
                if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
								"[Classification: %s] [Priority: %d]:",
								cn->name,
								ntohl(((Unified2EventCommon *)event)->priority_id))) >= SYSLOG_MAX_QUERY_SIZE)
		{
		    /* XXX */
		    FatalError("[%s()], failed call to snprintf \n",
			       __FUNCTION__);
		}
		
            }
        }
        else if( ntohl(((Unified2EventCommon *)event)->priority_id) != 0 )
        {
	    if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
							    "[Priority: %d]:",
							    ntohl(((Unified2EventCommon *)event)->priority_id))) >= SYSLOG_MAX_QUERY_SIZE)
	    {
		/* XXX */
		FatalError("[%s()], failed call to snprintf \n",
			   __FUNCTION__);
	    }
        }
	
	if( OpSyslog_Concat(syslogContext))
        {
            /* XXX */
            FatalError("OpSyslog_Concat(): Failed \n");
        }	
	
	
	if( (IPH_IS_VALID(p)) &&	
	    (((GET_IPH_PROTO(p) != IPPROTO_TCP &&
	       GET_IPH_PROTO(p) != IPPROTO_UDP &&
	       GET_IPH_PROTO(p) != IPPROTO_ICMP) ||
	      p->frag_flag)))
	{
	    if(!BcAlertInterface())
	    {
		if(protocol_names[GET_IPH_PROTO(p)])
		{
		    if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
								       " {%s} %s -> %s",
								       protocol_names[GET_IPH_PROTO(p)],
								       sip, dip))   >= SYSLOG_MAX_QUERY_SIZE)
		    {
			/* XXX */
			FatalError("[%s()], failed call to snprintf \n",
				   __FUNCTION__);
		    }
		}
	    }
	    else
	    {
		if(protocol_names[GET_IPH_PROTO(p)])
		{
		    
		    if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
								       " <%s> {%s} %s -> %s",
								       barnyard2_conf->interface,
								       protocol_names[GET_IPH_PROTO(p)],
								       sip, dip)) >= SYSLOG_MAX_QUERY_SIZE)
		    {
			/* XXX */
			FatalError("[%s()], failed call to snprintf \n",
				   __FUNCTION__);
		    
		    }
		}
	    }
	}
	else
	{
	    if(BcAlertInterface())
	    {
		if(protocol_names[GET_IPH_PROTO(p)])
		{
		    if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
								       " <%s> {%s} %s:%i -> %s:%i",
								       barnyard2_conf->interface,
								       protocol_names[GET_IPH_PROTO(p)], sip,
								       p->sp, dip, p->dp)) >= SYSLOG_MAX_QUERY_SIZE)
		    {
			/* XXX */
			FatalError("[%s()], failed call to snprintf \n",
				   __FUNCTION__);
		    }
		}
	    }
	    else
	    {
		if(protocol_names[GET_IPH_PROTO(p)])
		{
		    if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
								       " {%s} %s:%i -> %s:%i",
								       protocol_names[GET_IPH_PROTO(p)], sip, p->sp,
								       dip, p->dp)) >= SYSLOG_MAX_QUERY_SIZE)
		    {
			/* XXX */
			FatalError("[%s()], failed call to snprintf \n",
				   __FUNCTION__);
		    }
		}
	    }
	}
	
	
	if( OpSyslog_Concat(syslogContext))
	{
	    /* XXX */
	    FatalError("OpSyslog_Concat(): Failed \n");
	}

	break;
	
    case 1: /* Ze verbose */
	
	if(Syslog_FormatTrigger(syslogContext, iEvent,0) ) 
	{
	    LogMessage("WARNING: Unable to append Trigger header.\n");
	    return;
	}
	
	/* Support for portscan ip */
	if(p->iph)
	{
	    if(Syslog_FormatIPHeaderAlert(syslogContext, p) ) 
	    {
		LogMessage("WARNING: Unable to append Trigger header.\n");
		return;
	    }
	}	
	
	if(p->iph)
	{
	    /* build the protocol specific header information */
	    switch(p->iph->ip_proto)
	    {
	    case IPPROTO_TCP:
		Syslog_FormatTCPHeaderAlert(syslogContext, p);
		break;
	    case IPPROTO_UDP:
		Syslog_FormatUDPHeaderAlert(syslogContext, p);
		break;
	    case IPPROTO_ICMP:
		Syslog_FormatICMPHeaderAlert(syslogContext, p);
		break;
	    }
	}
	
	/* CHECKME: -elz will update formating later on .. */
	if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
							   "\n")) >= SYSLOG_MAX_QUERY_SIZE)
	{
	    /* XXX */
	    FatalError("Couldn't finalize payload string ....\n");
	}
	
	if( OpSyslog_Concat(syslogContext))
	{
	    /* XXX */
	    FatalError("OpSyslog_Concat(): Failed \n");
	}
	
	break;
	
    default:
	FatalError("[%s()]: Unknown operation_mode ... bailing \n",
		   __FUNCTION__);
	break;
    }
    
    if(NetSend(syslogContext)) 
    {
	NetClose(syslogContext);
	if(syslogContext->local_logging != 1)
	{
	    FatalError("NetSend(): call failed for host:port '%s:%u' bailing...\n", syslogContext->server, syslogContext->port);
	}
    }


    return;
}
コード例 #9
0
ファイル: spo_syslog_full.c プロジェクト: dogbert2/barnyard2
void OpSyslog_Log(Packet *p, void *event, uint32_t event_type, void *arg)
{
    
    OpSyslog_Data *syslogContext = NULL;
    Unified2EventCommon *iEvent = NULL;
    
    if( (p == NULL) ||
        (event == NULL) ||
        (arg == NULL))
    {
        LogMessage("OpSyslog_Log(): Invoked with Packet[0x%x] Event[0x%x] Event Type [%u] Context pointer[0x%x]\n",
                   p,
                   event,
		   event_type,
                   arg);
        return;
    }
    
    if(event_type != UNIFIED2_IDS_EVENT)
    {
	LogMessage("OpSyslog_Log(): Is currently unable to handle Event Type [%u] \n",
		   event_type);
    }

    syslogContext = (OpSyslog_Data *)arg;
    iEvent = event;

    memset(syslogContext->payload,'\0',(SYSLOG_MAX_QUERY_SIZE));
    memset(syslogContext->formatBuffer,'\0',(SYSLOG_MAX_QUERY_SIZE));
    syslogContext->payload_current_pos = 0;
    syslogContext->format_current_pos = 0;
    
    if(Syslog_FormatTrigger(syslogContext, iEvent,1) ) 
    {
	FatalError("WARNING: Unable to append Trigger header.\n");
    }
    
    if(p->iph)
    {
	Syslog_FormatIPHeaderLog(syslogContext, p);
    }
    
    if(p->iph)
    {
	switch(p->iph->ip_proto)
	{
	case IPPROTO_ICMP:
	    Syslog_FormatICMPHeaderLog(syslogContext, p);
	    break;
	case IPPROTO_TCP:
	    Syslog_FormatTCPHeaderLog(syslogContext, p);
		break;
	case IPPROTO_UDP:
	    Syslog_FormatUDPHeaderLog(syslogContext, p);
	    break;
	}
    }
    
    Syslog_FormatPayload(syslogContext, p);    
    
    /* CHECKME: -elz will update formating later on .. */
    if( (syslogContext->format_current_pos += snprintf(syslogContext->formatBuffer,SYSLOG_MAX_QUERY_SIZE,
                                                       "\n")) >= SYSLOG_MAX_QUERY_SIZE)
    {
        /* XXX */
        FatalError("Couldn't finalize payload string ....\n");
    }
    
    if( OpSyslog_Concat(syslogContext))
    {
        /* XXX */
        FatalError("OpSyslog_Concat(): Failed \n");
    }
    
    if(NetSend(syslogContext)) 
    {
	NetClose(syslogContext);
	//Reliability...
	FatalError("WARNING: Unable to connect to our syslog host: '%s:%u'\n", syslogContext->server, syslogContext->port);
	
	return;
    }
    
    return;
}