We could do this before clearing buf and calling sscanf(), thereby saving the need to do those things when ip is NULL.