the logic here is strange. shouldn't we be early returning if `packet == NULL`? Below this you dereference `packet` directly, even if it is NULL