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

Source Code for Module dpkt.stun

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