Refactor sendIcmp code into a new function