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

📄 tcpip.c

📁 ST for linux SDK采用的tcp/ip协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:
   print("+-------+-------------+---------------------------------------------+------+\n");
   for (i=0;i<TCPIP_MAX_STREAMS;i++)
    {
     if (TT_TCPIPi_Stream[i].Name[0]!=0) print("|   %d   | %s         | %-43s |   %c  |\n",TT_TCPIPi_Stream[i].NetId,TT_TCPIPi_Stream[i].Name,TT_TCPIPi_Stream[i].Params,TT_TCPIPi_Stream[i].Mode);
    }
   print("+-------+-------------+---------------------------------------------+------+\n");
   return(FALSE);
  }

 /* Check stream name */
 /* ----------------- */
 if (strlen(STR_Name)!=3)
  {
   print("--> Invalid stream name, should be [\"IP0\",\"IP1\",\"IP2\",\"IP3\"] !\n");
   return(TRUE);
  }
 if ((STR_Name[0]!='I')||(STR_Name[1]!='P')||((STR_Name[2]!='0')&&(STR_Name[2]!='1')&&(STR_Name[2]!='2')&&(STR_Name[2]!='3')))
  {
   print("--> Invalid stream name, should be [\"IP0\",\"IP1\",\"IP2\",\"IP3\"] !\n");
   return(TRUE);
  }
 
 /* Get the parameters of the stream */
 /* -------------------------------- */
 if (cget_string(pars_p,"-",STR_Params,sizeof(STR_Params))==TRUE)
  {
   tag_current_line(pars_p,"Invalid stream parameters, should be [\"-\" to delete the stream or \"udp://192.168.0.43:32782\"]");
   return(TRUE);
  }
 
 /* If we want to delete the stream */
 /* ------------------------------- */
 if (strcmp((char *)STR_Params,"-")==0)
  {
   for (i=0;i<TCPIP_MAX_STREAMS;i++)
    {
     if (strcmp(STR_Name,TT_TCPIPi_Stream[i].Name)==0) break;
    } 
   if (i==TCPIP_MAX_STREAMS)
    {
     print("--> This stream \"%s\" doesn't exists !\n",STR_Name);
     return(TRUE);
    }
   ErrCode=TCPIP_CloseStream(TT_TCPIPi_Stream[i].Handle);
   if (ErrCode!=ST_NO_ERROR)
    { 
     print("--> Unable to delete the stream \"%s\" !\n",STR_Name);
     return(TRUE);
    }
   print("--> Stream \"%s\" has been deleted\n",STR_Name);
   for (i=0;i<TCPIP_MAX_STREAMS;i++)
    {
     if (strcmp(STR_Name,TT_TCPIPi_Stream[i].Name)==0)
      {
       memset(&TT_TCPIPi_Stream[i],0,sizeof(TT_TCPIPi_Stream_t));
       break;
      }
    } 
   return(FALSE);
  }

 /* Check if already exists */
 /* ----------------------- */
 for (i=0;i<TCPIP_MAX_STREAMS;i++)
  {
   if (strcmp(TT_TCPIPi_Stream[i].Name,STR_Name)==0)
    {
     print("--> This stream name already exists !\n");
     return(TRUE);
    }
  }
 
 /* Get the mode of the stream */
 /* -------------------------- */
 if (cget_string(pars_p,"r",STR_Mode,sizeof(STR_Mode))==TRUE)
  {
   tag_current_line(pars_p,"Invalid stream mode, should be [\"r\" or \"w\"] !");
   return(TRUE);
  }
 if ((strlen(STR_Mode)!=1)||((STR_Mode[0]!='r')&&(STR_Mode[0]!='w')))
  {
   print("--> Invalid stream mode, should be [\"r\" or \"w\"] !\n");
   return(TRUE);
  } 
    
 /* Check params */
 /* ------------ */
 /* Stream parameters could be : */
 /* "udp://@:12345               */
 /* "udp://192.168.0.50:12345    */
 /* "rtp://@:12345               */
 /* "rtp://192.168.0.50:12345    */
 /* "rtsp://192.168.0.50:12345   */
 {
  U8  Protocole[16];
  U8  Address[TCPIP_MAX_STRING];
  U32 Port;
  /* String size should be at least "xxx://x:x" --> 9 bytes */
  if (strlen(STR_Params)<9)
   {
    print("--> Invalid stream params, should be [\"udp://192.168.0.100:32784\"] !\n");
    return(TRUE);
   } 
  /* Look for protocole */         
  for (i=0;i<(strlen(STR_Params)-3);i++)
   {
    if ((STR_Params[i]==':')&&(STR_Params[i+1]=='/')&&(STR_Params[i+2]=='/')) break;
   }
  if (i==(strlen(STR_Params)-3))
   {
    print("--> Invalid protocole in stream parameters, should be [\"udp://\",\"rtp://\",\"rtsp://\"] !\n");
    return(TRUE);
   }
  strncpy((char *)Protocole,(char *)STR_Params,i); Protocole[i]=0;
  if ((strcmp((char *)Protocole,"udp")!=0)&&(strcmp((char *)Protocole,"rtp")!=0)&&(strcmp((char *)Protocole,"rtsp")!=0))
   {
    print("--> Protocole not supported in stream parameters, should be [\"udp://\",\"rtp://\",\"rtsp://\"] !\n");
    return(TRUE);
   }
  /* Look for address */
  i=i+3;
  if ((STR_Params[i]!='@')&&(STR_Params[i+1]!=':'))
   {
    U32 a,b,c,d;
    for (j=i;j<strlen(STR_Params);j++)
     {
      if (STR_Params[j]==':') break;
     }
    if (j==strlen(STR_Params))
     {
      print("--> Invalid address in stream parameters, should be [\"@:12345\",\"192.168.0.50:12345\"] !\n");
      return(TRUE);
     }
    strncpy((char *)Address,&STR_Params[i],j-i); Address[j-i]=0;
    if (sscanf((char *)Address,"%d.%d.%d.%d",&a,&b,&c,&d)!=4)
     {
      print("--> Invalid ip address in stream params, should be [\"192.168.0.100\"] !\n");
      return(TRUE);
     }
    i=j+1;
   }
  else
   {
    i=i+2;
   }
  /* Look for port */
  if (sscanf(&STR_Params[i],"%d",&Port)!=1)
   {
    print("--> Invalid port address in stream params, should be a decimal value !\n");
    return(TRUE);
   }
 }

 /* Open the stream */
 /* --------------- */
 ErrCode=TCPIP_OpenStream(ID,(U8 *)STR_Name,(U8 *)STR_Params,(U8 *)STR_Mode,&STR_Handle);
 if (ErrCode!=ST_NO_ERROR)
  {
   print("--> Unable to open this stream !\n");
   return(TRUE);
  }

 /* Copy the stream in the list */
 /* --------------------------- */
 for (i=0;i<TCPIP_MAX_STREAMS;i++)
  {
   if (TT_TCPIPi_Stream[i].Name[0]==0)
    {
     TT_TCPIPi_Stream[i].NetId  = ID;
     TT_TCPIPi_Stream[i].Handle = STR_Handle;
     strcpy((char *)TT_TCPIPi_Stream[i].Name,STR_Name);
     strcpy((char *)TT_TCPIPi_Stream[i].Params,STR_Params);
     TT_TCPIPi_Stream[i].Mode=STR_Mode[0];
     break;
    }
  }
 print("--> Stream \"%s\" is opened !\n",STR_Name);

 /* Return no errors */
 /* ---------------- */
 return(FALSE);
}
#endif

