EmbeddedRelated.com
Forums

Changing IP Address at runtime?

Started by reotrb March 15, 2005

Hello all,
I'm using the WiFi application kit, and I'm trying to figure out how
I can change the IP Address at runtime. I have tried using the
ifconfig function, but it just doesnt seem to work. The thing that
confuses me is the first parameter of this function, IFETH0. This
specifies the ethernet interface, but I'm not using ethernet - I'm
using the WiFi adapter. My code works perfectly fine if I state the
IP Address using #define MY_IP_ADDRESS 192.168.0.2 at the top of the
code, but not if I define it at runtime. Can anyone help me out? A
portion of my code appears below.

Thanks,
Rob

#define TCPCONFIG 0

#define WIFI_INIT \
wifi_ioctl(NULL,WIFI_MODE,"BSS",0); \
wifi_ioctl(NULL,WIFI_SSID,"default",0);

#define DISABLE_ETHERNET_AUTOCONF
#define PKTDRV "cfprism.lib"

#define LOCAL_PORT 5551

//The dcrtcp library supports IP and TCP.
#use "dcrtcp.lib" int check_for_received_data(void);
void service_request(void);
void establish_connection(void);
int connection_established(void);

tcp_Socket sock;

main() { ifconfig(IF_ETH0, IFS_DOWN, IFS_IPADDR, aton("192.168.0.2"),
IFS_NETMASK, aton("255.255.255.0"),
IFS_ROUTER_SET, aton("192.168.0.2"),
IFS_UP,
IFS_END);


I posted a reply a couple of days ago that was in relation to modbus(under user name jester_fu_ah). If
you have a look in it, you will see reference to the ETH 'macro' and a breif example of how to configure
them at run time for an ethernet client. I think the original thread related to using different port numbers.
It's no good using ifconfig, as you have found the same thing i did, it just doesn't work. However, if you
use the #define macros for it in your code, you can actually pass strings of the IP addr. and subnet mask
in allowing runtime configuration.

I had a look at the rabbit source code, and could not see a reason why this happened... but i got it working! Quoting reotrb <robkoch@robk...>:

>
> Hello all,
>
> I'm using the WiFi application kit, and I'm trying to figure out how
>
> I can change the IP Address at runtime. I have tried using the
>
> ifconfig function, but it just doesnt seem to work. The thing that
>
> confuses me is the first parameter of this function, IFETH0. This
>
> specifies the ethernet interface, but I'm not using ethernet - I'm
>
> using the WiFi adapter. My code works perfectly fine if I state the
>
> IP Address using #define MY_IP_ADDRESS 192.168.0.2 at the top of the
>
> code, but not if I define it at runtime. Can anyone help me out? A
>
> portion of my code appears below. >
> Thanks,
>
> Rob >
> #define TCPCONFIG 0 >
> #define WIFI_INIT \
>
> wifi_ioctl(NULL,WIFI_MODE,"BSS",0); \
>
> wifi_ioctl(NULL,WIFI_SSID,"default",0); >
> #define DISABLE_ETHERNET_AUTOCONF
>
> #define PKTDRV "cfprism.lib" >
> #define LOCAL_PORT 5551 >
> //The dcrtcp library supports IP and TCP.
>
> #use "dcrtcp.lib" > int check_for_received_data(void);
>
> void service_request(void);
>
> void establish_connection(void);
>
> int connection_established(void); >
> tcp_Socket sock; >
> main() { > ifconfig(IF_ETH0, IFS_DOWN, IFS_IPADDR, aton("192.168.0.2"),
>
> IFS_NETMASK, aton("255.255.255.0"),
>
> IFS_ROUTER_SET, aton("192.168.0.2"),
>
> IFS_UP,
>
> IFS_END); >
>
> Yahoo! Groups Links > To >
>



At 06:09 PM 3/15/2005, you wrote:
>Hello all,
>I'm using the WiFi application kit, and I'm trying to figure out how
>I can change the IP Address at runtime. I have tried using the
>ifconfig function, but it just doesnt seem to work. The thing that
>confuses me is the first parameter of this function, IFETH0. This
>specifies the ethernet interface, but I'm not using ethernet - I'm
>using the WiFi adapter. My code works perfectly fine if I state the
>IP Address using #define MY_IP_ADDRESS 192.168.0.2 at the top of the
>code, but not if I define it at runtime. Can anyone help me out? A
>portion of my code appears below.
>
> ifconfig(IF_ETH0, IFS_DOWN, IFS_IPADDR, aton("192.168.0.2"),
> IFS_NETMASK, aton("255.255.255.0"),
> IFS_ROUTER_SET, aton("192.168.0.2"),
> IFS_UP,
> IFS_END);

Try using IF_WIFI0 instead of IF_ETH0

This depends on the version. The original wifi kit replaced ETH0 with the
wifi libs. 9.21 looks like it has it as interface #2.

<Scott --
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.7.2 - Release Date: 3/11/2005




-----Original Message-----
From: Scott Henion [mailto:shenion@shen...]
Sent: Wednesday, March 16, 2005 12:59 AM
To: rabbit-semi@rabb...
Subject: Re: [rabbit-semi] Changing IP Address at runtime?
At 06:09 PM 3/15/2005, you wrote:
>Hello all,
>I'm using the WiFi application kit, and I'm trying to figure out how
>I can change the IP Address at runtime. I have tried using the
>ifconfig function, but it just doesnt seem to work. The thing that
>confuses me is the first parameter of this function, IFETH0. This
>specifies the ethernet interface, but I'm not using ethernet - I'm
>using the WiFi adapter. My code works perfectly fine if I state the
>IP Address using #define MY_IP_ADDRESS 192.168.0.2 at the top of the
>code, but not if I define it at runtime. Can anyone help me out? A
>portion of my code appears below.
>
> ifconfig(IF_ETH0, IFS_DOWN, IFS_IPADDR, aton("192.168.0.2"),
> IFS_NETMASK, aton("255.255.255.0"),
> IFS_ROUTER_SET, aton("192.168.0.2"),
> IFS_UP,
> IFS_END);

Try using IF_WIFI0 instead of IF_ETH0

This depends on the version. The original wifi kit replaced ETH0 with
the
wifi libs. 9.21 looks like it has it as interface #2.

<Scott ------

Here are snippets from my code which shows what I did to check and see
if ifconfig is working at all:

char szIP_Address[16];
longword IP_Addr;

#define IPDEFAULT "192.168.0.220"
#define MASKDEFAULT "255.255.255.0"

//Don't remember why I put this here.
//But I think I need to define ETH0
//Someday I'll pull it out and see if everything still works
//####### note that ETH0 is a ZERO at the end not an "OH". Messed me up
for hours!!!!!!#define IFCONFIG_ETH0 \
IFS_IPADDR, aton(IPDEFAULT), \
IFS_NETMASK, aton(MASKDEFAULT), \
IFS_UP

ifconfig(IF_ETH0, IFS_IPADDR, aton(IPDEFAULT), IFS_END); //set the
default address

ifconfig(IF_ETH0, IFG_IPADDR, &IP_Addr, IFS_END); //get the current
address and put it in IP_Addr
inet_ntoa(szIP_Address,IP_Addr); //convert address to "xxx.xxx.xxx.xxx"
form for display

printf("IP Address: %s\n",szIP_Address);

//##### To make it take effect you have to do this:
ifconfig(IF_ETH0, IFS_UP, IFS_END);

-Pete