First-Principles Study of the Electronic and Magnetic Properties of Defects in Carbon Nanostructures