iPXE
nslookup_cmd.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012 Patrick Plenefisch <phplenefisch@wpi.edu>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  */
00019 
00020 FILE_LICENCE ( GPL2_OR_LATER );
00021 
00022 #include <stdio.h>
00023 #include <getopt.h>
00024 #include <ipxe/command.h>
00025 #include <ipxe/parseopt.h>
00026 #include <usr/nslookup.h>
00027 
00028 /** @file
00029  *
00030  * nslookup command
00031  *
00032  */
00033 
00034 /** "nslookup" options */
00035 struct nslookup_options {};
00036 
00037 /** "nslookup" option list */
00038 static struct option_descriptor nslookup_opts[] = {};
00039 
00040 /** "nslookup" command descriptor */
00041 static struct command_descriptor nslookup_cmd =
00042         COMMAND_DESC ( struct nslookup_options, nslookup_opts, 2, 2,
00043                        "<setting> <name>" );
00044 
00045 /**
00046  * The "nslookup" command
00047  *
00048  * @v argc              Argument count
00049  * @v argv              Argument list
00050  * @ret rc              Return status code
00051  */
00052 static int nslookup_exec ( int argc, char **argv ) {
00053         struct nslookup_options opts;
00054         const char *name;
00055         const char *setting_name;
00056         int rc;
00057 
00058         /* Parse options */
00059         if ( ( rc = parse_options ( argc, argv, &nslookup_cmd, &opts ) ) != 0 )
00060                 return rc;
00061 
00062         /* Parse setting name */
00063         setting_name = argv[optind];
00064 
00065         /* Parse name to be resolved */
00066         name = argv[ optind + 1 ];
00067 
00068         /* Look up name */
00069         if ( ( rc = nslookup ( name, setting_name ) ) != 0 )
00070                 return rc;
00071 
00072         return 0;
00073 }
00074 
00075 /** The "nslookup" command */
00076 struct command nslookup_command __command = {
00077         .name = "nslookup",
00078         .exec = nslookup_exec,
00079 };