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

📄 networktest.c

📁 这是DSP的程序
💻 C
字号:
#define CFG_HOSTNAME_MAX 30
#define CFG_DOMAIN_MAX 30

int NetworkTest() 
{
char *LocalIPAddr = "128.247.117.12"; 
char *LocalIPMask = "255.255.254.0"; 
char *GatewayIP = "128.247.116.1"; 
char *HostName = "testhost";
char *DomainName = "demo.net";

/*--------------------**------------------*/
char *NetworkIPAddr="128.247.117.12";

 int rc; 
 CI_IPNET NA; 
 CI_ROUTE RT;
 HANDLE hCfg;

// THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!!

rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
if( rc )
{
printf("NC_SystemOpen Failed (%d)\n",rc);
for(;;);
}

// Create and build the system configuration from scratch. 

// Create a new configuration 
 hCfg = CfgNew(); 
 if( !hCfg ) 
 { 
   printf("Unable to create configuration\n"); 
   goto main_exit; 
 }

/*----Load the configuration (and then we can free the buffer)---*/ 
/*  CfgLoad( hCfg, size, pBuf ); 
  mmFree( pBuf ); */    //load a configuration by using this function here.

// We1.better validate the length of the supplied names 
 if( strlen( DomainName ) >= CFG_DOMAIN_MAX ||
  strlen( HostName ) >= CFG_HOSTNAME_MAX ) 
  { 
    printf("Names too long\n"); 
    goto main_exit; 
  }


// Manually configure our local IP address
  bzero( &NA, sizeof(NA) ); 
  NA.IPAddr = inet_addr(LocalIPAddr);
  NA.IPMask = inet_addr(LocalIPMask); 
  strcpy( NA.Domain, DomainName );
  NA.NetType = 0;
 
// Add the address to interface 1 
  CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NA, 0 );

// Add our hostname 
  CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0, strlen(HostName), (UINT8 *)HostName, 0 );
// Add the default gateway. Since it is the default, the 
// destination address and mask are both zero (we go ahead 
// and show the assignment for clarity). 

  bzero( &RT, sizeof(RT) ); 
  RT.IPDestAddr = 0; 
  RT.IPDestMask = 0; 
  RT.IPGateAddr = inet_addr(GatewayIP);

// Add the route 
  CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (UINT8 *)&RT, 0 );

// Boot the system using this configuration 

// We keep booting until the function returns less than 1. This allows 
// us to have a "reboot" command. 

  do { 
        rc = NC_NetStart( hCfg, NetworkStart, NetworkStop, NetworkIPAddr ); 
     } while( rc > 0 );

// Delete Configuration 
   CfgFree( hCfg );

// Close the OS 
main_exit: 
    NC_SystemClose(); 
    return(0); 
}

⌨️ 快捷键说明

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