add the suggested patch after refactoring; add a unit test
add the suggested patch after refactoring; add a unit test

hexcap/dpkt,lkash/test,smutt/dpkt,jack8daniels2/dpkt,jameslittle/dpkt,bpanneton/dpkt,yangbh/dpkt