Understanding the spectra of TeV blazars: implications for the cosmic infrared background