Redian新闻
>
为什么这段代码在FreeBSD上不work? (编译没问题)
avatar
为什么这段代码在FreeBSD上不work? (编译没问题)# Unix - 噫吁兮,危乎高哉
n*l
1
下面这段代码在Linux Red Hat上run得很好, 可是在FreeBSD上run

之后一点反应都没有。究竟是什么问题呢?谢谢了先。
isock = socket (AF_INET, SOCK_RAW, IPROTO_ICMP);
tsock = socket (AF_INET, SOCK_RAW, IPROTO_TCP);
usock = socket (AF_INET, SOCK_RAW, IPROTO_UDP);
if (isock < 0 || tsock < 0 || usock < 0) {
exit(0);
}
while (1) {
FD_ZERO (&rfds);
FD_SET (isock, &rfds);
FD_SET (usock, &rfds);
FD_SET (tsock, &rfds);
if (select (usock + 1, &rfds, NULL, NULL, NULL) < 1) {
perror("select");
continue;
}
avatar
w*n
2
Here is an excerpt from linux raw(7):
Raw sockets may tap all IP protocols in Linux, even prot
cols like ICMP or TCP which have a protocol module in the
kernel. In this case the packets are passed to both the
kernel module and the raw socket(s). This should not be
relied upon in portable programs, many other BSD socket
implementation have limitations here.
There are detailed explanations in UNP.

【在 n***l 的大作中提到】
: 下面这段代码在Linux Red Hat上run得很好, 可是在FreeBSD上run
: 了
: 之后一点反应都没有。究竟是什么问题呢?谢谢了先。
: isock = socket (AF_INET, SOCK_RAW, IPROTO_ICMP);
: tsock = socket (AF_INET, SOCK_RAW, IPROTO_TCP);
: usock = socket (AF_INET, SOCK_RAW, IPROTO_UDP);
: if (isock < 0 || tsock < 0 || usock < 0) {
: exit(0);
: }
: while (1) {

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。