/* ========================================================================
   Name:        TT_TCPIP_Status
   Description: Return statistics on TCPIP                
   ======================================================================== */

#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)&&defined(OSPLUS)
BOOL TT_TCPIP_Status(parse_t *pars_p,char *result)
{
 ST_ErrorCode_t     ErrCode=ST_NO_ERROR;
 TCPIP_Statistics_t TCPIP_Statistics;
 S32                ID,RESET;

 /* Get Ethernet Identifier */
 /* ----------------------- */
 if (cget_integer(pars_p,0,&ID)==TRUE)
  {
   tag_current_line(pars_p,"Invalid ethernet ID, should be [0,1,..]");
   return(TRUE);
  }
 if (ID>=TCPIP_MAX_NUMBER)
  {
   print("--> Invalid ethernet ID, should be [0,1,..] !\n");
   return(TRUE);
  }

 /* Get Reset flag */
 /* -------------- */
 if (cget_integer(pars_p,0,&RESET)==TRUE)
  {
   tag_current_line(pars_p,"Invalid RESET flag, should be force 1 to reset the statistics !");
   return(TRUE);
  }

 /* Get statistics */
 /* -------------- */
 memset(&TCPIP_Statistics,0,sizeof(TCPIP_Statistics_t));
 ErrCode=TCPIP_GetStatistics(ID,&TCPIP_Statistics);
 if (ErrCode!=ST_NO_ERROR)
  {
   print("--> Unable to get informations from tcpip !\n");
   return(TRUE);
  }
                    
 /* Print the statistics */
 /* -------------------- */
 print("TCPIP(%d) Statistics\n",ID);
 print("-------------------\n");
 print("-- Link status --\n");
 print("Link status                        = %s\n",((TCPIP_Statistics.Link_enabled  ==   1) ? "Up":"Down"));
 print("Link duplex                        = %s\n",((TCPIP_Statistics.Link_duplex   ==   1) ? "Full duplex":"Half duplex"));
 print("Link speed                         = %s\n",((TCPIP_Statistics.Link_speed    == 100) ? "100MBits/s":"10MBits/s"));
 print("Link loopback                      = %s\n",((TCPIP_Statistics.Link_loopback ==   1) ? "Enabled":"Disabled"));
 print("-- Fatal receive errors --\n");
 print("Nb of receive error packets        = %u\n",TCPIP_Statistics.Receive_packet_error);
 print("Nb of receive without buffers      = %u\n",TCPIP_Statistics.Receive_no_buffers);
 print("Nb of receive crc errors           = %u\n",TCPIP_Statistics.Receive_crc_error);
 print("Nb of receive alignment errors     = %u\n",TCPIP_Statistics.Receive_alignment_error);
 print("Nb of receive overrun errors       = %u\n",TCPIP_Statistics.Receive_overrun_error);
 print("Nb of receive mii errors           = %u\n",TCPIP_Statistics.Receive_mii_error);
 print("Nb of receive descriptor errors    = %u\n",TCPIP_Statistics.Receive_descriptor_error);
 print("Nb of receive runt errors          = %u\n",TCPIP_Statistics.Receive_runt_error);
 print("Nb of receive too long errors      = %u\n",TCPIP_Statistics.Receive_toolong_error);
 print("Nb of receive late collision       = %u\n",TCPIP_Statistics.Receive_late_collision);
 print("Nb of receive expired watchdog     = %u\n",TCPIP_Statistics.Receive_watchdog_expired);
 print("-- Fatal transmit errors --\n");
 print("Nb of transmit error packets       = %u\n",TCPIP_Statistics.Transmit_packet_error);
 print("Nb of transmit underrun error      = %u\n",TCPIP_Statistics.Transmit_underrun_error);
 print("Nb of transmit nocarrier error     = %u\n",TCPIP_Statistics.Transmit_nocarrier_error);
 print("Nb of transmit jabber error        = %u\n",TCPIP_Statistics.Transmit_jabber_error);
 print("Nb of transmit one collision       = %u\n",TCPIP_Statistics.Transmit_one_collision);
 print("Nb of transmit more collisions     = %u\n",TCPIP_Statistics.Transmit_more_collision);
 print("Nb of transmit max collisions      = %u\n",TCPIP_Statistics.Transmit_max_collision);
 print("Nb of transmit late collisions     = %u\n",TCPIP_Statistics.Transmit_late_collision);
 print("-- Miscellaneous receive --\n");
 print("Nb of successful receive packets   = %u\n",TCPIP_Statistics.Receive_packet_ok);
 print("Nb of bytes received               = %u\n",TCPIP_Statistics.Receive_bytes_ok);
 print("Nb of direct receive bytes         = %u\n",TCPIP_Statistics.Receive_direct_bytes);
 print("Nb of direct receive frames        = %u\n",TCPIP_Statistics.Receive_direct_frames);
 print("Nb of multicast receive bytes      = %u\n",TCPIP_Statistics.Receive_multicast_bytes);
 print("Nb of multicast receive frames     = %u\n",TCPIP_Statistics.Receive_multicast_frames);
 print("Nb of broadcast receive bytes      = %u\n",TCPIP_Statistics.Receive_broadcast_bytes);
 print("Nb of broadcast receive frames     = %u\n",TCPIP_Statistics.Receive_broadcast_frames);
 print("-- Miscellaneous transmit --\n");
 print("Nb of successful transmit packets  = %u\n",TCPIP_Statistics.Transmit_packet_ok);
 print("Nb of bytes transmitted            = %u\n",TCPIP_Statistics.Transmit_bytes_ok);
 print("Nb of direct transmit bytes        = %u\n",TCPIP_Statistics.Transmit_direct_bytes);
 print("Nb of direct transmit frames       = %u\n",TCPIP_Statistics.Transmit_direct_frames);
 print("Nb of multicast transmit bytes     = %u\n",TCPIP_Statistics.Transmit_multicast_bytes);
 print("Nb of multicast transmit frames    = %u\n",TCPIP_Statistics.Transmit_multicast_frames);
 print("Nb of broadcast transmit bytes     = %u\n",TCPIP_Statistics.Transmit_broadcast_bytes);
 print("Nb of broadcast transmit frames    = %u\n",TCPIP_Statistics.Transmit_broadcast_frames);
 print("Nb of length transmit queue        = %u\n",TCPIP_Statistics.Transmit_length_queue);

 /* Check if reset statistic needed */
 /* ------------------------------- */
 if (RESET==1)
  {
   ErrCode=TCPIP_ResetStatistics(ID,&TCPIP_Statistics);
   if (ErrCode!=ST_NO_ERROR)
    {
     print("--> Unable to reset the statistics of the tcpip !\n");
     return(TRUE);
    }
  }

 /* Return no errors */
 /* ---------------- */
 return(FALSE);
}
#endif

