<s> """<STR_LIT>""" <EOL> import array <EOL> import struct <EOL> from socket import htons , ntohs <EOL> def cksum ( s ) : <EOL> if len ( s ) & <NUM_LIT:1> : <EOL> s = s + '<STR_LIT>' <EOL> words = array . array ( '<STR_LIT:h>' , s ) <EOL> sum = <NUM_LIT:0> <EOL> for word in words : <EOL> sum = sum + ( word & <NUM_LIT> ) <EOL> hi = sum >> <NUM_LIT:16> <EOL> lo = sum & <NUM_LIT> <EOL> sum = hi + lo <EOL> sum = sum + ( sum >> <NUM_LIT:16> ) <EOL> return ( ~ sum ) & <NUM_LIT> <EOL> def gets ( s ) : <EOL> return struct . unpack ( '<STR_LIT:h>' , s ) [ <NUM_LIT:0> ] & <NUM_LIT> <EOL> def mks ( h ) : <EOL> return struct . pack ( '<STR_LIT:h>' , h ) <EOL> def iph2net ( s ) : <EOL> len = htons ( gets ( s [ <NUM_LIT:2> : <NUM_LIT:4> ] ) ) <EOL> id = htons ( gets ( s [ <NUM_LIT:4> : <NUM_LIT:6> ] ) ) <EOL> off = htons ( gets ( s [ <NUM_LIT:6> : <NUM_LIT:8> ] ) ) <EOL> return s [ : <NUM_LIT:2> ] + mks ( len ) + mks ( id ) + mks ( off ) + s [ <NUM_LIT:8> : ] <EOL> def net2iph ( s ) : <EOL> len = ntohs ( gets ( s [ <NUM_LIT:2> : <NUM_LIT:4> ] ) ) <EOL> id = ntohs ( gets ( s [ <NUM_LIT:4> : <NUM_LIT:6> ] ) ) <EOL> off = ntohs ( gets ( s [ <NUM_LIT:6> : <NUM_LIT:8> ] ) ) <EOL> return s [ : <NUM_LIT:2> ] + mks ( len ) + mks ( id ) + mks ( off ) + s [ <NUM_LIT:8> : ] <EOL> def udph2net ( s ) : <EOL> sp = htons ( gets ( s [ <NUM_LIT:0> : <NUM_LIT:2> ] ) ) <EOL> dp = htons ( gets ( s [ <NUM_LIT:2> : <NUM_LIT:4> ] ) ) <EOL> len = htons ( gets ( s [ <NUM_LIT:4> : <NUM_LIT:6> ] ) ) <EOL> return mks ( sp ) + mks ( dp ) + mks ( len ) + s [ <NUM_LIT:6> : ] <EOL> def net2updh ( s ) : <EOL> sp = ntohs ( gets ( s [ <NUM_LIT:0> : <NUM_LIT:2> ] ) ) <EOL> dp = ntohs ( gets ( s [ <NUM_LIT:2> : <NUM_LIT:4> ] ) ) <EOL> len = ntohs ( gets ( s [ <NUM_LIT:4> : <NUM_LIT:6> ] ) ) <EOL> return mks ( sp ) + mks ( dp ) + mks ( len ) + s [ <NUM_LIT:6> : ] </s>
