Diffuse scattering of x rays from nonideal layered structures