usrNetConfigIf.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:4k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* usrNetConfigIf.c - Configure the network interface */
  2. /* Copyright 1992 - 2000 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01d,19apr01,jmp  fixed SIMNT route setting (SPR# 64900).
  7. 01c,06dec00,spm  renamed file to fix project tool build (alphabetical order
  8.                  requires it to follow usrNetBoot.c for linker dependencies)
  9. 01b,16nov00,spm  enabled new DHCP lease for runtime device setup (SPR #20438)
  10. 01a,18aug98,ann  created from usrNetwork.c
  11. */
  12. /* 
  13. DESCRIPTION
  14. This file is included by the configuration tool to setup a network device
  15. according to the parameters in the boot line. It contains the initialization
  16. routine for the INCLUDE_NETDEV_CONFIG component.
  17. */ 
  18. /******************************************************************************
  19. *
  20. * usrNetIfConfig - configure network interface
  21. *
  22. * This routine configures the specified network interface with the specified
  23. * boot parameters:
  24. *
  25. * - subnetmask is extracted from inetAdrs and, if present,
  26. *   set for interface
  27. * - inet address is set for interface
  28. * - if present, inet name for interface is added to host table.
  29. *
  30. * RETURNS: OK or ERROR
  31. *
  32. * NOMANUAL
  33. */
  34. STATUS usrNetIfConfig 
  35.     (
  36.     char *      devName,  /* device name */
  37.     int         unitNum,  /* unit number */
  38.     char *      inetAdrs,  /* inet address */
  39.     char *      inetName,  /* host name */
  40.     int         netmask  /* subnet mask */
  41.     )
  42.     {
  43.     char ifname [20];
  44. #ifdef  INCLUDE_PCMCIA
  45.     if (strncmp (devName, "pcmcia", 6) == 0)
  46. devName = "pcmcia";
  47. #endif  /* INCLUDE_PCMCIA */
  48.     /* check for empty inet address */
  49.     if (inetAdrs[0] == EOS)
  50. {
  51. printf ("No inet address specified for interface %s.n", devName);
  52. return (ERROR);
  53. }
  54.     /* build interface name */
  55.     sprintf (ifname, "%s%d", devName, unitNum);
  56.     /* set subnet mask, if any specified */
  57.     if (netmask != 0)
  58. ifMaskSet (ifname, netmask);
  59.     /* set inet address */
  60.     if (ifAddrSet (ifname, inetAdrs) != OK)
  61. {
  62. printf ("Error setting inet address of %s to %s, errno = %#xn",
  63. ifname, inetAdrs, errno);
  64. return (ERROR);
  65. }
  66.     /* add host name to host table */
  67.     if ((inetName != NULL) && (*inetName != EOS))
  68. hostAdd (inetName, inetAdrs);
  69. #if CPU==SIMNT
  70.     routeAdd("0.0.0.0", sysBootParams.ead);
  71. #endif  /* CPU==SIMNT */
  72.     return (OK);
  73.     }
  74. /*******************************************************************************
  75. *
  76. * usrNetConfig - configure the network boot device
  77. *
  78. * This routine is the initialization routine for the INCLUDE_NETDEV_CONFIG
  79. * component. It assigns the IP address and netmask from the boot parameters
  80. * to the network boot device. Those values might be added manually or
  81. * obtained as a result of automatic configuration with DHCP. The netAttachFlag
  82. * variable is FALSE for devices such as PPP or SLIP which are attached and
  83. * configured already, and also do not support automatic configuration.
  84. *
  85. * RETURNS: N/A
  86. *
  87. * NOMANUAL
  88. */
  89. void usrNetConfig
  90.     (
  91.     char *  pDevName,  /* device name */
  92.     int  unitNum,  /* unit number */
  93.     char *  pDevHostName,  /* device host name */
  94.     char *  pAddrString  /* device address */
  95.     )
  96.     {
  97.     /*
  98.      * Do nothing if another device is already configured or an
  99.      * error was detected in the boot parameters.
  100.      */
  101.     if (netDevBootFlag)
  102.         return;
  103.     /* Configure the network device using the address/mask information. */
  104.     if (netAttachFlag)     /* Device attached but not configured yet? */
  105.         {
  106.         if (usrNetIfConfig (pDevName, unitNum, pAddrString, pDevHostName,
  107.                             netmask) != OK)
  108.             netDevBootFlag = TRUE;
  109.         }
  110.     return;
  111.     }