Wavefront aberrations play a major role when focusing an ultrashort laser pulse to a high-quality focal spot. Here, we report a novel method to measure and correct wavefront aberrations of a 30-fs pulsed laser beam. The method only requires a programmable liquid-crystal spatial light modulator and a camera. Wavefront retrieval is based on pupil segmentation with an annular lens array, which allows us to determine the local phase that minimizes focusing errors due to wavefront aberrations. Our method provides accurate results even when implemented with low dynamic range cameras and polychromatic beams. Finally, the retrieved phase is added to a diffractive lens codified onto the spatial light modulator to experimentally demonstrate near-diffraction-limited femtosecond beam focusing without refractive components.