dd_opt.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <resolv.h>
#include <string.h>
#include <malloc.h>
#include <libintl.h>
#include <stdio.h>
#include <netdb.h>
#include <errno.h>
#include <dirent.h>
#include <procfs.h>
#include <netdir.h>
#include "dd_misc.h"
#include "dd_opt.h"
#define RDISC_FNAME "in.rdisc"
/*
* Free an allocated dhcp option structure.
*/
void
{
int i;
if (opt->error_code == 0) {
case ASCII_OPTION:
}
break;
case BOOLEAN_OPTION:
break;
case IP_OPTION:
}
break;
case NUMBER_OPTION:
break;
case OCTET_OPTION:
}
break;
default:
return;
}
}
/* Don't free the static no-memory error return */
}
}
/*
* Allocate an option structure.
*/
static struct dhcp_option *
{
struct dhcp_option *opt;
opt->error_code = 0;
switch (ot) {
case ASCII_OPTION:
} else {
}
break;
case BOOLEAN_OPTION:
break;
case IP_OPTION:
sizeof (struct in_addr *));
} else {
}
break;
case NUMBER_OPTION:
sizeof (int64_t));
} else {
}
break;
case OCTET_OPTION:
sizeof (uchar_t *));
} else {
}
break;
default:
}
}
return (opt);
}
/*
* Return an out of memory error
*/
static struct dhcp_option *
{
}
return (&opt_nomem);
}
/*
* Return an error based on errno value
*/
static struct dhcp_option *
errno_opt() {
struct dhcp_option *opt;
int serrno;
/* Save errno value before allocation attempt */
return (malloc_failure());
}
return (opt);
}
/*
* Construct list of default routers.
*/
/*ARGSUSED*/
static struct dhcp_option *
get_default_routers(const char *arg)
{
struct dhcp_option *opt;
int addrcnt = 0;
char *cp;
int i;
/*
* Method here is completely bogus; read output from netstat and
* grab lines with destination of 'default'. Look at the netstat
* code if you think there's a better way...
*/
return (errno_opt());
}
continue;
/* got one, add to list */
for (i = addrcnt - 1; i >= 0; --i) {
}
return (opt);
}
for (i = addrcnt - 1; i >= 0; --i) {
}
return (opt);
}
/* LINTED - comparison */
/* inet_addr didn't like it */
}
while (--addrcnt >= 0)
return (opt);
}
++addrcnt;
}
}
/*
* Return all the routers we found.
*/
if (addrcnt != 0) {
for (i = 0; i < addrcnt; ++i) {
}
return (opt);
}
for (i = 0; i < addrcnt; ++i) {
}
} else {
}
}
return (opt);
}
/*ARGSUSED*/
static struct dhcp_option *
get_dns_domain(const char *arg)
{
struct dhcp_option *opt;
opt = malloc_failure();
/* Resolver failed initialization */
} else {
/* Initialized OK, copy domain name to return structure */
/*
* If first one is loopback address, we return empty
* as this almost certainly means that DNS is not
* configured.
*/
else
/* Couldn't allocate return memory */
opt = malloc_failure();
}
}
}
return (opt);
}
/*ARGSUSED*/
static struct dhcp_option *
get_dns_servers(const char *arg)
{
struct dhcp_option *opt;
int i, j;
opt = malloc_failure();
/* Resolver initialization failed */
/*
* If first one is loopback address, we ignore as this
* almost certainly means that DNS is not configured.
*/
} else {
/* Success, copy the data into our return structure */
/* IPv4 only, thanks */
continue;
sizeof (struct in_addr));
/* Out of memory, return immediately */
return (malloc_failure());
}
}
/* Adjust number of addresses returned to real count */
}
}
return (opt);
}
/* Get parameters related to a specific interface */
static struct dhcp_option *
{
int s;
int num_ifs;
int i;
struct dhcp_option *opt;
#define MY_TRUE 1
#define MY_FALSE 0
struct sockaddr_in *sin;
/*
* Open socket, needed for doing the ioctls. Then get number of
* interfaces so we know how much memory to allocate, then get
* all the interface configurations.
*/
return (errno_opt());
}
return (malloc_failure());
}
(void) close(s);
return (opt);
}
/*
* Find the interface which matches the one requested, and then
* return the parameter requested.
*/
continue;
}
switch (code) {
case CD_SUBNETMASK:
(void) close(s);
return (opt);
}
(void) close(s);
return (malloc_failure());
}
(void) close(s);
return (malloc_failure());
}
/*LINTED - alignment*/
break;
case CD_MTU:
(void) close(s);
return (opt);
}
(void) close(s);
return (malloc_failure());
}
break;
case CD_BROADCASTADDR:
(void) close(s);
return (opt);
}
(void) close(s);
return (malloc_failure());
}
(void) close(s);
return (malloc_failure());
}
/*LINTED - alignment*/
break;
default:
}
break;
}
(void) close(s);
}
return (opt);
}
/*
* See if we are using router discovery on this system. Method is to
* read procfs and find out if the in.rdisc daemon is running.
*/
/*ARGSUSED*/
static struct dhcp_option *
get_router_discovery(const char *arg)
{
struct dhcp_option *opt;
return (malloc_failure());
}
} else {
}
return (opt);
}
/*ARGSUSED*/
static struct dhcp_option *
get_nis_domain(const char *arg)
{
struct dhcp_option *opt;
char *d;
int err;
err = yp_get_default_domain(&d);
if (err != 0) {
}
} else {
return (malloc_failure());
}
return (malloc_failure());
}
}
return (opt);
}
/*
* Provide a default for the NISserv option. We can only reliably
* find out the master (as that's the only API) so that's what we provide.
*/
/*ARGSUSED*/
static struct dhcp_option *
get_nis_servers(const char *arg)
{
struct dhcp_option *opt;
int err;
char *d;
char *m;
/*
* Get the default domain name, ask for master of hosts table,
* look master up in hosts table to get address.
*/
err = yp_get_default_domain(&d);
if (err != 0) {
}
}
free(m);
}
} else {
free(m);
return (malloc_failure());
}
return (malloc_failure());
}
/*LINTED - alignment*/
}
return (opt);
}
/*ARGSUSED*/
static struct dhcp_option *
get_nisplus_domain(const char *arg)
{
struct dhcp_option *opt;
return (malloc_failure());
}
}
return (opt);
}
/*ARGSUSED*/
static struct dhcp_option *
get_nisplus_servers(const char *arg)
{
struct dhcp_option *opt;
int i;
int cnt = 0;
struct sockaddr_in *sin;
}
return (opt);
}
}
return (opt);
}
return (malloc_failure());
}
/* Make sure it's an internet-type address */
if (strcmp("inet",
/* Find a translation service */
continue;
}
/* Translate address to normal in_addr structure */
continue;
}
sizeof (struct in_addr));
return (malloc_failure());
}
/*LINTED - alignment*/
++cnt;
}
}
/*
* Adjust size of returned block to the actual data size, as
* the above loop may not have filled in all of the elements
* which were allocated.
*/
return (malloc_failure());
}
}
return (opt);
}
/*
* Retrieve the default value for a specified DHCP option. Option code is
* from the lst in dhcp.h, arg is an option-specific string argument, and
* context is a presently unused parameter intended to allow this mechanism
* to extend to vendor options in the future. For now, only standard options
* are supported. Note that in some cases the returned pointer may be NULL,
* so the caller must check for this case.
*/
/*ARGSUSED*/
struct dhcp_option *
{
struct dhcp_option *opt;
switch (code) {
case CD_SUBNETMASK:
case CD_MTU:
case CD_BROADCASTADDR:
case CD_ROUTER:
return (get_default_routers(arg));
case CD_DNSSERV:
return (get_dns_servers(arg));
case CD_DNSDOMAIN:
return (get_dns_domain(arg));
case CD_ROUTER_DISCVRY_ON:
return (get_router_discovery(arg));
case CD_NIS_DOMAIN:
return (get_nis_domain(arg));
case CD_NIS_SERV:
return (get_nis_servers(arg));
case CD_NISPLUS_DMAIN:
return (get_nisplus_domain(arg));
case CD_NISPLUS_SERVS:
return (get_nisplus_servers(arg));
default:
}
return (opt);
}
}