Synthesis, structure, and magnetic properties of iron and nickel nanoparticles encapsulated into carbon