/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1991, 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 252.227-7013.  |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Avenue                               |
 * |         Sunnyvale, California 94088-3650, USA             |
 * |-----------------------------------------------------------|
 */
/* $Header: eisaconnect.c,v 1.2.1.1 92/06/24 14:12:27 marker Exp $ */

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>

#include <net/if.h>
#include <netinet/in.h>

#define	NSIP
#include <netns/ns.h>
#include <netns/ns_if.h>

#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <netdb.h>

extern int errno;
struct	ifreq ifr;
char	name[30];
int	s;
#define SIOCEISACONN    _IOW(i, 99, struct ifreq) /* set connector on EISA board */

main(argc, argv)
	int argc;
	char *argv[];
{
	int af = AF_INET;
	int data;

	if (argc < 3) {
		fprintf(stderr,
		"usage: eisaconnect interface [ thick | thin | 10baseT ]\n");
		exit(1);
	}
	argv++;
	strncpy(name, *argv, sizeof(name));
	strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
	ifr.ifr_addr.sa_family = af;
	s = socket(af, SOCK_DGRAM, 0);
	if (s < 0) {
		perror("eisaconnect: socket");
		exit(1);
	}
        if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
                perror("ioctl (SIOCGIFFLAGS)");
                exit(1);
        }

	/* overload ifr_data with connection code */
	argv++;
	if ( !strcmp( *argv,"thick" ) ){
		ifr.ifr_data = (caddr_t)0x4;
	} else 
	if ( !strcmp( *argv,"thin" ) ){
		ifr.ifr_data = (caddr_t)0x2;
	} else 
	if ( !strcmp( *argv,"10baseT" ) ){
		ifr.ifr_data = (caddr_t)0x0;
	} else {
	   fprintf(stderr,"eisaconnect: unknown connection : %s\n",*argv);
	    fprintf(stderr,
		"usage: eisaconnect interface [ thick | thin | 10baseT ]\n");
	    exit(1);
	}
	if (ioctl(s, SIOCEISACONN, (caddr_t)&ifr) < 0)
		perror("ioctl (SIOCEISACONN)");
	exit(0);
}

