EmbeddedRelated.com
Forums
Memfault Beyond the Launch

DHCP <-> STATIC IP

Started by aintnoprobs May 6, 2005
HI all,

I use DC 9.1 on a RCM3200.

I've been experimenting the runtime ip address change from DHCP to
Static & vice-versa on a simple program.

After toggling the choice 4 times the program crashes giving the
following error on a message box.

"Run Time Error: XMEM allocation failed .. ( out of memory)
Address fd: e855"

Occasionally this address changes slighlty.

Any clues as to why this would happen?

Regards
Nil


At 01:39 AM 5/6/2005, you wrote:

>After toggling the choice 4 times the program crashes giving the
>following error on a message box.
>
>"Run Time Error: XMEM allocation failed .. ( out of memory)
>Address fd: e855"
>
>Occasionally this address changes slighlty.
>
>Any clues as to why this would happen?

Are you calling sock_init() more than once? ------
| Scott G. Henion| shenion@shen... |
| Consultant | Stone Mountain, GA |
| SHDesigns | PGP Key 0xE98DDC48 |
| http://www.shdesigns.org/rabbit/ |
------ --
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.5 - Release Date: 5/4/2005


Sorry for the late reply as I was out of office.

I figured out calling http_init(); each time after a runtimeIPchange
() is not healthy. I initially did this because the web pages
disappeared after a runtime IP change.

Just call only tcp_reserveport(80); only after a Runtime IP change
and everything works ok.

Thanks Scott for the suggestion.

Regards
Nil

--- In rabbit-semi@rabb..., Scott Henion <shenion@s...> wrote:
> At 01:39 AM 5/6/2005, you wrote:
>
> >After toggling the choice 4 times the program crashes giving the
> >following error on a message box.
> >
> >"Run Time Error: XMEM allocation failed .. ( out of memory)
> >Address fd: e855"
> >
> >Occasionally this address changes slighlty.
> >
> >Any clues as to why this would happen?
>
> Are you calling sock_init() more than once? > ------
> | Scott G. Henion| shenion@s... |
> | Consultant | Stone Mountain, GA |
> | SHDesigns | PGP Key 0xE98DDC48 |
> | http://www.shdesigns.org/rabbit/ |
> ------ > --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.11.5 - Release Date: 5/4/2005


Nil,
 
Perhaps you could elaborate a bit on how you are able to switch back and forth between DHCP and Static IP. I've never been able to do that successfully without rebooting each time.
 
Steve


aintnoprobs <n...@hotmail.com> wrote:
Sorry for the late reply as I was out of office.

I figured out calling http_init(); each time after a runtimeIPchange
() is not healthy. I initially did this because the web pages
disappeared after a runtime IP change.

Just call only tcp_reserveport(80); only after a Runtime IP change
and everything works ok.

Thanks Scott for the suggestion.

Regards
Nil

--- In r...@yahoogroups.com, Scott Henion <shenion@s...> wrote:
> At 01:39 AM 5/6/2005, you wrote:
>
> >After toggling the choice 4 times the program crashes giving the
> >following error on a message box.
> >
> >"Run Time Error: XMEM allocation failed .. ( out of memory)
> >Address fd: e855"
> >
> >Occasionally this address changes slighlty.
> >
> >Any clues as to why this would happen?
>
> Are you calling sock_init() more than once?> ------
> | Scott G. Henion| shenion@s... |
> |   Consultant   |   Stone Mountain, GA  |
> |   SHDesigns    |   PGP Key 0xE98DDC48  |
> |     http://www.shdesigns.org/rabbit/   |
> ------> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.11.5 - Release Date: 5/4/2005


Hi Steve,

DHCP<->Static and vice-versa works well at runtime with no rebooting.

I define TCPCONFIG as 6
At bootup I call two functions.
1.loadNetwork(char *ip,char *sub, char *gw, int dhcp)
2.runtimeIPChange(char *ip,char *sub, char *gw, int dhcp)

