⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ora_package.c

📁 网管程序.应用于网管主机之间按照规则交换网管数据
💻 C
字号:
/********************************************************************************     文件名称: ora_package.c*     功    能:  各类报文组织函数*                *     作    者:  黄强存*     编写日期:  2004.12.13*     编写地点:  天津移动*     编写单位:  创我科技**     命名规范:  函数名:	SendReqAuth;*                变量:		char strDigestD[ 50 ];  *                函数返回整数*                指针以p开头; 字符数组以str开头*                 *     修改记录:  夏颖昌*            1、 2005年01月07日:*            2、 2005年01月11日:*******************************************************************************/#include 	<signal.h>#include	"binm_socket.h"#include	"md5c_tjbi.h"#include	"TNMPNMPStack.h" int SendReqAuth( int sockFD ){   int		 i, nLen;   MD5_CTX	 context;   char		 strTemp[ 6 + 1 ];	   unsigned char strMD5Temp[ 16 + 1 ];   char       	 g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	 g_pPnmpData;	   memset( g_strBuffer, 0x00,  sizeof( g_strBuffer ));   InitStruct( &g_pPnmpData );	   //赋值	   g_pPnmpData.pdVerson = 1.0;   g_pPnmpData.pdPackageType = 1;   g_pPnmpData.pdCommand = 1;   strcpy( g_pPnmpData.pdUser, NM_USER );   strcpy( g_pPnmpData.pdServer, NM_HOST_IP );   memset( strTemp, 0x00, sizeof( strTemp ));   sprintf( strTemp, ":%d", NM_PORT );   strcat( g_pPnmpData.pdServer, strTemp );   strcpy( g_pPnmpData.pdClient, BI_HOST_IP );   memset( strTemp, 0x00, sizeof( strTemp ));   sprintf( strTemp, ":%d", BI_PORT );   strcat( g_pPnmpData.pdClient, strTemp );   strcpy( g_pPnmpData.pdHostId, BI_HOST_NAME );	   //passwd md5		   MD5Init( &context );		   nLen = strlen( NM_PASSWD );   MD5Update( &context, NM_PASSWD, nLen );			   MD5Final( strMD5Temp, &context );	   //printf("Now the md5 string is: %s \n", strMD5Temp);   if( ToBase64( strMD5Temp, g_pPnmpData.pdPassWord, 16, &nLen ) == -1 )   {      printf( "Error: Passwd To Base64 error\n" );      return( -1 );   }   //strcpy( g_pPnmpData.pdPassWord, NM_PASSWD );   //封装包数据   if( BuildData( &g_pPnmpData, g_strBuffer ) != 0 )   {      printf( "Error: Call the BuildData is error\n" );      return( -1 );		   }   printf("Send: Auth Req***[%s]\n", g_strBuffer );   //printf( "Send the Req Auth---Buffer_Len=[%d]\n", strlen( g_strBuffer ));	   //利用socket 发送数据   i = 0;   while( 1 )   {      if( ++i > 3 )      {         printf( "Error: Write the ReqAuth Failed\n" );          return( -1 );      }      if(( write( sockFD, g_strBuffer, strlen( g_strBuffer ))) <= 0 )          continue;      else      {          //printf( "Send the Req Auth successful!\n" );          break;      }   }	   return 0;}int ReceiveData2( int sockFD, PNMP_DATA *pPnmpData )    {   int		i, sts;   fd_set	rdset;   char		g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	g_pPnmpData;   struct timeval tv;		   tv.tv_sec = 300;   tv.tv_usec = 0;   FD_ZERO( &rdset );   FD_SET( sockFD, &rdset );		   memset(( char *)g_strBuffer, 0x00, sizeof( g_strBuffer ));   InitStruct( &g_pPnmpData );   //利用socket 接收数据   if(( sts = select( sockFD + 1, &rdset, NULL, NULL, &tv )) <= 0 )   {      printf( "Error: select time out --- sts=[%d]\n", sts );      return( -2 );   }	   if( read( sockFD, g_strBuffer, MAX_NUM ) == -1 )    {      printf( "Error: read socket failed(ReceiveData2)\n" );       return( -1 );   }   printf("Rece: (ReceiveData2)***[%s]\n", g_strBuffer );   //拆包数据   if( ParserData( g_strBuffer, &g_pPnmpData ) < 0 )   {       printf( "Error: Call ParserData Failed: %s\n",strerror( errno ));       return( FAILED_RETURN_CODE );    } 	   memcpy( pPnmpData, &g_pPnmpData, sizeof( PNMP_DATA));	   return( SUCCESSED_RETURN_CODE );}int ReceiveData( int sockFD, PNMP_DATA *pPnmpData )    {   int		i, sts;   fd_set	rdset;   char		g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	g_pPnmpData;   struct timeval tv;		   tv.tv_sec = WAIT_TIME_OUT;   tv.tv_usec = 0;   FD_ZERO( &rdset );   FD_SET( sockFD, &rdset );		   memset(( char *)g_strBuffer, 0x00, sizeof( g_strBuffer ));   InitStruct( &g_pPnmpData );   //利用socket 接收数据   if(( sts = select( sockFD + 1, &rdset, NULL, NULL, &tv )) <= 0 )   {      printf( "Error: select time out --- sts=[%d]\n", sts);      return( -2 );   }   i = 0;   while( 1 )   {      if( ++i > 3 )      {         printf( "Error: read socket failed\n" );          return( -1 );      }      if( read( sockFD, g_strBuffer, MAX_NUM ) == -1 )          continue;      else         break;   }/*   if( read( sockFD, g_strBuffer, MAX_NUM ) == -1 )   {      printf( "Error: read socket failed(ReceiveData)\n" );      return( -1 );   }*/   printf("Rece: (ReceiveData)***[%s]\n", g_strBuffer );   //拆包数据   if( ParserData( g_strBuffer, &g_pPnmpData ) < 0 )   {       printf( "Error: Call ParserData Failed: %s\n",strerror( errno ));       return( FAILED_RETURN_CODE );    } 	   memcpy( pPnmpData, &g_pPnmpData, sizeof( PNMP_DATA ));	   return( SUCCESSED_RETURN_CODE );}//发送任务请求int SendReqTask( int sockFD, char* pSequence, char* fileName ){   int		i, nLen;   char		strDateTime[ 20 + 1 ];   char		strTemp[ 6 + 1 ];	   char       	g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	g_pPnmpData;	   memset( g_strBuffer, 0x00,  sizeof( g_strBuffer ));   InitStruct( &g_pPnmpData );	//PKG PNMP/1.0\r\n//Package-Type: REQ\r\n//Command: Task\r\n//Sequence: BITask0034501\r\n//Parameter: M0411820031125100000.avl\r\n//\r\n	   //赋值	   g_pPnmpData.pdVerson = 1.0;   g_pPnmpData.pdPackageType = 1;   g_pPnmpData.pdCommand = 2;	//Task 2   strcpy( g_pPnmpData.pdSequence, pSequence );   strcpy( g_pPnmpData.pdParameter, fileName );		   //封装包数据   if( BuildData( &g_pPnmpData, g_strBuffer ))   {      printf( "Error: Call the BuildData failed\n" );      return( -1 );		   }   printf( "Send: Req Task***[%s]\n", g_strBuffer );   //printf( "Send the Req Task---BufferLen=[%d]\n", strlen( g_strBuffer));	   //利用socket 发送数据   i = 0;   while( 1 )   {      if( ++i > 3 )      {         printf( "Error: write socket failed\n" );          return( -1 );      }      if( write( sockFD, g_strBuffer, strlen( g_strBuffer )) == -1 )          continue;      else      {          //printf( "Write the ReqTask successful!\n" );          break;      }    }   return 0;}//发送成功下载的MSGint SendMsgTaskSucc( int sockFD, char* pSequence, char* fileName ){   int		i, nLen;   char		strDateTime[ 20 + 1 ];   char		strTemp[ 6 + 1 ];   char       	g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	g_pPnmpData;	   InitStruct( &g_pPnmpData );	//PKG PNMP/1.0\r\n//Package-Type: MSG\r\n//Command: DownloadFinish\r\n//Status: 2\r\n//Sequence: BITask0034502\r\n//Parameter: M0411820031124100000.avl\r\n//\r\n	   //赋值	   g_pPnmpData.pdVerson = 1.0;   g_pPnmpData.pdPackageType = 3;   g_pPnmpData.pdCommand = 6;	//DownloadFinish 6   g_pPnmpData.pdStatus = 2 ;	   strcpy( g_pPnmpData.pdSequence, pSequence );   //strcpy( g_pPnmpData.pdParameter, fileName );   strcpy( g_pPnmpData.pdPassWord, fileName );		          //封装包数据   if( BuildData( &g_pPnmpData, g_strBuffer ))   {      printf( "Error: Call the BuildData Failed!\n" );      return( -1 );		   }   printf( "Send: MsgTaskSucc***[%s]\n", g_strBuffer );   //printf( "Send Msg Task Succ---BufferLen=[%d]\n", strlen( g_strBuffer ));	   //利用socket 发送数据   i = 0;   while( 1 )   {      if( ++i > 3 )      {         printf( "Error: write socket failed\n" );          return( -1 );      }      if( write( sockFD, g_strBuffer, strlen( g_strBuffer )) == -1 )          continue;      else      {          //printf( "Write the MsgTaskSucc successful!\n" );          break;      }    }	   return 0;}//发送失败下载的MSGint SendMsgTaskFail( int sockFD, char* pSequence, char* fileName ){   int		i, nLen;   char		strDateTime[ 20 + 1 ];   char		strTemp[ 6 + 1 ];   char       	g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	g_pPnmpData;	   InitStruct( &g_pPnmpData );	//PKG PNMP/1.0\r\n//Package-Type: MSG\r\n//Command: DownloadFinish\r\n//Status: 2\r\n//Sequence: BITask0034502\r\n//Parameter: M0411820031124100000.avl\r\n//\r\n	   //赋值	   g_pPnmpData.pdVerson = 1.0;   g_pPnmpData.pdPackageType = 3;   g_pPnmpData.pdCommand = 6;	//DownloadFinish 6   g_pPnmpData.pdStatus = 106 ;	//数据不全   strcpy( g_pPnmpData.pdSequence, pSequence );   //strcpy( g_pPnmpData.pdParameter, fileName );   strcpy( g_pPnmpData.pdPassWord, fileName );		          //封装包数据   if( BuildData( &g_pPnmpData, g_strBuffer ))   {      printf( "Error: Call the BuildData Failed!\n" );      return( -1 );		   }   printf( "Send: MsgTaskFail***[%s]\n", g_strBuffer );   //printf( "Send Msg Task Fail---BufferLen=[%d]\n", strlen( g_strBuffer ));	   //利用socket 发送数据   i = 0;   while( 1 )   {      if( ++i > 3 )      {         printf( "Error: write socket failed\n" );          return( -1 );      }      if( write( sockFD, g_strBuffer, strlen( g_strBuffer )) == -1 )          continue;      else      {          //printf( "Write the MsgTaskFail successful!\n" );          break;      }    }	   return 0;}int SendReqSync( int sockFD ){   int		i, nLen;   int		n;   char		strDateTime[ 16 + 1 ];   char       	g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	g_pPnmpData;   memset( g_strBuffer, 0x00,  sizeof( g_strBuffer ));   InitStruct( &g_pPnmpData );//PKG PNMP/1.0\r\n//Package-Type: REQ\r\n//Command: Sync\r\n//Parameter: 2003-12-04_10:37:03\r\n//\r\n   //赋值   g_pPnmpData.pdVerson = 1.0;   g_pPnmpData.pdPackageType = 1;   g_pPnmpData.pdCommand = 3;   GetTime( strDateTime );   sprintf( g_pPnmpData.pdParameter, "%c%c%c%c-%c%c-%c%c_%c%c:%c%c:%c%c", strDateTime[0], strDateTime[1],strDateTime[2],strDateTime[3],strDateTime[4],strDateTime[5],strDateTime[6],strDateTime[7],strDateTime[8],strDateTime[9],strDateTime[10],strDateTime[11],strDateTime[12],strDateTime[13]);   //封装包数据   if( BuildData( &g_pPnmpData, g_strBuffer ))   {      printf( "Error: Call the BuildData Failed!\n" );      return( -1 );   }   printf( "Send: Req Sync***[%s]\n", g_strBuffer );   //printf( "Send the Req Sync---BufferLen=[%d]\n", strlen( g_strBuffer ));   //利用socket 发送数据   i = 0;   while( 1 )   {      if( ++i > 3 )      {         printf( "Error: write socket failed\n" );         return( -1 );      }      if( write( sockFD, g_strBuffer, strlen( g_strBuffer )) <= 0 )      {         printf( "Error: write Failed: %s\n",strerror( errno ));         //signal(SIGIO, SIG_IGN);         signal(SIGPIPE, SIG_IGN);         continue;      }      else      {         //printf( "Write the ReqSync successful!\n" );         break;      }   }   return( SUCCESSED_RETURN_CODE );}int SendAckSync( int sockFD ){//PKG PNMP/1.0\r\n//Package-Type: ACK\r\n//Status: 0\r\n//\r\n   int		i;   char		strTemp[ 6 + 1 ];   char       	g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	g_pPnmpData;   memset( g_strBuffer, 0x00,  sizeof( g_strBuffer ));   InitStruct( &g_pPnmpData );   //赋值   g_pPnmpData.pdVerson = 1.0;   g_pPnmpData.pdPackageType = 2;   g_pPnmpData.pdStatus = 0;   //封装包数据   if( BuildData( &g_pPnmpData, g_strBuffer ))   {      printf("Error: Call BuildData Failed\n");      return( -1 );   }   printf( "Send: Ack Sync***[%s]\n", g_strBuffer );   //利用socket 发送数据   i = 0;   while( 1 )   {      if( ++i > 3 )      {         printf( "Error: write socket failed\n" );         return( -1 );      }      if( write( sockFD, g_strBuffer, strlen( g_strBuffer )) <= 0 )         continue;      else      {         //printf( "Write the AckSync successful!\n" );         break;      }   }   return 0;}int SendAckAuth( int sockFD ){//PKG PNMP/1.0\r\n//Package-Type: ACK\r\n//Status: 0\r\n//\r\n   int		i;   char		strTemp[ 6 + 1 ];	   char       	g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	g_pPnmpData;   memset( g_strBuffer, 0x00,  sizeof( g_strBuffer ));   InitStruct( &g_pPnmpData );	   //赋值	   g_pPnmpData.pdVerson = 1.0;   g_pPnmpData.pdPackageType = 2;   g_pPnmpData.pdStatus = 0;         //封装包数据   if( BuildData( &g_pPnmpData, g_strBuffer ))   {      printf( "Error: Call the BuildData Failed!\n");      return( -1 );		   }   printf( "Send: Ack Auth***[%s]\n", g_strBuffer );   //printf( "Send the Ack Auth---BufferLen=[%d]\n", strlen( g_strBuffer ));	   //利用socket 发送数据   i = 0;   while( 1 )   {      if( ++i > 3 )      {         printf( "Error: write socket failed\n" );          return( -1 );      }      if( write( sockFD, g_strBuffer, strlen( g_strBuffer )) <= 0 )          continue;      else      {          //printf( "Write the AckAuth successful!\n" );          break;      }    }	   return 0;}int SendAck( int sockFD, int status ){//PKG PNMP/1.0\r\n//Package-Type: ACK\r\n//Status: 0\r\n//\r\n   int		i;   char		strTemp[ 6 + 1 ];	   char       	g_strBuffer[ MAX_NUM + 1 ];   PNMP_DATA	g_pPnmpData;   memset( g_strBuffer, 0x00,  sizeof( g_strBuffer ));   InitStruct( &g_pPnmpData );	   //赋值	   g_pPnmpData.pdVerson = 1.0;   g_pPnmpData.pdPackageType = 2;   g_pPnmpData.pdStatus = status;         //封装包数据   if( BuildData( &g_pPnmpData, g_strBuffer ))   {      printf( "Error: Call BuildData Failed!\n");      return( -1 );		   }   printf( "Send: Ack ***[%s]\n", g_strBuffer );	   //利用socket 发送数据   i = 0;   while( 1 )   {      if( ++i > 3 )      {         printf( "Error: write socket failed\n" );          return( -1 );      }      if( write( sockFD, g_strBuffer, strlen( g_strBuffer )) <= 0 )          continue;      else      {          //printf( "Write the Ack successful!\n" );          break;      }    }	   return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -