File: MacRegister.c

package info (click to toggle)
macgate 1.14-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 148 kB
  • ctags: 137
  • sloc: ansic: 1,163; sh: 197; makefile: 59
file content (120 lines) | stat: -rw-r--r-- 3,985 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 *      MacGated - User Space interface to Appletalk-IP decapsulation.
 *               - Utility to register Appletalk-IP Gateways.
 *      Written By: Jay Schulist <Jay.Schulist@spacs.k12.wi.us>
 *                  Copyright (C) 1997-1998 Jay Schulist
 *
 *      Utility to register Appletalk-IP Gateways
 *
 * This software may be used and distributed according to the terms
 * of the GNU Public License, incorporated herein by reference.
 */

#include <unistd.h>
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <syslog.h>
#include <signal.h>

#include <linux/in.h>
#include <linux/if_ether.h>
#include <linux/atalk.h>        /* For struct at */

#include <sys/socket.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/wait.h>

#include "MacGate.h"            /* Our stuff */

extern int      NBPRegIPGATEWAY (unsigned long ipaddr, int atp_skt);
extern int      NBPUnRegIPGATEWAY (unsigned long ipaddr, int atp_skt);
extern int      NBPRegIPADDRESS (unsigned long ipaddr, int atp_skt);
extern int      NBPUnRegIPADDRESS (unsigned long ipaddr, int atp_skt);

int main (int argc, char *argv[])
{
	struct iface_list *MacGateIface = NULL;
        struct iface_list *iface;
	char command[4];
        int err, c;

        while((c=getopt(argc, argv, "ci")) != EOF)
        {
                switch(c)
                {
                        case 'i' :
                                iface = (struct iface_list *)malloc(sizeof( struct iface_list));
                                iface->ip = in_aton(argv[optind++]);
                                iface->next = MacGateIface;
                                MacGateIface = iface;
                                break;

			case 'c' :
				strncpy(command, argv[optind++], 4);
                                if(strncmp(command, "add", 4) != 0)
                                {
                                        if(strncmp(command, "del", 4) != 0)
                                        {
                                                printf("Bad command\n");
                                                exit(1);
                                        }
                                }
                                break;

			default:
                                printf("MacRegister Options:\n");
				printf("	-c	add/del Gateway\n");
				printf("	-i	IP Gateway #\n");
				printf("Example: MacRegister -c add -i 192.168.1.1\n");
				exit(1);
                }
        }

	if(strcmp("add", command) == 0)
        {
		for(iface = MacGateIface; iface != NULL; iface = iface->next)
        	{
                	/* Register MacGate as IP Gateway */
                	if((err = NBPRegIPGATEWAY(iface->ip, DDPIPSKT)) < 0)
                	{
                	        syslog(LOG_ERR, "NBPRegIPGATEWAY() error, %d", err);
                	        return err;
                	}
                	if((err = NBPRegIPADDRESS(iface->ip, DDPIPSKT)) < 0)
                	{
                	        syslog(LOG_ERR, "NBPRegIPADDRESS() error, %d", err);
                	        return err;
                	}
        	}
		printf("MacRegister: Registration of Gateway(s) done\n");

		exit(0);
	}

	if(strcmp("del", command) == 0)
        {
		/* Unregister our IPGATEWAYs and IPADDRESSes */
	        for(iface = MacGateIface; iface != NULL; iface = iface->next)
	        {
	                /* Register MacGate as IP Gateway */
	                if((err = NBPUnRegIPGATEWAY(iface->ip, DDPIPSKT)) < 0)
	                {
	                        syslog(LOG_ERR, "NBPRegIPGATEWAY() error, %d", err);
	                        exit(err);
	                }
	                if((err = NBPUnRegIPADDRESS(iface->ip, DDPIPSKT)) < 0)
	                {
	                        syslog(LOG_ERR, "NBPRegIPADDRESS() error, %d", err);
	                        exit(err);
	                }
	        }
		printf("MacRegister: Unregistration of Gateway(s) done\n");

		exit(0);
	}

	return 1;
}