[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <426367E2313C2449837CD2DE46E7EAF9236A78D1@SN2PRD0310MB382.namprd03.prod.outlook.com>
Date: Tue, 24 Jul 2012 22:13:00 +0000
From: KY Srinivasan <kys@...rosoft.com>
To: Dan Williams <dcbw@...hat.com>,
Stephen Hemminger <shemminger@...tta.com>
CC: Olaf Hering <olaf@...fle.de>,
"gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"devel@...uxdriverproject.org" <devel@...uxdriverproject.org>,
"virtualization@...ts.osdl.org" <virtualization@...ts.osdl.org>,
"apw@...onical.com" <apw@...onical.com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"ben@...adent.org.uk" <ben@...adent.org.uk>
Subject: RE: [PATCH 10/17] Tools: hv: Gather ipv[4,6] gateway information
> -----Original Message-----
> From: Dan Williams [mailto:dcbw@...hat.com]
> Sent: Tuesday, July 24, 2012 2:37 PM
> To: Stephen Hemminger
> Cc: Olaf Hering; KY Srinivasan; gregkh@...uxfoundation.org; linux-
> kernel@...r.kernel.org; devel@...uxdriverproject.org;
> virtualization@...ts.osdl.org; apw@...onical.com; netdev@...r.kernel.org;
> ben@...adent.org.uk
> Subject: Re: [PATCH 10/17] Tools: hv: Gather ipv[4,6] gateway information
>
> On Tue, 2012-07-24 at 09:56 -0700, Stephen Hemminger wrote:
> > On Tue, 24 Jul 2012 18:53:59 +0200
> > Olaf Hering <olaf@...fle.de> wrote:
> >
> > > On Tue, Jul 24, Stephen Hemminger wrote:
> > >
> > > > On Tue, 24 Jul 2012 09:01:34 -0700
> > > > "K. Y. Srinivasan" <kys@...rosoft.com> wrote:
> > > >
> > > > > + memset(cmd, 0, sizeof(cmd));
> > > > > + strcat(cmd, "/sbin/ip -f inet route | grep -w ");
> > > > > + strcat(cmd, if_name);
> > > > > + strcat(cmd, " | awk '/default/ {print $3 }'");
> > > >
> > > >
> > > > Much simpler method:
> > > >
> > > > ip route show match 0/0
> > >
> > > This also has the benefit that ip is not called with absolute path, now
> > > that distros move binaries around.
> > >
> > > Olaf
> >
> > It is also not hard to do the same thing with a little function
> > using libmnl
>
> Yeah seriously, netlink anyone? You'll even get nicer error reporting
> that way.
While I will be the first admit that using C API is always better (in C code),
in this particular instance I am not so sure. All I am doing is retrieving information
on default gateways. If there is an error, that is ok and this won't be reported
back to the host. Using the ip command significantly simplifies the code here.
Regards,
K. Y
Powered by blists - more mailing lists