views:

168

answers:

2

Hi All. I'm trying to do some raw socket programming. I have some example code that compiles/run just fine on a 32 bit machine but when I try to compile the same code on a 64 bit machine I get this discrepancy between /usr/includes/sys and/usr/includes/linux header files. I would have thought that on a 64 bit machine all the headers are already "corrected" for 64 bit usage. Could someone please give me some pointers on how to resolve this issue. I'm using linux(fedora 9 64bit), GCC 4.3.2

Thanks!

I compile as follows: gcc -Wall -o server server.c and get the following errors:

In file included from /usr/include/sys/uio.h:24,
             from /usr/include/sys/socket.h:28,
             from server.c:4:
/usr/include/sys/types.h:46: error: conflicting types for ‘loff_t’
/usr/include/linux/types.h:30: error: previous declaration of ‘loff_t’ was here
/usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’
/usr/include/linux/types.h:13: error: previous declaration of ‘dev_t’ was here
In file included from /usr/include/sys/types.h:133,
             from /usr/include/sys/uio.h:24,
             from /usr/include/sys/socket.h:28,
             from server.c:4:
/usr/include/time.h:105: error: conflicting types for ‘timer_t’
/usr/include/linux/types.h:22: error: previous declaration of ‘timer_t’ was here
In file included from /usr/include/sys/uio.h:24,
             from /usr/include/sys/socket.h:28,
             from server.c:4:
/usr/include/sys/types.h:198: error: conflicting types for ‘int64_t’
/usr/include/linux/types.h:98: error: previous declaration of ‘int64_t’ was here
/usr/include/sys/types.h:204: error: conflicting types for ‘u_int64_t’
/usr/include/linux/types.h:97: error: previous declaration of ‘u_int64_t’ was here
In file included from /usr/include/sys/types.h:220,
             from /usr/include/sys/uio.h:24,
             from /usr/include/sys/socket.h:28,
             from server.c:4:
/usr/include/sys/select.h:78: error: conflicting types for ‘fd_set’
/usr/include/linux/types.h:12: error: previous declaration of ‘fd_set’ was here
In file included from /usr/include/sys/uio.h:24,
             from /usr/include/sys/socket.h:28,
             from server.c:4:
/usr/include/sys/types.h:235: error: conflicting types for ‘blkcnt_t’
/usr/include/linux/types.h:124: error: previous declaration of ‘blkcnt_t’ was here
server.c: In function ‘main’:
server.c:45: warning: implicit declaration of function ‘htons’
server.c: In function ‘sigint’:
server.c:144: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’
server.c:145: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’
+1  A: 

You shouldn't be including things from linux/, that's not supported for userspace programs.

It also looks as if you're missing some include, since you get the warning for htons().

Also you should use %ld in the format string, not just %d to print long int variables.

unwind
According to the code I have you are suppose to use the "linux includes" as I'm trying to send/receive packets at the ethernet level. (I'm not doing ICMP or ping or anythig like that,but doing my own thing). I tried removing them but then I get even more errors. Are you saying that everything that is defined in the linux headers should also be in the "userland" headers?
NomadAlien
@nomad.alien: That's what I was thinking, yes ... I seem unable to dig up a reference now, though. But all the duplicate warnings you're getting suggests that you're including more than you need. I would be easier if you posted some skeleton code, I guess.
unwind
ok, thanks for the tips everybody. I'll try a few of the things mentioned and if that doesn't work out I'll post some code.
NomadAlien
A: 

Assuming that your compilation environment is correct, I suspect that a C macro is defined that shouldn't be or one is defined that shouldn't and that this is causing the incompatible type definitions. Look at the header-files in question to determine what that macro might be.

Steve Emmerson