/* ========================================================================
   Name:        TT_TCPIP_FtpStart
   Description: Start ftp server
   ======================================================================== */

#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)&&defined(TCPIP_STACK_NEXGEN)
BOOL TT_TCPIP_FtpStart(parse_t *pars_p,char *result)
{
 S32 ID;
 ST_ErrorCode_t ErrCode=ST_NO_ERROR;
 
 /* Get Ethernet Identifier */
 /* ----------------------- */
 if (cget_integer(pars_p,0,&ID)==TRUE)
  {
   tag_current_line(pars_p,"Invalid ethernet ID, should be [0,1,..]");
   return(TRUE);
  }
 if (ID>=TCPIP_MAX_NUMBER)
  {
   print("--> Invalid ethernet ID, should be [0,1,..] !\n");
   return(TRUE);
  }

 /* Start FTP server */
 /* ---------------- */
 ErrCode=FTPS_Start(ID);
 if (ErrCode!=ST_NO_ERROR)
  {
   print("--> Unable to start the ftp server !\n");
   return(TRUE);
  }
  
 /* Return no errors */
 /* ---------------- */
 print("--> Ftp server is started !\n");
 return(FALSE);
}
#endif

/* ========================================================================
   Name:        TT_TCPIP_FtpStop
   Description: Stop ftp server
   ======================================================================== */

