Showing posts with label tcp. Show all posts
Showing posts with label tcp. Show all posts

Sunday, May 24, 2009

Logging Framework Change

Decided I was going about it all wrong (it was getting late). Changed the implementation to simply provide convenience methods on top of the Python 'logging' package's framework -- with the added benefit of not having to worry about the nitty-gritty of the 'logging' package. Just simple, direct access to the log methods.


>>> from loggable import Loggable
>>> class A(object):
... def __init__(self):
... self.log = Loggable (self)
...
>>> a = A()
>>> a.log.info('test')
2009-05-24 12:48:08,654 - __main__.A - INFO - test
>>> a.log.critical('test')
2009-05-24 12:48:19,475 - __main__.A - CRITICAL - test
>>> a.log.state('test')
2009-05-24 12:48:22,978 - __main__.A - STATE_CHANGE - test
>>> a.log.pktsent ('test')
2009-05-24 12:48:26,402 - __main__.A - PACKET_SENT - test
>>> a.log.generated('test')
2009-05-24 12:48:49,516 - __main__.A - RESPONSE_GEN - test
>>> a.log.field('test')
2009-05-24 12:48:52,475 - __main__.A - FIELD_CHANGE - test


Also have been working on a simple TCP State Machine today. My theory is that we will need to know [1] what state the local TCP connection is in, and [2] what state the remote TCP connection should be in. A simple state machine should allow us to do this with some flexibility. Here is the base class/interface. Suggestions are highly welcomed:

class  TcpState(object):
'''
Base TCP State class. Note that it will, by design, ignore all non-TCP layers.
The TCP State classes will not perform verification that the packets are all
to/from the same hosts. That filtering will be implemented elsewhere in the
framework.
'''

def __init__(self):
self._nextState = None

def packetSent(self, tcpPacket):
'''
Hand off a packet to the TcpState object, where the object will perform
any necessary calculation, and determine if a state change should be
caused by the provided packet.

The packet should be a packet that is considered 'sent' from
the TCP stack that this state belongs to.

@return True if the packet causes a state change. False otherwise.
'''
return False

def packetRecvd(self, tcpPacket):
'''
Same as packetSent, but in the opposite direction.

The packet should be a packet that is considered 'received' from
the remote TCP stack.

@see packetSent
'''
return False

def causedStateChange(self):
'''
Returns true if a previous call to packetSent/packetRecvd caused a
state-change.
'''
return self._nextState != None

def getNextState(self):
'''
Returns the class (subclass of TcpState) that represents the state that
the TCP stack should be in, as a result of previous packetSent/Recvd calls.
@return A class object, or None if no state change should occur.
'''
return self._nextState

Interesting Predicament: Blogo does not like pasting HTML code inside of "pre" tags. It tries to make the HTML code visible, by changing each < and > to "<" or ">", respectively. It seems that I can't find a Blog client that does everything perfectly. So no Python syntax highlighting for now.

Read more...

Friday, May 22, 2009

Wireshark Behavior

Looks like the issue is the adapter.

http://www.mail-archive.com/wireshark-users@wireshark.org/msg03669.html


Read more...

Wireshark Strangeness

Playing around with Wireshark, looking at the dissected data, and getting some weird results. Evidently the small echo server I wrote (see below) does not create the correct TCP checksum. I thought that this might be an issue when using lo0 (loopback), but the data simply doesn't show up in Wireshark when going to/from the same IP address (in my case, 172.16.0.10). Shows up in netstat:

tcp4       0      0  172.16.0.10.46002      172.16.0.10.55074      ESTABLISHED
tcp4 0 0 172.16.0.10.55074 172.16.0.10.46002 ESTABLISHED
tcp4 0 0 *.46002 *.* LISTEN

Not sure what its issue is.

Loopback pcap file available here.


Read more...

Followers