sockets - How to send igmp join from specific interface with python ? -


i'm trying implement following program in python send join request specific interface (right kernel choosing default).

 import socket  import struct  import time    mcast_grp = '239.0.1.1'   mcast_port = 2000        sock = socket.socket(socket.af_inet, socket.sock_dgram, socket.ipproto_udp)    sock.setsockopt(socket.sol_socket, socket.so_reuseaddr, 1)   sock.bind((mcast_grp, mcast_port))   mreq = struct.pack("4sl", socket.inet_aton(mcast_grp), socket.inaddr_any)   sock.setsockopt(socket.ipproto_ip, socket.ip_add_membership, mreq) 

i trying change socket.inaddr_any socket.inet_aton('x.x.x.x') when x.x.x.x interface ip address represent string, got error.

any way can make work?

thanks, talor

found answer: need change "4sl" "4s4s" , express interface want send igmp join request four-bytes string. can write code follow:
interface = '168.152.63.15' mreq = struct.pack("4s4s", socket.inet_aton(mcast_grp), socket.inet_aton(interface))


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -