예제 #1
0
파일: SASA.C 프로젝트: iplusu/sarp
int
TSASA::Send (unsigned char* queue, int queueSize, int rec_queueSize)
{
  unsigned char *p = queue, ch;
  int i = queueSize;
  
  if (rec_queueSize==-1){rec_queueSize = queueSize;}
#ifdef DEBUG
  printf ("send(recv): ");
#endif
  while (i--){
#ifdef DEBUG
    printf ("%02X(", (unsigned int)*p);
#endif    
    ch = SendRecv(*p);
#ifdef DEBUG    
    printf ("%02X) ", (unsigned int)ch);
#endif    
    *p++ = ch;
  }
#ifdef DEBUG  
  printf ("\n");
#endif  
  return queueSize;
}
예제 #2
0
파일: SMTP.cpp 프로젝트: DeegC/10d
// Default destructor
Smtp::~Smtp( )
{
   CHAR cBuffer[ 256 ];
   if ( m_SA )
   {
      SendRecv( "QUIT", "\r\n" );
     ::Sleep( 1000 );
     INT iErr = shutdown( m_SA, SD_SEND );
     if ( iErr == SOCKET_ERROR )
        INT iLastError = WSAGetLastError();

     for ( ; ; )
    {
        INT iRC = recv( m_SA, cBuffer, zsizeof( cBuffer ), 0 );
        if ( iRC == 0 || iRC == SOCKET_ERROR )
           break;
    }
     iErr = closesocket( m_SA );
     if ( iErr == SOCKET_ERROR )
        INT iLastError = WSAGetLastError();
   }

   WSACleanup( );
   m_SA = 0;
   m_bEhloNotSent = FALSE;
}
예제 #3
0
/**
 * @ingroup SnmpStack
 * @brief SNMPv2 이면 SNMP 요청 메시지를 전송한 후, 이에 대한 응답 메시지를 수신한다.
 *				SNMPv3 이면 SNMP 요청 메시지를 전송한 후, 이에 대한 응답 메시지 수신후, 다시 SNMP 요청 메시지를 전송한 후, 이에 대한 응답 메시지를 수신한다.
 * @param pclsRequest		SNMP 요청 메시지
 * @param pclsResponse	SNMP 응답 메시지
 * @returns 성공하면 true 를 리턴하고 실패하면 false 를 리턴한다.
 */
