Re: [anemon-devs] Supporting multiple interfaces |
[ Thread Index |
Date Index
| More anemon.org/devs Archives
]
- To: devs@xxxxxxxxxx
- Subject: Re: [anemon-devs] Supporting multiple interfaces
- From: blue caddy <nomorecaddy@xxxxxxxxx>
- Date: Mon, 25 Feb 2008 02:02:20 -0800 (PST)
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Message-ID; b=hf4JlmiIcsrD0jQGl85gD5EC15dP5SyrLuaJkBncLyso/jVqLC2G4mHIseFJ3RlcSpKXdNf2RIq9iN0FMl2QvZtLDSdeSCWLanryPX/8GBHcuHsIVjDza7OJ3CCg+9apR+NHfjxy4ybhVY+T51Lucsc28oUrkQRzqUkmyTHTSDs=;
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