Qt-interest Archive, December 2006
How to get Network Interface name?
Message 1 in thread
Hi all,
How could I get the network interface's name using Qt? I have checked
QNetworkInterface, and try to use its function name() to get some
info. What I got is something like
{D58ECFEB-FACE-4FF6-A705-9D670962CC94}, which I think makes no sense
to human beings, although I have noticed that Trolltech says "On
Windows, it's an internal ID that cannot be changed by the user."
Can I get something that is more sensible? say, something like
"Broadcom Netlink (TM)" or "Generic dialup adapter"? Is it possible
that I get such information from Qt library directly? or should I use
some other tools to get such info?
Any suggestions would be very appreciated. Thanks in advance :-)
--
[ signature omitted ]
Message 2 in thread
On Wednesday 27 December 2006 17:23, YUAN Jue wrote:
> Hi all,
>
> How could I get the network interface's name using Qt? I have checked
> QNetworkInterface, and try to use its function name() to get some
> info.
------ [8< ]----------------------
> Can I get something that is more sensible? say, something like
> "Broadcom Netlink (TM)" or "Generic dialup adapter"? Is it possible
> that I get such information from Qt library directly? or should I use
> some other tools to get such info?
>
> Any suggestions would be very appreciated. Thanks in advance :-)
I'm afraid you have to use the system functions for that. This is OS-Specific
and to my knowledge, Qt doesn't support those functions.
Kind Regards,
--
[ signature omitted ]
Message 3 in thread
Hi Peter,
On 12/28/06, Peter M. Groen <pgroen@xxxxxxxx> wrote:
>
>
> On Wednesday 27 December 2006 17:23, YUAN Jue wrote:
> > Hi all,
> >
> > How could I get the network interface's name using Qt? I have checked
> > QNetworkInterface, and try to use its function name() to get some
> > info.
> ------ [8< ]----------------------
> > Can I get something that is more sensible? say, something like
> > "Broadcom Netlink (TM)" or "Generic dialup adapter"? Is it possible
> > that I get such information from Qt library directly? or should I use
> > some other tools to get such info?
> >
> > Any suggestions would be very appreciated. Thanks in advance :-)
>
> I'm afraid you have to use the system functions for that. This is OS-Specific
> and to my knowledge, Qt doesn't support those functions.
>
Thanks for this info. Then I think libpcap is a choice for this task,
right? Is there any Qt-wrapper for libpcap? That would be great if
there already exists some (google returns nothing about it).
Another question: Is there any way that we could do DHCP to some
certain NIC using Qt function? if not, could libpcap be able to do
that?
Thanks in advance :-)
--
[ signature omitted ]
Message 4 in thread
On Thursday 28 December 2006 17:31, you wrote:
> Thanks for this info. Then I think libpcap is a choice for this task,
> right? Is there any Qt-wrapper for libpcap? That would be great if
> there already exists some (google returns nothing about it).
>
> Another question: Is there any way that we could do DHCP to some
> certain NIC using Qt function? if not, could libpcap be able to do
> that?
>
> Thanks in advance :-)
Hi Yuan,
I don't think there is a Qt-wrapper already, as this is a linux specific
library. Best way to approach this is looking inside the code of tcpdump on
how to get the interface names. Also ethereal should be a dead give-away. :)
Hope this helps.
--
[ signature omitted ]
Message 5 in thread
On Fri, 29 Dec 2006 01:21:01 +0100
"Peter M. Groen" <pgroen@xxxxxxxx> wrote:
> I don't think there is a Qt-wrapper already, as this is a linux
> specific library.
For linux only:
struct ifreq ifr;
struct ifreq *IFR;
struct ifconf ifc;
char buf[1024];
int s, i;
int ok = 0;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s==-1) {
return -1;
}
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
ioctl(s, SIOCGIFCONF, &ifc);
IFR = ifc.ifc_req;
for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) {
printf ("%s\n", IFR->ifr_name);
}
close(s);
HTH
ing. Federico Fuga
--
[ signature omitted ]
Message 6 in thread
Hi,
On 12/29/06, ing. Federico Fuga <fuga@xxxxxxxxxxxxxx> wrote:
> On Fri, 29 Dec 2006 01:21:01 +0100
> "Peter M. Groen" <pgroen@xxxxxxxx> wrote:
>
> > I don't think there is a Qt-wrapper already, as this is a linux
> > specific library.
>
> For linux only:
>
> struct ifreq ifr;
> struct ifreq *IFR;
> struct ifconf ifc;
> char buf[1024];
> int s, i;
> int ok = 0;
>
> s = socket(AF_INET, SOCK_DGRAM, 0);
> if (s==-1) {
> return -1;
> }
>
> ifc.ifc_len = sizeof(buf);
> ifc.ifc_buf = buf;
> ioctl(s, SIOCGIFCONF, &ifc);
>
> IFR = ifc.ifc_req;
> for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) {
> printf ("%s\n", IFR->ifr_name);
> }
>
> close(s);
>
Thanks for all the info and code. It does help :-)
--
[ signature omitted ]