Hi
I want to set the requested floating IP from my C++ code.
This can be done in two ways :
1) Using ioctl system calls:
struct lifreq myreq;
..
ioctl(sock, SIOCLIFADDIF, &myreq);
..
ioctl(sock, SIOCSLIFFLAGS, &myreq);
..
ioctl(sock, SIOCSLIFBRDADDR, &myreq);
2) Using system Command with ifconfig string.
command="ifconfig "+ first_phy +" plumb " "+IP+" up netmask "+
findIP.netmask+" broadcast "+findIP.broadcastAddress;
system(command.c_str());
Now i want to know which is the better way of implementing?
|
|
0
|
|
|
|
Reply
|
rishabh.garg (21)
|
10/16/2007 6:46:01 AM |
|
On Tue, 16 Oct 2007 06:46:01 -0000, linux_bp <rishabh.garg@gmail.com> wrote:
> Hi
> I want to set the requested floating IP from my C++ code.
> This can be done in two ways :
>
> 1) Using ioctl system calls:
>
> struct lifreq myreq;
> ioctl(sock, SIOCLIFADDIF, &myreq);
> ioctl(sock, SIOCSLIFFLAGS, &myreq);
> ioctl(sock, SIOCSLIFBRDADDR, &myreq);
>
> 2) Using system Command with ifconfig string.
>
> command="ifconfig "+ first_phy +" plumb " "+IP+" up netmask "+
> findIP.netmask+" broadcast "+findIP.broadcastAddress;
>
> system(command.c_str());
>
> Now i want to know which is the better way of implementing?
The answer depends highly on what you define 'better' to be.
On Solaris, ioctl() calls which are documented in manpages will not go
away a rainy Saturday afternoon, because someone woke up on the wrong
side of his bed. They are the _documented_ and _supported_ interface
which you can depend on. They are also faster than having to fork() an
entirely new process with system().
On the other hand, if you are targetting non-Solaris platforms too,
where ioctl() arguments may vary a lot, it may be "easier" and "more
portable" (for some definition of the terms "easy" and "portable") to
just call ifconfig and let it do its platform-specific magic behind the
scenes. Having said that, if you find yourself forking dozens of
ifconfig processes per second, this may be a very nice way to waste c
lot of time forking short-lived processes and kill the performance of
other application parts.
In the end, it all depends on what your particular application does.
|
|
0
|
|
|
|
Reply
|
Giorgos
|
10/16/2007 8:06:02 AM
|
|