Package dpkt :: Module stun
[hide private]
[frames] | no frames]

Source Code for Module dpkt.stun

 1  # $Id: stun.py 382 2006-07-31 04:07:52Z jonojono $ 
 2   
 3  """Simple Traversal of UDP through NAT.""" 
 4   
 5  import dpkt 
 6   
 7  # STUN - RFC 3489 
 8  # http://tools.ietf.org/html/rfc3489 
 9  # Each packet has a 20 byte header followed by 0 or more attribute TLVs. 
10   
11  # Message Types 
12  BINDING_REQUEST                 = 0x0001 
13  BINDING_RESPONSE                = 0x0101 
14  BINDING_ERROR_RESPONSE          = 0x0111 
15  SHARED_SECRET_REQUEST           = 0x0002 
16  SHARED_SECRET_RESPONSE          = 0x0102 
17  SHARED_SECRET_ERROR_RESPONSE    = 0x0112 
18   
19  # Message Attributes 
20  MAPPED_ADDRESS                  = 0x0001 
21  RESPONSE_ADDRESS                = 0x0002 
22  CHANGE_REQUEST                  = 0x0003 
23  SOURCE_ADDRESS                  = 0x0004 
24  CHANGED_ADDRESS                 = 0x0005 
25  USERNAME                        = 0x0006 
26  PASSWORD                        = 0x0007 
27  MESSAGE_INTEGRITY               = 0x0008 
28  ERROR_CODE                      = 0x0009 
29  UNKNOWN_ATTRIBUTES              = 0x000a 
30  REFLECTED_FROM                  = 0x000b 
31   
32 -class STUN(dpkt.Packet):
33 __hdr__ = ( 34 ('type', 'H', 0), 35 ('len', 'H', 0), 36 ('xid', '16s', 0) 37 )
38
39 -def tlv(buf):
40 n = 4 41 t, l = struct.unpack('>HH', buf[:n]) 42 v = buf[n:n+l] 43 buf = buf[n+l:] 44 return (t,l,v, buf)
45