#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)&&defined(TCPIP_STACK_NEXGEN)
BOOL TT_TCPIP_FtpStop(parse_t *pars_p,char *result)
{
 S32 ID;
 ST_ErrorCode_t ErrCode=ST_NO_ERROR;
 
 /* Get Ethernet Identifier */
 /* ----------------------- */
 if (cget_integer(pars_p,0,&ID)==TRUE)
  {
   tag_current_line(pars_p,"Invalid ethernet ID, should be [0,1,..]");
   return(TRUE);
  }
 if (ID>=TCPIP_MAX_NUMBER)
  {
   print("--> Invalid ethernet ID, should be [0,1,..] !\n");
   return(TRUE);
  }

 /* Stop FTP server */
 /* --------------- */
 print("--> Stop will return only when all clients will be disconnected from the server !\n");
 ErrCode=FTPS_Stop(ID);
 if (ErrCode!=ST_NO_ERROR)
  {
   print("--> Unable to stop the ftp server !\n");
   return(TRUE);
  }
  
 /* Return no errors */
 /* ---------------- */
 print("--> Ftp server is stopped !\n");
 return(FALSE);
}
#endif

/* ========================================================================
   Name:        TT_TCPIPi_PingCallback
   Description: Ping callback function
   ======================================================================== */

#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)&&defined(TCPIP_STACK_NEXGEN)
static int TT_TCPIPi_PingCallback(int seq,int err,int datasize,int ttl,int time,NGsockaddr *saddr,void *data)
{
 char ipaddr[40];
               
 /* Display result of the ping */
 /* -------------------------- */
 memset(ipaddr,0,sizeof(ipaddr));
 if ((err==NG_EOK)&&(saddr!=NULL))
  {
   ngInetNTOA(saddr->sin_addr,ipaddr,40);
   print("%d bytes from %s: icmp_seq=%d ttl=%d time=%d ms\n",datasize,ipaddr,seq,ttl,time);
  }
 else
  {
   print("Host not responding\n");
  }

 /* Return no errors */
 /* ---------------- */
 return(NG_EOK);
}
#endif





⌨️ 快捷键说明

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