use local packet_length variable in sendto

Having a global packet_length variable doesn't seem to be the best
idea. To avoid trouble, a scope local variable should be preferred.