/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1990 MIPS Computer Systems, Inc.            |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 52.227-7013.   |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Drive                                |
 * |         Sunnyvale, CA 94086                               |
 * |-----------------------------------------------------------|
 */
#ident	"$Header: dlconfig.c,v 1.1.2.1 92/06/24 14:12:25 marker Exp $"

#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <sys/dlpi.h>
#include <sys/stropts.h>
#include <svr3/bsd/net/if.h>
#include <sys/dlpisif.h>

char databuff[256];
char ctrlbuff[256];
struct strbuf ctl;
struct strbuf dat;
int fd;
int ret;
char *cp;
extern flag;
extern char *sys_errlist[];
extern verbose;
extern unsigned char dlpi_macaddr[];
extern dlpi_macaddr_len;

dl_info_ack_t dlpi_last_info;

#ifndef	PHYAD_SIZE
#define	PHYAD_SIZE	6
#endif

/*
 * dlpiconf - configure IF->PPA translations
 *
 *    dlpiconf /dev/dlpisif ppa# if_name
 *
 */

main(argc, argv)
	int argc;
	char *argv[];
{
	dlpisif_sifname_t dsif;
	extern char *optarg;
	extern int optind, opterr;
	int c;
	char *cmd = argv[0];

	while ((c = getopt (argc, argv, "v")) != -1)
	    switch (c) {
		case 'v':
		    verbose++;
		    break;

		default:
		    fprintf (stderr, "usage: %s: [-v] device ppa# if_name\n", cmd);
		    exit (1);
	    }

	fd = dlpi_open (argv[optind++]);
	dlpi_info_req (fd);

	dsif.ppa = strtol (argv[optind++], (char **)0, 0);
	strncpy (dsif.ifname, argv[optind++], IFNAMSIZ);

	dlpi_strioctl (fd, DLPISIF_CONFPPA, 2, &dsif, sizeof(dsif));
	dlpi_info_req (fd);
	dlpi_attach   (fd, dsif.ppa);
	dlpi_info_req (fd);
	dlpi_detach   (fd);
	dlpi_info_req (fd);

	if (!verbose)
	    dlpi_enetaddr (dlpi_macaddr, dlpi_macaddr_len);
	close(fd);
	exit(0);
}