void loadNetwork(char* ip, char* sub, char* gw, int dhcp){
/*Need the following if statement due to a bug*/
if(!dhcp){
ifconfig(IF_ETH0, IFS_IPADDR, aton(ip),IFS_NETMASK, aton(sub),
IFS_ROUTER_SET, aton(gw),IFS_DOWN,IFS_END);
sock_init();
ifup(IF_ETH0);
}
runtimeIPChange(ip, sub, gw, dhcp);
http_init();
tcp_reserveport(80);
}

void initInterface(char* ip, char* sub, char* gw, int dhcp){
auto DHCPInfo * di;
if(dhcp){
ifdown(IF_ETH0);
ifconfig(IF_ETH0, IFG_DHCP_INFO, &di, IFS_END); // Get whether
interface is qualified for DHCP
printf("Interface IF_ETH0 is %squalified for DHCP.\n",
di ? "" : "NOT ");
ifconfig(IF_ETH0,IFS_DHCP, di != NULL, // Use DHCP if interface
is qualified for it
IFS_DHCP_TIMEOUT, 15, // Specify timeout in seconds
IFS_DHCP_FALLBACK, 1, // Allow use of fallbacks to static
configuration
IFS_END);
if (di){// Specify fallbacks for DHCP...
ifconfig(IF_ETH0,IFS_IPADDR, aton(DROPIP),
IFS_NETMASK,aton(DROPMASK),
IFS_ROUTER_SET, aton(DROPGW),
IFS_END);}
sock_init();
ifup(IF_ETH0);

}
else{ // STATIC IP
printf("Forced to use static IP");
ifconfig(IF_ETH0, IFS_DHCP, 0, IFS_END);
ifconfig(IF_ETH0, IFS_IPADDR, aton(ip),
IFS_NETMASK, aton(sub),
IFS_ROUTER_SET, aton(gw),
IFS_UP,
IFS_END);

}
tcp_reserveport(80);

}

DROPXX values are fallback if DHCP server is not present. Now, during a Runtime IP change, Call only the initInterface(char*
ip, char* sub, char* gw, int dhcp) Method.
I tested this by having key presses, 0-9 and by going true a case
statement, and printing the ip_print_ifs();
Seems to switch fine with no problems.

Regards
Nil --- In rabbit-semi@rabb..., Steve Trigero <seecwriter@y...>
wrote:
> Nil,
>
> Perhaps you could elaborate a bit on how you are able to switch
back and forth between DHCP and Static IP. I've never been able to do
that successfully without rebooting each time.
>
> Steve
>


Nil,

According to "the manual", http_init() MUST be called
after sock_init(). But in your code, I don't see
sock_init() being called at all on boot up.
Is runtimeIPChange your procedure, as apposed to a DC
lib function? Maybe that's where sock_init() is being
called?
It also looks to me like sock_init() will get called
more than once when you switch between Static IP and
DHCP. I thought sock_init() could only be called one
time, otherwise horrible things happen to your
program.

Steve

