我用:
int syn_socket = (AF_INET, SOCK_RAW, IPPROTO_RAW);
创建原始套接字,我有 root权限。然后:
int on = 1;
int rc = setsockopt(syn_socket, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on));
setsockopt
返回-1
,errno
为EBADF
。这是日志:
[2016-12-05 11:02:34 UTC] [syn.cpp:266] [syn]创建raw socket(255)
[2016-12-05 11:02:34 UTC] [syn.cpp:220] [ send_syn_packet] setsockopt(255)失败。 (Ba d文件描述符)
[ 2016-12-05 11:02:34 UTC] [syn.cpp:292] [syn]发送syn 数据包失败。