我想要做一些原始套接字编程。我有一些编译/运行在32位机器上的示例代码,但是当我尝试在64位机器上编译相同的代码时,我得到了/ usr/includes/sys和/ usr/includes/linux头文件之间的差异。我原以为在64位机器上,所有的头文件已经被“纠正”了64位的使用。 有人可以给我一些关于如何解决这个问题的指针。我使用的是linux(fedora 9 64bit),GCC 4.3.2在64位机上汇编问题的原始套接字
谢谢!
我编译如下:GCC -Wall -o服务器server.c并得到以下错误:
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’
根据代码我想你可以使用“linux includes”,因为我试图在以太网层发送/接收数据包。 (我没有做ICMP或ping或任何这样的事情,但做我自己的事情)。我试图删除他们,但后来我得到更多的错误。你是说在linux头文件中定义的所有内容都应该放在“userland”头文件中? – NomadAlien 2010-01-18 08:14:10
@ nomad.alien:这就是我的想法,是的......尽管如此,我似乎无法挖掘参考。但是,您收到的所有重复警告都表明您包含的内容超出了您的需要。我想,如果你发布了一些骨架代码,我会更容易。 – unwind 2010-01-18 08:26:28
好的,谢谢大家的提示。我会尝试一些提到的事情,如果这不起作用,我会发布一些代码。 – NomadAlien 2010-01-18 18:27:26