def bind(self, addr, port, tos, ttl, df):
log.debug(
"bind(addr=%s, port=%d, tos=%d, ttl=%d)", addr, port, tos, ttl)
self.socket = socket.socket(
socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_TOS, tos)
self.socket.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind((addr, port))
if df:
if (sys.platform == "linux2"):
self.socket.setsockopt(socket.SOL_IP, 10, 2)
elif (sys.platform == "win32"):
self.socket.setsockopt(socket.SOL_IP, 14, 1)
elif (sys.platform == "darwin"):
log.error("do-not-fragment can not be set on darwin")
else:
log.error("unsupported OS, ignore do-not-fragment option")
else:
if (sys.platform == "linux2"):
self.socket.setsockopt(socket.SOL_IP, 10, 0)
评论列表
文章目录