By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,433 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,433 IT Pros & Developers. It's quick & easy.

Find Interface name

P: n/a
hi all,
i trying to find the intferface name using this coding ,but that is
not working ,,,if anybody this pervious..please help to find the
interface name using Linux C.

//CODE
ioctl(sd, SIOCGIFNAME, &ifr);
strncpy(ifname,ifr.ifr_name,IFNAMSIZ);
printf("Interface name :%s\n",ifname);

//
thanks all

Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
chellappa wrote:
hi all,
i trying to find the intferface name using this coding ,but that is
not working ,,,if anybody this pervious..please help to find the
interface name using Linux C.

//CODE
ioctl(sd, SIOCGIFNAME, &ifr);
strncpy(ifname,ifr.ifr_name,IFNAMSIZ);
printf("Interface name :%s\n",ifname);


In Standard C, an `int' is guaranteed to be able
to count as high as 32767. Some implementations use
a wider `int', but 32767 is the maximum you can be
absolutely sure of.

If one were to write a program to count the number
of times Chellappa has been told that Standard C has
no networking facilities, the number of times he has
been told to take his networking questions to newsgroups
where networking experts hang out, the number of times
he has been given the names of those newsgroups, and the
number of times he has utterly failed to get the message,
would it be wise to use a mere `int' for the counter?

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 15 '05 #2

P: n/a
Eric Sosman wrote:
chellappa wrote:
hi all,
i trying to find the intferface name using this coding ,but that is
not working ,,,if anybody this pervious..please help to find the
interface name using Linux C.

//CODE
ioctl(sd, SIOCGIFNAME, &ifr);
strncpy(ifname,ifr.ifr_name,IFNAMSIZ);
printf("Interface name :%s\n",ifname);

In Standard C, an `int' is guaranteed to be able
to count as high as 32767. Some implementations use
a wider `int', but 32767 is the maximum you can be
absolutely sure of.

If one were to write a program to count the number
of times Chellappa has been told that Standard C has
no networking facilities, the number of times he has
been told to take his networking questions to newsgroups
where networking experts hang out, the number of times
he has been given the names of those newsgroups, and the
number of times he has utterly failed to get the message,
would it be wise to use a mere `int' for the counter?


I'd put bets on at least an unsigned long, preferably an unsigned long
long if the implementation supports it.

Joe
Nov 15 '05 #3

P: n/a
Hi,

I don't know about SIOCGIFNAME, but I assume that what you want is
to call ioctl(sd, SIOCGIFCONF, &ifconf) to obtain all the network
interfaces on your system.

Regards,
Ang Way Chuang

Nov 15 '05 #4

P: n/a
In addition, you may also want to look into these 2 functions:

char *if_indextoname(unsigned ifindex, char *ifname);
struct if_nameindex *if_nameindex(void);

http://www.opengroup.org/onlinepubs/...dextoname.html
http://www.opengroup.org/onlinepubs/...nameindex.html

I think you should download Single Unix Specification version 3 from
www.opengroup.org if you plan to program in Unix. Hope this answer your
question.

Regards,
Ang Way Chuang

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.