public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] IP adress Get and Set (SIOCSIFADDR problem ? )
@ 2007-09-29 21:35 Xun Yuan
  2007-09-29 21:46 ` Alok Singh
  0 siblings, 1 reply; 5+ messages in thread
From: Xun Yuan @ 2007-09-29 21:35 UTC (permalink / raw)
  To: ecos-discuss

HI There,
 
Would someone please tell me why the second parameter
in GetIP and SetIP is SOCK_DGRAM in the below link? 
Does it matter in case of getting/setting IP addresses
of an interface?  If it does not, any value would do,
such as SOCK_RAW, SOCK_DSTREAM, right?
 
Thanks very much in advance
pam
 
 
http://www.cygwin.com/ml/ecos-discuss/2004-01/msg00130.html


      ____________________________________________________________________________________
Catch up on fall's hot new shows on Yahoo! TV. Watch previews, get listings, and more!
http://tv.yahoo.com/collections/3658 

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [ECOS] IP adress Get and Set (SIOCSIFADDR problem ? )
  2007-09-29 21:35 [ECOS] IP adress Get and Set (SIOCSIFADDR problem ? ) Xun Yuan
@ 2007-09-29 21:46 ` Alok Singh
  2007-10-01 23:55   ` Xun Yuan
  0 siblings, 1 reply; 5+ messages in thread
From: Alok Singh @ 2007-09-29 21:46 UTC (permalink / raw)
  To: Xun Yuan, ecos-discuss

Yuan,
I believe you are right.  I always use SOCK_RAW. 
Are you seeing any problem with SOCK_RAW? For some reasons, ecos
bootp/dhcp sever code uses SOCK_DGRAM while setting IP address.

-ALOK 

-----Original Message-----
From: ecos-discuss-owner@ecos.sourceware.org
[mailto:ecos-discuss-owner@ecos.sourceware.org] On Behalf Of Xun Yuan
Sent: Sunday, September 30, 2007 3:05 AM
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] IP adress Get and Set (SIOCSIFADDR problem ? )

HI There,
 
Would someone please tell me why the second parameter
in GetIP and SetIP is SOCK_DGRAM in the below link? 
Does it matter in case of getting/setting IP addresses
of an interface?  If it does not, any value would do,
such as SOCK_RAW, SOCK_DSTREAM, right?
 
Thanks very much in advance
pam
 
 
http://www.cygwin.com/ml/ecos-discuss/2004-01/msg00130.html


 
________________________________________________________________________
____________
Catch up on fall's hot new shows on Yahoo! TV. Watch previews, get
listings, and more!
http://tv.yahoo.com/collections/3658 

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss




--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [ECOS] IP adress Get and Set (SIOCSIFADDR problem ? )
  2007-09-29 21:46 ` Alok Singh
@ 2007-10-01 23:55   ` Xun Yuan
  0 siblings, 0 replies; 5+ messages in thread
From: Xun Yuan @ 2007-10-01 23:55 UTC (permalink / raw)
  To: Alok Singh, ecos-discuss

Hi Alok,

Thank you so much for the quick reply!

Both SOCK_RAW and SOCK_DGRAM work.  Maybe some other
options work as well.  I talked to people at work.  I
was told the difference with different options lies in
that when you get ip address, you will not be able to
as a non-super-user if it's set with SOCK_RAW, since
only super user has SOCK_RAW permission.

My other question is that: is there a way for the set
IP address to survive power cycle with
ioctl(SIOCSIFADDR)?

I know for sure if the host's original IP address is
dynamic.  When you power off the computer and power it
back on, the DHCP in config file
(etc/sysconfig/network-scripts/ifcfg-eth0) is still
there, the system starts to get IP address from DHCP
server.


Thanks very much in advance!
pam




--- Alok Singh <alok.singh@broadcom.com> wrote:

> Yuan,
> I believe you are right.  I always use SOCK_RAW. 
> Are you seeing any problem with SOCK_RAW? For some
> reasons, ecos
> bootp/dhcp sever code uses SOCK_DGRAM while setting
> IP address.
> 
> -ALOK 
> 
> -----Original Message-----
> From: ecos-discuss-owner@ecos.sourceware.org
> [mailto:ecos-discuss-owner@ecos.sourceware.org] On
> Behalf Of Xun Yuan
> Sent: Sunday, September 30, 2007 3:05 AM
> To: ecos-discuss@sources.redhat.com
> Subject: [ECOS] IP adress Get and Set (SIOCSIFADDR
> problem ? )
> 
> HI There,
>  
> Would someone please tell me why the second
> parameter
> in GetIP and SetIP is SOCK_DGRAM in the below link? 
> Does it matter in case of getting/setting IP
> addresses
> of an interface?  If it does not, any value would
> do,
> such as SOCK_RAW, SOCK_DSTREAM, right?
>  
> Thanks very much in advance
> pam
>  
>  
>
http://www.cygwin.com/ml/ecos-discuss/2004-01/msg00130.html
> 



      ____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ECOS] IP adress Get and Set (SIOCSIFADDR problem ? )
  2004-01-16 17:05 sebastien Couret
@ 2004-01-16 19:53 ` Andrew Lunn
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2004-01-16 19:53 UTC (permalink / raw)
  To: sebastien Couret; +Cc: ecos-discuss

