Homoclinic and heteroclinic solutions for a class of two dimensional hamiltonian systems