--- aintnoprobs <nilkamal@nilk...> wrote:
> Hi Steve,
>
> DHCP<->Static and vice-versa works well at runtime
> with no rebooting.
>
> I define TCPCONFIG as 6
> At bootup I call two functions.
> 1.loadNetwork(char *ip,char *sub, char *gw, int
> dhcp)
> 2.runtimeIPChange(char *ip,char *sub, char *gw, int
> dhcp)
>
> void loadNetwork(char* ip, char* sub, char* gw, int
> dhcp){
> /*Need the following if statement due to a bug*/
> if(!dhcp){
> ifconfig(IF_ETH0, IFS_IPADDR,
> aton(ip),IFS_NETMASK, aton(sub),
> IFS_ROUTER_SET, aton(gw),IFS_DOWN,IFS_END);
> sock_init();
> ifup(IF_ETH0);
> }
> runtimeIPChange(ip, sub, gw, dhcp);
> http_init();
> tcp_reserveport(80);
> }
>
> void initInterface(char* ip, char* sub, char* gw,
> int dhcp){
> auto DHCPInfo * di;
> if(dhcp){
> ifdown(IF_ETH0);
> ifconfig(IF_ETH0, IFG_DHCP_INFO, &di, IFS_END);
> // Get whether
> interface is qualified for DHCP
> printf("Interface IF_ETH0 is %squalified for
> DHCP.\n",
> di ? "" : "NOT ");
> ifconfig(IF_ETH0,IFS_DHCP, di != NULL, // Use
> DHCP if interface
> is qualified for it
> IFS_DHCP_TIMEOUT, 15, // Specify timeout in
> seconds
> IFS_DHCP_FALLBACK, 1, // Allow use of
> fallbacks to static
> configuration
> IFS_END);
> if (di){// Specify fallbacks for DHCP...
> ifconfig(IF_ETH0,IFS_IPADDR, aton(DROPIP),
> IFS_NETMASK,aton(DROPMASK),
> IFS_ROUTER_SET, aton(DROPGW),
> IFS_END);}
> sock_init();
> ifup(IF_ETH0);
>
> }
> else{ // STATIC IP
> printf("Forced to use static IP");
> ifconfig(IF_ETH0, IFS_DHCP, 0, IFS_END);
> ifconfig(IF_ETH0, IFS_IPADDR, aton(ip),
> IFS_NETMASK, aton(sub),
> IFS_ROUTER_SET, aton(gw),
> IFS_UP,
> IFS_END);
>
> }
> tcp_reserveport(80);
>
> }
>
> DROPXX values are fallback if DHCP server is not
> present. > Now, during a Runtime IP change, Call only the
> initInterface(char*
> ip, char* sub, char* gw, int dhcp) Method.
> I tested this by having key presses, 0-9 and by
> going true a case
> statement, and printing the ip_print_ifs();
> Seems to switch fine with no problems.
>
> Regards
> Nil > --- In rabbit-semi@rabb..., Steve Trigero
> <seecwriter@y...>
> wrote:
> > Nil,
> >
> > Perhaps you could elaborate a bit on how you are
> able to switch
> back and forth between DHCP and Static IP. I've
> never been able to do
> that successfully without rebooting each time.
> >
> > Steve
> >



Hi Steve,
Yes, http_init() should be called after sock_init()

If you look closely at the code you will see that sock_init() is
called before http_init()

BOOTUP====================
1. Static IP - > sock_init() is called at loadNetwork() before
runtimeIPChange() is called

2. DHCP IP -> loadNetwork simply calls runtimeIPChange() and sock_init
() is called there.

So no matter what type, sock_init() is called before http_init() is
called. AT RUNTIME==================
Only call the runtimeIPChange() function. Yes this is a method of my
own and not of ZWorld.
It does call the sock_init() each time activating a DHCP address but
I think because the interface is 'down' it does not make a difference.
(try to remove it and see if fails *grin*)

Going from a DHCP to a static, it does not call sock_init() at all.

Going either way, both calls tcp_reserveport(80) though.

After this code I've swapped between the two types manytimes
manually, but no crashes. So the 'horrible' things are undiscovered
yet. If you discover anything please let me know too. :)

Nil
--- In rabbit-semi@rabb..., Steve Trigero <seecwriter@y...>
wrote:
> Nil,
>
> According to "the manual", http_init() MUST be called
> after sock_init(). But in your code, I don't see
> sock_init() being called at all on boot up.
> Is runtimeIPChange your procedure, as apposed to a DC
> lib function? Maybe that's where sock_init() is being
> called?
> It also looks to me like sock_init() will get called
> more than once when you switch between Static IP and
> DHCP. I thought sock_init() could only be called one
> time, otherwise horrible things happen to your
> program.
>
> Steve



Memfault Beyond the Launch