|
|
<net/if.h> vs. <linux/if.h>
Hello, All!
What's the big difference of using </if.h> and <linux/if.h> ? Consider for
instance simple code:
#include <net/if.h>
int main(void)
{
char buf[IFNAMSIZ];
struct ifreq ifr;
return 0;
}
#gcc -ansi -W -Wall ifr1.c
ifr1.c: In function `main':
ifr1.c:13: `IFNAMSIZ' undeclared (first use in this function)
ifr1.c:13: (Each undeclared identifier is reported only once
ifr1.c:13: for each function it appears in.)
ifr1.c:14: storage size of `ifr' isn't known
ifr1.c:13: warning: unused variable `buf'
ifr1.c:14: warning: unused variable `ifr'
"Storage size isn't known" means that particular structure was found
undefined in the scope, on the other hand "gcc -E .." produced quite valid
output.
Upon changing included header to <linux/if.h> compilation succeded. What's
so magical in it?
Yes, I'm using RedHat ang glibc.
Thanks in advance.
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
|
|
0
|
|
|
|
Reply
|
Roman
|
3/30/2006 6:22:17 AM |
|
Roman Mashak wrote:
> What's the big difference of using </if.h> and <linux/if.h> ? Consider
> for instance simple code:
>
> #include <net/if.h>
[..]
> char buf[IFNAMSIZ];
> struct ifreq ifr;
[..]
> ifr1.c:13: `IFNAMSIZ' undeclared (first use in this function)
> ifr1.c:13: (Each undeclared identifier is reported only once
> ifr1.c:13: for each function it appears in.)
Constant was not defined.
> ifr1.c:14: storage size of `ifr' isn't known
> ifr1.c:13: warning: unused variable `buf'
> ifr1.c:14: warning: unused variable `ifr'
struct ifreq was declared but not defined.
> Upon changing included header to <linux/if.h> compilation succeded.
> What's so magical in it?
<linux/...> as the name suggests contains stuff that is specific for that
particular kernel. As a general guideline, you shouldn't use that stuff in
userspace programs, at most in programs closely related to the kernel and
programs willing to adapt to every interface change of these private
parts.
Also, the code of course becomes non portable because it depends on Linux
internals/specifics, while the interface in <net/...> is probably more
widely portable.
If you told us here what you're trying to do, people might be able to offer
proper alternatives.
Uli
--
http://www.erlenstar.demon.co.uk/unix/
|
|
0
|
|
|
|
Reply
|
Ulrich
|
3/30/2006 8:15:37 AM
|
|
Roman Mashak wrote:
> Hello, All!
>
> What's the big difference of using </if.h> and <linux/if.h> ? Consider for
> instance simple code:
>
> #include <net/if.h>
> int main(void)
> {
> char buf[IFNAMSIZ];
> struct ifreq ifr;
>
> return 0;
> }
>
> #gcc -ansi -W -Wall ifr1.c
> ifr1.c: In function `main':
> ifr1.c:13: `IFNAMSIZ' undeclared (first use in this function)
> ifr1.c:13: (Each undeclared identifier is reported only once
> ifr1.c:13: for each function it appears in.)
> ifr1.c:14: storage size of `ifr' isn't known
> ifr1.c:13: warning: unused variable `buf'
> ifr1.c:14: warning: unused variable `ifr'
Your include files aren't what they should be.
Igmar
|
|
0
|
|
|
|
Reply
|
Igmar
|
3/30/2006 9:49:48 AM
|
|
Hello, Ulrich!
You wrote on Thu, 30 Mar 2006 10:15:37 +0200:
??>> ifr1.c:13: `IFNAMSIZ' undeclared (first use in this function)
??>> ifr1.c:13: (Each undeclared identifier is reported only once
??>> ifr1.c:13: for each function it appears in.)
UE> Constant was not defined.
It was defined in net/if.h
??>> ifr1.c:14: storage size of `ifr' isn't known
??>> ifr1.c:13: warning: unused variable `buf'
??>> ifr1.c:14: warning: unused variable `ifr'
UE> struct ifreq was declared but not defined.
This struct was declared in net/if.h and I defined 'struct ifreq ifr' in my
code.
??>> Upon changing included header to <linux/if.h> compilation succeded.
??>> What's so magical in it?
UE> <linux/...> as the name suggests contains stuff that is specific for
UE> that particular kernel. As a general guideline, you shouldn't use that
UE> stuff in userspace programs, at most in programs closely related to the
I understand this and want to avoid, that's why I posted here. What's so
unusual in my simple code (where I only made definition) that causes
warnings?
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
|
|
0
|
|
|
|
Reply
|
Roman
|
3/30/2006 10:40:49 AM
|
|
Hello, Igmar!
You wrote on Thu, 30 Mar 2006 11:49:48 +0200:
??>> undeclared (first use in this function) ifr1.c:13: (Each undeclared
??>> identifier is reported only once ifr1.c:13: for each function it
??>> appears in.) ifr1.c:14: storage size of `ifr' isn't known ifr1.c:13:
??>> warning: unused variable `buf' ifr1.c:14: warning: unused variable
??>> `ifr'
IP> Your include files aren't what they should be.
Doubt strongly... The probable cause of warnings is '-ansi' option of
compiler which doesn't suppose any extensions such as sockets.
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
|
|
0
|
|
|
|
Reply
|
Roman
|
3/30/2006 11:23:36 AM
|
|
Roman Mashak wrote:
> Doubt strongly... The probable cause of warnings is '-ansi' option of
> compiler which doesn't suppose any extensions such as sockets.
Yes. In this case you need to explicitly tell the compiler which
extensions you want to use. See the "Feature Test Macros" in the
glibc man page (info libc). You probably need _BSD_SOURCE or
_SVID_SOURCE.
--
mail1dotstofanetdotdk
|
|
0
|
|
|
|
Reply
|
Bjorn
|
3/30/2006 7:00:51 PM
|
|
|
5 Replies
550 Views
(page loaded in 8.454 seconds)
Similiar Articles: Download header files for running unix network programs - comp ...I am new to socket programming and I want to download the entire header file package (unp.h,unpifi.h,net.if_arp.h) used for making unix network progr... My simple tcp sniffer sniffs only incoming packts and not outgoing ...... tcp.h> #include <netpacket/packet.h> #include <net/ethernet.h> #include <net/if.h ... sendto : permission denied.. in linux systems Prev by Date: Re: My simple tcp ... How to get all IP Addresses on AIX using C++ - comp.unix ...... include <stropts.h> #include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <net/if.h ... Unix & Linux: How to get all IP Addresses on AIX using C++ ... ... header's included but still get 'implicit declaration' - comp.unix ...COMPGROUPS.NET | Search ... signal.h> #include <linux/if_ether.h> #include <linux/ip.h> #include <linux/tcp.h ... can not received broadcast message in linux 7.1 - comp.unix ...My OS is linux redhat 7.1 with kernel 2.2. When I make a program to received a ... COMPGROUPS.NET | Search | ... What is wrong with pthread_kill on Redhat Linux ??? - comp.unix ...Hi, I have redhat 9.0 Linux installed on my system with ... thread library used by redhat 9. > pthread_kill and a few ... on Redhat Linux ... unix.programmer * /usr/include/net ... Wildcard bug in matlab (linux version) - comp.soft-sys.matlab ...COMPGROUPS.NET | Search ... supported on Windows, and with different file kinds supported for Windows vs Linux vs ... ZFS RAIDZ versus HARDWARE RAID on SAN - comp.unix.solaris ...John S. <fishinjts@netscape.net> wrote: > On Feb 20, 6:55 pm, "greek_philosophi ... Hardware Raid | yPass.net Blog Solaris ZFS vs. Linux ... ... StorageMojo » ZFS ... Sun ZFS vs. Oracle ASM - comp.unix.solarisChris Morgan <cm@mihalis.net> writes: > Casper H.S. Dik <Casper.Dik@Sun.COM> writes ... Doubt performance Solaris 10 Vs Linux RH - comp.unix.solaris ... Sun ZFS vs ... How to implement a function to copy file on LINUX ? - comp.unix ...COMPGROUPS.NET | Search | ... hi all, im porting WIN func CopyFile to Linux, BOOL CopyFile( LPCTSTR ... vs. - Der Keiler UNIX: The source for the ...Hello, All! What's the big difference of using </if.h> and <linux/if.h> ? Consider for instance simple code: #include <net/if.h> int main(void) {char buf[IFNAMSIZ]; Linux.com | The source for Linux informationLinux.com - For the community, by the community, Linux.com is the central source for Linux information, software, documentation, how-tos and answers across the server ... 7/26/2012 1:55:23 PM
|
|
|
|
|
|
|
|
|