[Twisted-Python] UDP answer from different IP

Wolfgang Eichler Wolfgang.W.Eichler at gmx.de
Thu Apr 6 03:45:21 EDT 2006

I would like to clarify the situation and describe my current work-around:

My twisted application is on client machine A. It sends  SNMP requests to server machine B.

         self.proxy = agentproxy.AgentProxy(
            ipAddress, port,            					# here   '', 6665
            community = community,
            snmpVersion = 'v1',
            protocol = self.port.protocol,
        df = self.proxy.getTable(oids, timeout= 0.5, retryCount=5)

Machine B has two interfaces to the network with IP '' and '' . Here runs some arbitrary SNMP Agent.

Twisted on A opens a port (25000 or so) and sends getNext requests.
These requests contain an ID, that is later used to identifiy incoming messages and  relate them to the request.

To do this snmpprotocol.py has a function getRequestKey, that retrieves this ID from protocol elements.

When sending the getNext-message getRequestKey() returns:

(('', 6665), 782)

This is the key which later should work to identify this request when the answers from B arrive.

But since B uses the other interface to answer, the message that arrives carries:

(('', 6665), 782) and this key is not known.

I wonder why we need the IP address and port at this point, since the ID (782) is unique to machine A and port 25000 and is sufficient to identify the request to which this incoming message belongs.

I patched in snmpprotocol.py:

	def getRequestKey( self, request, target ):
		"""Get the request key from a request/response"""
		for key in [
			'get_request', 'get_response',
			'get_next_request', 'get_bulk_request',
			'response', 'set_request',
				ID = request['pdu'][key]['request_id']
			except KeyError, err:
			except TypeError, err:
					"""Unexpected TypeError retrieving request key %r: %s""",
					key, log.getException(err),
#				return target, ID.get()
				return ID.get()
		raise KeyError( """Unable to get a request key id from %s for target %s"""%( request, target))

This worked.
Could this be checked by some expert ? Any problem with this approach ?


More information about the Twisted-Python mailing list