dhcp_cmd.c File Reference

DHCP management commands. More...

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <assert.h>
#include <getopt.h>
#include <gpxe/netdevice.h>
#include <gpxe/in.h>
#include <gpxe/command.h>
#include <usr/dhcpmgmt.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static void dhcp_syntax (char **argv)
 "dhcp" command syntax message
static int dhcp_exec (int argc, char **argv)
 The "dhcp" command.
static void pxebs_syntax (char **argv)
 "pxebs" command syntax message
static int pxebs_exec (int argc, char **argv)
 The "pxebs" command.

Variables

struct command dhcp_commands[] __command
 DHCP management commands.


Detailed Description

DHCP management commands.

Definition in file dhcp_cmd.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static void dhcp_syntax ( char **  argv  )  [static]

"dhcp" command syntax message

Parameters:
argv Argument list

Definition at line 46 of file dhcp_cmd.c.

References printf().

Referenced by dhcp_exec().

00046                                         {
00047         printf ( "Usage:\n"
00048                  "  %s <interface>\n"
00049                  "\n"
00050                  "Configure a network interface using DHCP\n",
00051                  argv[0] );
00052 }

static int dhcp_exec ( int  argc,
char **  argv 
) [static]

The "dhcp" command.

Parameters:
argc Argument count
argv Argument list
Return values:
rc Exit code

Definition at line 61 of file dhcp_cmd.c.

References dhcp(), dhcp_syntax(), find_netdev(), getopt_long(), net_device::name, netdev, NULL, optind, printf(), and strerror().

00061                                                {
00062         static struct option longopts[] = {
00063                 { "help", 0, NULL, 'h' },
00064                 { NULL, 0, NULL, 0 },
00065         };
00066         const char *netdev_txt;
00067         struct net_device *netdev;
00068         int c;
00069         int rc;
00070 
00071         /* Parse options */
00072         while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
00073                 switch ( c ) {
00074                 case 'h':
00075                         /* Display help text */
00076                 default:
00077                         /* Unrecognised/invalid option */
00078                         dhcp_syntax ( argv );
00079                         return 1;
00080                 }
00081         }
00082 
00083         /* Need exactly one interface name remaining after the options */
00084         if ( optind != ( argc - 1 ) ) {
00085                 dhcp_syntax ( argv );
00086                 return 1;
00087         }
00088         netdev_txt = argv[optind];
00089 
00090         /* Parse arguments */
00091         netdev = find_netdev ( netdev_txt );
00092         if ( ! netdev ) {
00093                 printf ( "No such interface: %s\n", netdev_txt );
00094                 return 1;
00095         }
00096 
00097         /* Perform DHCP */
00098         if ( ( rc = dhcp ( netdev ) ) != 0 ) {
00099                 printf ( "Could not configure %s: %s\n", netdev->name,
00100                          strerror ( rc ) );
00101                 return 1;
00102         }
00103 
00104         return 0;
00105 }

static void pxebs_syntax ( char **  argv  )  [static]

"pxebs" command syntax message

Parameters:
argv Argument list

Definition at line 112 of file dhcp_cmd.c.

References printf().

Referenced by pxebs_exec().

00112                                          {
00113         printf ( "Usage:\n"
00114                  "  %s <interface> <server_type>\n"
00115                  "\n"
00116                  "Perform PXE Boot Server discovery\n",
00117                  argv[0] );
00118 }

static int pxebs_exec ( int  argc,
char **  argv 
) [static]

The "pxebs" command.

Parameters:
argc Argument count
argv Argument list
Return values:
rc Exit code

Definition at line 127 of file dhcp_cmd.c.

References find_netdev(), getopt_long(), net_device::name, netdev, NULL, optind, printf(), pxebs(), pxebs_syntax(), strerror(), and strtoul().

00127                                                 {
00128         static struct option longopts[] = {
00129                 { "help", 0, NULL, 'h' },
00130                 { NULL, 0, NULL, 0 },
00131         };
00132         const char *netdev_txt;
00133         const char *pxe_type_txt;
00134         struct net_device *netdev;
00135         unsigned int pxe_type;
00136         char *end;
00137         int c;
00138         int rc;
00139 
00140         /* Parse options */
00141         while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
00142                 switch ( c ) {
00143                 case 'h':
00144                         /* Display help text */
00145                 default:
00146                         /* Unrecognised/invalid option */
00147                         pxebs_syntax ( argv );
00148                         return 1;
00149                 }
00150         }
00151         if ( optind != ( argc - 2 ) ) {
00152                 pxebs_syntax ( argv );
00153                 return 1;
00154         }
00155         netdev_txt = argv[optind];
00156         pxe_type_txt = argv[ optind + 1 ];
00157 
00158         /* Parse arguments */
00159         netdev = find_netdev ( netdev_txt );
00160         if ( ! netdev ) {
00161                 printf ( "No such interface: %s\n", netdev_txt );
00162                 return 1;
00163         }
00164         pxe_type = strtoul ( pxe_type_txt, &end, 0 );
00165         if ( *end ) {
00166                 printf ( "Bad server type: %s\n", pxe_type_txt );
00167                 return 1;
00168         }
00169 
00170         /* Perform Boot Server Discovery */
00171         if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
00172                 printf ( "Could not discover boot server on %s: %s\n",
00173                          netdev->name, strerror ( rc ) );
00174                 return 1;
00175         }
00176 
00177         return 0;
00178 }


Variable Documentation

struct command dhcp_commands [] __command

Initial value:

 {
        {
                .name = "dhcp",
                .exec = dhcp_exec,
        },
        {
                .name = "pxebs",
                .exec = pxebs_exec,
        },
}
DHCP management commands.

Definition at line 181 of file dhcp_cmd.c.


Generated on Tue Apr 6 20:01:46 2010 for gPXE by  doxygen 1.5.7.1