我想要做一些原始套接字編程。我有一些編譯/運行在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