[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openmosix-devel
Subject:    Re: [Openmosix-devel] openMosix Userland Tools for 2.6
From:       Matteo <matteo () magm3 ! com>
Date:       2005-07-25 17:16:09
Message-ID: 1122311769.9887.7.camel () localhost ! localdomain
[Download RAW message or body]

I've juste made a C++ function to do exactly that...
I'll paste it here, it works pretty well.
For the credit, it is based on an original code by Gilbert Cao, and it
is GPL (taken from his opendd project
http://cvs.bsdmon.com/cvs/cgi/viewcvs.cgi/opendd/):

int
SysInfo::extractLocalIP() {
	struct sockaddr sockAddr;
	struct ifreq ifr;
  	int fd;
	string ifname="eth0";
  
  /* Open a dummy socket */
  if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
    return 0;
  
  memset(&ifr, 0, sizeof(struct ifreq));
  strcpy(ifr.ifr_name, ifname.c_str());
  if (ioctl(fd, SIOCGIFADDR, &ifr) >= 0) {
    if (ifr.ifr_addr.sa_family == AF_INET) {
      memcpy(&sockAddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
      close(fd);    
	  localIP = string(inet_ntoa(((struct sockaddr_in
*)&sockAddr)->sin_addr));
	  return 1;
    }
  }
  close(fd);
  return 0;
}

here localIP is of type string, private member of the SysInfo class.
Variable ifname can be passed in argument...

I hope this helps, at least it doesn't imply new dependences.

Mattéo

Le samedi 23 juillet 2005 à 07:05 -0500, Evan Hisey a écrit :
> The original attempt was soemthing like that. But it only works if you
> have ip installed. on PXE boot's that is not guarenteed. With it built
> in to teh daemon, then you know it is there, and have fewer outside
> dependencies.
> 
> Evan
> 
> On 7/23/05, shogunx <shogunx@sleekfreak.ath.cx> wrote:
> > On Thu, 21 Jul 2005, Evan Hisey wrote:
> > 
> > > Hey list-
> > >   There is now an anonymous svn access to the Userland Tools. After
> > > getting snagged on a sane method of discovering the local host IP ( we
> > > ended up raiding the original omdiscd). We are now making progress
> > > again, and hope to get the omd finished
> > 
> > here is a shell command for such... not sure about the sanity though.
> > 
> > ip address show eth0 | egrep -m 1 -o '[[:digit:]]+.[[:digit:]]+.[[:digit:]]+[.][[:digit:]]+ '
> > 
> > just a random tangent, but might be handy to someone.
> > 
> > sleekfreak pirate broadcast
> > http://sleekfreak.ath.cx:81/
> > 
> >
> 
> 
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
> _______________________________________________
> openMosix-devel mailing list
> openMosix-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openmosix-devel
> 



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&opÌk
_______________________________________________
openMosix-devel mailing list
openMosix-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openmosix-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic