Re: [anemon-devs] Supporting multiple interfaces

[ Thread Index | Date Index | More anemon.org/devs Archives ]


Hi Mathieu,

I actually got this to work using setsockopt:

def SetOutIf(self, outIf):
    self.dhcp_socket.setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,struct.pack("%ds" %(len(outIf)+1,), outIf))

I also had to add REUSEADDR in dhcp_network.py

class DhcpServer(DhcpNetwork) :
    def __init__(self, listen_address="0.0.0.0", client_listen_port=67,server_listen_port=68) :
        
        DhcpNetwork.__init__(self,listen_address,server_listen_port,client_listen_port)
        
        self.dhcp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.dhcp_socket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)
        self.dhcp_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
        self.dhcp_socket.bind((self.listen_address, self.listen_port))


Then I had to make the script multi-threaded:

from threading import *
import pyDaemon
import threading

class SrvrThread ( threading.Thread ):
    def __init__(self,srvr):
        Thread.__init__(self)
        self.srvr = srvr
        self.status = -1
    def run ( self ):
        while True :
                self.srvr.GetNextDhcpPacket()

pyDaemon.createDaemon()
server = {}
for i in range(len(intList)):
    int = [intList[i]][0]
    server[int] = Server(netopt)
    server[int].SetOutIf(int)
    sThread=SrvrThread(server[int])
    sThread.start()


And then I got what I was looking for.

Thanks,
Blue

----- Original Message ----
From: Mathieu Ignacio <mathieu.ignacio@xxxxxxxxx>
To: devs@xxxxxxxxxx
Sent: Wednesday, February 20, 2008 2:46:06 PM
Subject: Re: [anemon-devs] Supporting multiple interfaces

blue caddy wrote:
> Using pydhcplib-0.3.2, I have added a static route to 255.255.255.255 via eth1.  
> This seems to work, as Offers and Acks are going out this interface.  Now, I'd like to run the server on eth2, eth3, etc.
> Do I have to use raw sockets, or is there a better way to accomplish it?

Due to the "high" level of python network 
implementation, pydhcp can't distinct network 
interfaces. Even the use of raw sockets 
weren't enough to do this in pure python <= 
2.4 (raw sockets were not fully implemented 
and/or lack of documentation to use it). I 
didn't update pydhcp since python 2.4 and 
early 2.5, then i can't tell you if raw 
socket implementation/documentation evolved.


> 
> thanks,
> Blue

Bye.
Mathieu.


      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/