bool CSnmpSession::SendRequest( CSnmpMessage * pclsRequest, CSnmpMessage * pclsResponse )
{
	if( SendRecv( pclsRequest, pclsResponse ) == false ) return false;

	if( pclsRequest->m_cMsgFlags == SNMP_MSG_FLAG_REPORT )
	{
		CSnmpMessage * pclsSecondRequest = CSnmpMessage::Create( pclsRequest );
		if( pclsSecondRequest )
		{
			pclsSecondRequest->m_iMsgId = ++m_iRequestId;
			pclsSecondRequest->m_iRequestId = pclsSecondRequest->m_iMsgId;
			pclsSecondRequest->m_strMsgAuthEngineId = pclsResponse->m_strMsgAuthEngineId;
			pclsSecondRequest->m_iMsgAuthEngineBoots = pclsResponse->m_iMsgAuthEngineBoots;
			pclsSecondRequest->m_iMsgAuthEngineTime = pclsResponse->m_iMsgAuthEngineTime;
			pclsSecondRequest->m_strMsgUserName = pclsSecondRequest->m_strUserId;
			pclsSecondRequest->m_strContextEngineId = pclsResponse->m_strContextEngineId;

			pclsSecondRequest->SetPrivParams( );
			pclsSecondRequest->SetAuthParams( );

			bool bRes = SendRecv( pclsSecondRequest, pclsResponse );
			delete pclsSecondRequest;

			if( bRes == false ) return false;

			if( pclsResponse->m_cMsgFlags & SNMP_MSG_FLAG_AUTH )
			{
				pclsResponse->m_strAuthPassWord = pclsRequest->m_strAuthPassWord;

				if( pclsResponse->CheckAuth() == false )
				{
					return false;
				}
			}

			if( pclsResponse->m_strEncryptedPdu.empty() == false )
			{
				pclsResponse->m_strPrivPassWord = pclsRequest->m_strPrivPassWord;
				pclsResponse->ParseEncryptedPdu( );
			}
		}
	}

	return true;
}
예제 #4
0
int Init_System( reax_system *system, control_params *control, 
		 simulation_data *data, storage *workspace, 
		 mpi_datatypes *mpi_data, char *msg )
{
  int i;
  reax_atom *atom;
  int nrecv[MAX_NBRS];
  
  Setup_New_Grid( system, control, mpi_data->world );
#if defined(DEBUG_FOCUS)
  fprintf( stderr, "p%d GRID:\n", system->my_rank );
  Print_Grid( &(system->my_grid), stderr );
#endif
  Bin_My_Atoms( system, &(workspace->realloc) );
  Reorder_My_Atoms( system, workspace );

  /* estimate N and total capacity */
  for( i = 0; i < MAX_NBRS; ++i ) nrecv[i] = 0;
  system->max_recved = 0;
  system->N = SendRecv( system, mpi_data, mpi_data->boundary_atom_type, nrecv,
			Estimate_Boundary_Atoms, Unpack_Estimate_Message, 1 );
  system->total_cap = MAX( (int)(system->N * SAFE_ZONE), MIN_CAP );
  Bin_Boundary_Atoms( system );

  /* estimate numH and Hcap */
  system->numH = 0;
  if( control->hbond_cut > 0 )
    for( i = 0; i < system->n; ++i ) {
      atom = &(system->my_atoms[i]);
      if( system->reax_param.sbp[ atom->type ].p_hbond == 1 )
	atom->Hindex = system->numH++;
      else atom->Hindex = -1;
    }
  system->Hcap = MAX( system->numH * SAFER_ZONE, MIN_CAP );

  //Allocate_System( system, system->local_cap, system->total_cap, msg ); 
#if defined(DEBUG_FOCUS)
  fprintf( stderr, "p%d: n=%d local_cap=%d\n", 
	   system->my_rank, system->n, system->local_cap );
  fprintf( stderr, "p%d: N=%d total_cap=%d\n", 
	   system->my_rank, system->N, system->total_cap );
  fprintf( stderr, "p%d: numH=%d H_cap=%d\n", 
	   system->my_rank, system->numH, system->Hcap );
#endif
 
  // if( Reposition_Atoms( system, control, data, mpi_data, msg ) == FAILURE )
  //   return FAILURE;
  
  /* initialize velocities so that desired init T can be attained */
  if( !control->restart || (control->restart && control->random_vel) )  
    Generate_Initial_Velocities( system, control->T_init );
  
  return SUCCESS;
}
예제 #5
0
int Net::SendRecv(in_addr_t ip, uint16_t port,
		const void* sendBuf, uint32_t pkgLen, void* recvBuf,
		uint32_t& recvLen) {

	sockaddr_in toAddr = {0};
	toAddr.sin_family = AF_INET;
	toAddr.sin_port = htons(port);
	toAddr.sin_addr.s_addr = ip;

	return SendRecv(toAddr, sendBuf, pkgLen, recvBuf, recvLen);
}
예제 #6
0
int Net::SendRecv(string ip, uint16_t port,
		const void* sendBuf, uint32_t pkgLen, void* recvBuf,
		uint32_t& recvLen) {
	return SendRecv(inet_addr(ip.c_str()), port, sendBuf, pkgLen, recvBuf, recvLen);
}
예제 #7
0
void stream_video(void) {
    char stream_buf[VIDEO_INBUF_SZ + 16]; // padded so libavcodec detects the end
    SOCKET videoSocket = INVALID_SOCKET;
    int keep_waiting = 0;

    if (g_ip != NULL) {
        videoSocket = connectDroidCam(g_ip, g_port);
        if (videoSocket == INVALID_SOCKET) {
            return;
        }
    }
    v_running  =1;
_wait:
    // We are the server
    if (videoSocket == INVALID_SOCKET) {
        videoSocket = accept_inet_connection(g_port);
        if (videoSocket == INVALID_SOCKET) { goto _out; }
        keep_waiting = 1;
    }
    {
        int L = sprintf(stream_buf, VIDEO_REQ, g_webcam_w, g_webcam_h);
        if ( SendRecv(1, stream_buf, L, videoSocket) <= 0 ){
            MSG_ERROR("Connection lost!");
            goto _out;
        }
        dbgprint("Sent request, ");
    }
    memset(stream_buf, 0, sizeof(stream_buf));
    if ( SendRecv(0, stream_buf, 5, videoSocket) <= 0 ){
        MSG_ERROR("Connection reset!\nDroidCam is probably busy with another client");
        goto _out;
    }

    if (decoder_prepare_video(stream_buf) == FALSE) { goto _out; }

    while (1){
        int frameLen;
        char *p = stream_buf;
        if (SendRecv(0, p, 4, videoSocket) == FALSE) goto _out;
        make_int4(frameLen, p[0], p[1], p[2], p[3]);
        SetImageFrameSize(frameLen);

        p = GetImageFrameBuf();
        while (frameLen > 4096) {
            if (SendRecv(0, p, 4096, videoSocket) == FALSE) goto _out;
            frameLen -= 4096;
            p += 4096;
        }
        if (SendRecv(0, p, frameLen, videoSocket) == FALSE) goto _out;
        if (DecodeFrame() == FALSE) break;
    }

_out:
    dbgprint("disconnect\n");
    disconnect(videoSocket);
    decoder_cleanup();

    if (keep_waiting){
        videoSocket = INVALID_SOCKET;
        goto _wait;
    }
    v_running = 0;
    connection_cleanup();
}
예제 #8
0
파일: SMTP.cpp 프로젝트: DeegC/10d
BOOL Smtp::CreateSmtpMessage( CHAR *cpSmtpServer,
                       CHAR *cpFrom,
                       CHAR *cpTo[],
                       INT cTo,
                       CHAR *cpSubject,
                       INT nMimeType,  //  1 - text; 2 - html
                       CHAR *cpBody,
                       INT nHasAttachment, // 0 - No;  1 -yes
                       CHAR *cpAttachFile)
{
   FILE *fp1;

   CHAR szBody1[5120] = "" ;
   CHAR szString1[1024];

   m_iCount++;
   if ( m_bEhloNotSent )
   {
      if ( !SendRecv( "EHLO ", "\r\n" ) )
        return( FALSE );
      m_bEhloNotSent = FALSE;
   }
   if ( !SendRecv( "MAIL FROM: ", cpFrom, "\r\n" ) )
      return( FALSE );

   for ( INT j = 0; j < cTo; j++ )
   {
     if ( !SendRecv( "RCPT TO: ", cpTo[ j ], "\r\n" ) )
       return( FALSE );
   }
   if ( !SendRecv( "DATA", "\r\n" ) )
      return( FALSE );

   FormatedDate fd;

   _TCHAR *tcpDate = fd.GetFormatedDate();
   if ( !Send( tcpDate, "\r\n" ) )
      return( FALSE );
   delete [] tcpDate;

   if ( !Send( "FROM: ", cpFrom, "\r\n" ) )
      return( FALSE );

   for ( j = 0; j < cTo; j++ )
   {
      if ( !Send( "TO: ", cpTo[ j ], "\r\n" ) )
         return( FALSE );
   }

   if ( !Send( "SUBJECT: ", cpSubject, "\r\n" ) )
      return( FALSE );

   prepare_header();
   if ( nMimeType == 2 )
   {
      if (nHasAttachment == 1 ) // so this is HTML And Attachment
      {
           insert_mixed_part();
         insert_boundry();
      }
       insert_html_part();
   }
   else // plain text with or without attachment
   {
      if (nHasAttachment == 1 )  // this is plain text with attachment
      {
           insert_mixed_part();
         insert_boundry();
      }
       insert_text_part();
   }
   // set the encoding
   if ( !Send( "Content-Transfer-Encoding: ", "7bit", "\r\n", "\r\n" ) )
      return( FALSE );
   // do the body
   if ( !Send( cpBody ) )
      return( FALSE );
   if ( !Send( "\r\n" ) )
      return( FALSE );

   // add attachments here if necessary
   if (nHasAttachment == 1 )
   {
      //insert_end_boundry();
      insert_boundry();

      if ( !Send( "Content-Type: APPLICATION/octet-stream; name=\"", cpAttachFile,"\"", "\r\n" ) )
         return( FALSE );
      if ( !Send( "Content-Transfer-Encoding: 7bit", "\r\n" ) )
         return( FALSE );
      if ( !Send( "Content-Disposition: attachment; filename=\"", cpAttachFile,"\"", "\r\n" ) )
         return( FALSE );
      if ( !Send( "\r\n" ) )
         return( FALSE );
       /////////////////////
   strcpy( szBody1, "");
   fp1 = fopen(cpAttachFile,"r");
   while (fgets(szString1,1024,fp1))
   {
      strcat( szBody1, szString1 );
   }
   fclose(fp1);
      /////////////////////

      if ( !Send( szBody1 ) )
         return( FALSE );

      insert_end_boundry();

   }

   // end th body
   if ( !Send( "\r\n" ) )
      return( FALSE );

   if ( !SendRecv( ".", "\r\n" ) )
      return( FALSE );

   return( TRUE );
}