通过原始套接字从接口接收数据时出错

2024-04-25 13:41:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我在下面给出了我的程序。这里我想通过原始套接字从simhost接口接收数据。然后我想把它写进一个缓冲区,但一旦select调用发生,程序执行就会停止并显示键盘中断。我的程序有什么问题?你知道吗

import socket
import select
import sys
import time
from socket import socket, AF_PACKET, SOCK_RAW

s = socket(AF_PACKET, SOCK_RAW)
s.bind(("simhost-eth2", 0))
buffer = []
input = [s]
while 1:
    inputready, outputready, exceptready = select.select(input, [], [])
    for s in inputready:
        l, addr = s.recvfrom(1024)
        buffer.append(l)
        print buffer

Tags: import程序inputrawpacketbuffersocketselect