Example #1
0
/**
 * The "pxebs" command
 *
 * @v argc		Argument count
 * @v argv		Argument list
 * @ret rc		Return status code
 */
static int pxebs_exec ( int argc, char **argv ) {
	struct pxebs_options opts;
	struct net_device *netdev;
	unsigned int pxe_type;
	int rc;

	/* Parse options */
	if ( ( rc = parse_options ( argc, argv, &pxebs_cmd, &opts ) ) != 0 )
		return rc;

	/* Parse net device name */
	if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
		return rc;

	/* Parse boot server type */
	if ( ( rc = parse_integer ( argv[ optind + 1 ], &pxe_type ) ) != 0 )
		return rc;

	/* Perform Boot Server Discovery */
	if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
		printf ( "Could not discover boot server on %s: %s\n",
			 netdev->name, strerror ( rc ) );
		return rc;
	}

	return 0;
}
Example #2
0
/**
 * The "pxebs" command
 *
 * @v argc		Argument count
 * @v argv		Argument list
 * @ret rc		Exit code
 */
static int pxebs_exec ( int argc, char **argv ) {
	static struct option longopts[] = {
		{ "help", 0, NULL, 'h' },
		{ NULL, 0, NULL, 0 },
	};
	const char *netdev_txt;
	const char *pxe_type_txt;
	struct net_device *netdev;
	unsigned int pxe_type;
	char *end;
	int c;
	int rc;

	/* Parse options */
	while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
		switch ( c ) {
		case 'h':
			/* Display help text */
		default:
			/* Unrecognised/invalid option */
			pxebs_syntax ( argv );
			return 1;
		}
	}
	if ( optind != ( argc - 2 ) ) {
		pxebs_syntax ( argv );
		return 1;
	}
	netdev_txt = argv[optind];
	pxe_type_txt = argv[ optind + 1 ];

	/* Parse arguments */
	netdev = find_netdev ( netdev_txt );
	if ( ! netdev ) {
		printf ( "No such interface: %s\n", netdev_txt );
		return 1;
	}
	pxe_type = strtoul ( pxe_type_txt, &end, 0 );
	if ( *end ) {
		printf ( "Bad server type: %s\n", pxe_type_txt );
		return 1;
	}

	/* Perform Boot Server Discovery */
	if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
		printf ( "Could not discover boot server on %s: %s\n",
			 netdev->name, strerror ( rc ) );
		return 1;
	}

	return 0;
}