/*
    Unbind an interface from an IPX network.

    Copyright (C) 1994, 1995  Ales Dryak <e-mail: A.Dryak@sh.cvut.cz>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <stdio.h>
#include <stdlib.h> 
#include <unistd.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/sockios.h>
#include <linux/ipx.h>
#include "ipxutil.h"

int main(int argc,char *argv[])
{
	int sock;
	long net;
	int verbose=0;

	if (argc>=2 && strcmp(argv[1],"-v")==0)
	{
		argc--;
		argv++;
		verbose=1;
	}
	if (argc!=2)
	{
		fprintf(stderr,
			"IPX network drop utility v0.9, (c) Ales Dryak, 1995\n"
			"Usage: ipxdrop [-v] <network>\n");
		exit(1);
	}
	
	if(sscanf(argv[1],"%lx",&net)==0)
	{
		fprintf(stderr,"Unable to parse network number '%s'.\n",argv[1]);
		exit(1);
	}

	net=htonl(net);
		
	sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX);
	if(sock==-1)
	{
		perror("socket");
		exit(1);
	}
	
	if(ioctl(sock,SIOCDELRT,(void *)&net)==-1)
	{
		perror("del route");
		exit(1);
	}

	if (verbose)
	{
		printf("Network ");
		ipx_print_network(net);
		printf(" dropped.\n");
	}
	close(sock);
	return 0;
}
