How write a IGMP V3 request

Discussion in 'Python' started by pedr0, Oct 1, 2012.

  1. pedr0

    pedr0 Guest

    Hello,

    I wrote this piece of code but I am not able to modify it in order to use IGMPV3
    and use the source feature of IGMPV3, how can I add a membership for a group on an interface for specified source ?

    Something like this piece of code (C under Linux):

    setsockopt(fd,SOL_IP,MCAST_JOIN_SOURCE_GROUP, &group_source_req,
    sizeof(group_source_req));



    import socket
    import fcntl
    import struct
    import sys

    def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
    s.fileno(),
    0x8915, # SIOCGIFADDR
    struct.pack('256s', ifname[:15])
    )[20:24])

    if len(sys.argv) < 3:
    print 'Usage : [MCAST_ADDR] [PORT] [IFNAME]'
    sys.exit(1)

    MCAST_GRP = sys.argv[1]
    MCAST_PORT = int(sys.argv[2])
    IF = sys.argv[3]

    ip_if = get_ip_address(IF)
    packet = 0
    print("Capturing from "+IF+"("+ip_if+") group "+MCAST_GRP+":"+str(MCAST_PORT))
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind(('', MCAST_PORT))
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton(MCAST_GRP)+socket.inet_aton(ip_if))

    while True:
    try:
    sock.recv(1024)
    print '1K received'
    packet = packet +1
    except:
    print 'Received '+str(packet*1024)+' bytes'
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_DROP_MEMBERSHIP, socket.inet_aton(MCAST_GRP)+socket.inet_aton(ip_if))
    sys.exit(0)
    pedr0, Oct 1, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    0
    Views:
    5,327
    Steve
    Jul 1, 2003
  2. Daniel Bass
    Replies:
    2
    Views:
    3,708
    dave wanta
    Jul 4, 2003
  3. Christian H
    Replies:
    1
    Views:
    868
    Natty Gur
    Jul 29, 2003
  4. Brian Birtle
    Replies:
    2
    Views:
    2,013
    John Saunders
    Oct 16, 2003
  5. George
    Replies:
    5
    Views:
    6,602
    George
    Apr 2, 2004
Loading...

Share This Page