> So ioctl calls always return a no error value, but IP adress stays the same 
> as shown by the result gaved by the Linux Synthetic Target :
> 
> <
> IP Adress of 'eth0' is '10.0.0.254' 
> IP address of 'eth0' set to '1.2.3.4' 
> IP Adress of 'eth0' is '10.0.0.254'

Im guessing here....but before you do a set, remove the old address.
What could be happening is you are assigning multiple addresses to the
same interface. Your get function is also only returning the first
address. If you were to ask it for more addresses i think you will
then find it also returns 1.2.3.4.

Try calling show_network_tables().

     Andrew

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ECOS] IP adress Get and Set (SIOCSIFADDR problem ? )
@ 2004-01-16 17:05 sebastien Couret
  2004-01-16 19:53 ` Andrew Lunn
  0 siblings, 1 reply; 5+ messages in thread
From: sebastien Couret @ 2004-01-16 17:05 UTC (permalink / raw)
  To: ecos-discuss

Hello,

I'm using FreeBSd stack over eCOS , last CVS revision.
It seems that IP adress cannot be changed while the application is running 
... 

I'm using ioctl to get and set IP adress of network interfaces as shown in 
the following code :

<
#include <network.h>
#include <arpa/inet.h> // for using inet_addr

//////////////////////////////////////////////
// Set IP adress of interface to value adress
//////////////////////////////////////////////
int SetIP(const char* interface,const char * adress)
{
 int test_sock=0;
 struct sockaddr_in* addr=NULL;
 struct ifreq ifr;

 memset( &ifr, 0, sizeof( struct ifreq ) );
 addr= (struct sockaddr_in *)&(ifr.ifr_addr);
 memset(addr, 0, sizeof( struct sockaddr_in) );
 addr->sin_len=sizeof(struct sockaddr_in);
 addr->sin_family=AF_INET;
 addr->sin_addr.s_addr=inet_addr(adress);

 test_sock = socket( PF_INET, SOCK_DGRAM, 0 );
 if( test_sock == -1 )
 {
  diag_printf("Cannot obtain socket :%s\n",strerror(errno));
  return (-1);
 }

 strncpy( ifr.ifr_name,interface,IFNAMSIZ);
 if( ioctl( test_sock, SIOCSIFADDR, &ifr ) != 0 )
 {
  diag_printf("Cannot set IP address of interface '%s' to 
'%s':%s\n",interface,adress,strerror(errno));
  close(test_sock);
  return (-1);
 }
 else diag_printf("IP address of '%s' set to '%s'\n",interface,adress);
 close(test_sock);
 return(0);
}

//////////////////////////////////////////////
// Display IP address of interface
//////////////////////////////////////////////
int GetIP(const char* interface)
{
 int test_sock=0;
 struct sockaddr_in *addrp=NULL;
 struct ifreq ifr;

 test_sock = socket( PF_INET, SOCK_DGRAM, 0 );
 if( test_sock == -1 )
 {
  diag_printf("Cannot obtain socket :%s\n",strerror(errno));
  return (-1);
 }

 memset(&ifr,0,sizeof( struct ifreq ) );
 strncpy(ifr.ifr_name,interface,IFNAMSIZ);

 if( ioctl( test_sock, SIOCGIFADDR, &ifr ) == -1 )
 {
  diag_printf("Cannot obtain IP address of '%s' 
:%s\n",interface,strerror(errno));
  close(test_sock);
  return (-1);
 }
 close(test_sock);

 addrp = (struct sockaddr_in *)&(ifr.ifr_addr);
 diag_printf("IP Adress of '%s' is 
'%s'\n",interface,inet_ntoa(addrp->sin_addr));
 return(0);
}

//////////////////////////////////////////////
//////////////////////////////////////////////
int main(int argc,char** argv)
{
 init_all_network_interfaces();
 GetIP("eth0");
 SetIP("eth0","1.2.3.4");
 GetIP("eth0");
 return(0);
}
>

So ioctl calls always return a no error value, but IP adress stays the same 
as shown by the result gaved by the Linux Synthetic Target :

<
IP Adress of 'eth0' is '10.0.0.254' 
IP address of 'eth0' set to '1.2.3.4' 
IP Adress of 'eth0' is '10.0.0.254'
>
 
I have proposed a change in the in.c code. (commenting out lines 263-268 do 
the trick ...)
But I agree, that it's not fair to change FreeBSD code, may be i'm forgetting 
something while calling SetIP but i dunno what ... 

Someone got a clue ?
Thanks for your support.

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-10-01 23:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-29 21:35 [ECOS] IP adress Get and Set (SIOCSIFADDR problem ? ) Xun Yuan
2007-09-29 21:46 ` Alok Singh
2007-10-01 23:55   ` Xun Yuan
  -- strict thread matches above, loose matches on Subject: below --
2004-01-16 17:05 sebastien Couret
2004-01-16 19:53 ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).