[VxW] How to dynamically assign IP address on bootup?

Tony D. nospam at nospam.com
Thu Feb 12 00:17:26 PST 2004


You don't have to change the bootrom code because you can change the enet
address at runtime. Checkout this code sample:

void change_enet_iface_cfg(UINT32 New_Enet_IP_Address,
                           UINT32 New_Netmask,
                           UINT32 New_Gateway_IP_Address)
{

 INT8 IPAddrString[INET_ADDR_LEN];/*temp var to hold ASCII rep. of IP
address*/
 struct in_addr InetAddress; /*required by calls to API*/
 STATUS RetVal;

 /*cleanout the existing IP routing table entry(s) for the "old" (no longer
applicable) IP address
      that VxWorks assigned to the enet device at boot time. This one-liner
is simpler
      than "getting" the current IP address and netmask for the interface
and then deleting
      the routes associated with the address. */
 RetVal = ifRouteDelete(ENET_DEV_NAME,ENET_UNIT_NUM);

 /* According to VxWorks docs, we must change the netmask before setting the
address
       because the subsequent iAddrSet call uses the netmask to add a route
to the IP
       routing table. If the netmask isn't changed before changing the IP
address, then
       the "old" netmask would be used and it could screw things up !*/
    RetVal = ifMaskSet(ENET_DEV_UNIT_NAME,New_Netmask);

 /*need to convert the address to a dotted string before calling ifAddrSet()
      to set the interface's IP address. */
 InetAddress.s_addr  = New_Enet_IP_Address;
 inet_ntoa_b(InetAddress,IPAddrString);

 /* change the network interface IP address*/
 RetVal = ifAddrSet(ENET_DEV_UNIT_NAME,IPAddrString);

 /*Finally,add the default gateway IP address to the IP routing table*/
 /*First need to convert the address to a dotted string before calling
ifAddrSet()
      to set the interface's IP address. */
 InetAddress.s_addr  = New_Gateway_IP_Address;
 inet_ntoa_b(InetAddress,IPAddrString);

 /*Add the default gateway address to the table*/
 /* A gateway assigned to the destination network address of 0.0.0.0 is (by
convention)
       the default gateway*/
 RetVal = mRouteAdd("0.0.0.0",IPAddrString,0,0,0); /*from P78 of VxWorks
Net. Prog. guide*/
}


"Lourenco Paul" <Paul.Lourenco at au.thalesgroup.com> wrote in message
news:mailman.102.1076540843.1488.vxwexplo at csg.lbl.gov...
> Hi,
>
> I'm using the mv5100 vxworks BSP. I would like to read a value from global
VME space on bootup, and set the IP address according to what this value is.
How can this be done? Does it mean somehow changing the bootrom code?
>
> kind regards
> Paul L




More information about the VxWexplo mailing list