File: proxy.c

package info (click to toggle)
diald 0.99.4-7.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,100 kB
  • ctags: 935
  • sloc: ansic: 7,109; tcl: 977; sh: 880; perl: 306; makefile: 109
file content (94 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (3)
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
/*
 * tap.c - Proxy interface specific code in diald.
 *	   The proxy interface is used to monitor packets
 *	   when the physical link is down.
 *
 * Copyright (c) 1999 Mike Jagdis.
 * All rights reserved. Please see the file LICENSE which should be
 * distributed with this software for terms of use.
 */

#include "diald.h"


int
send_packet(unsigned short wprot, unsigned char *p, size_t len)
{
	if (proxy.send)
		return proxy.send(&proxy, wprot, p, len);
	errno = -ENOSYS;
	return -1;
}


int
recv_packet(unsigned char *p, size_t len)
{
	return (proxy.recv
		? proxy.recv(&proxy, p, len)
		: 0);
}


void
proxy_start()
{
	if (proxy.start)
		proxy.start(&proxy);
}


void
proxy_stop()
{
	if (proxy.stop)
		proxy.stop(&proxy);
}


void
proxy_close()
{
	if (proxy.close)
		proxy.close(&proxy);
}


void
proxy_release()
{
	if (proxy.release)
		proxy.release(&proxy);
}


int
proxy_init(proxy_t *proxy, char *proxydev)
{
	int fd;

	proxy->ifunit = -1;
	proxy->send = NULL;
	proxy->recv = NULL;
	proxy->init = NULL;
	proxy->start = NULL;
	proxy->stop = NULL;
	proxy->close = NULL;
	proxy->release = NULL;

	if (proxydev) {
		if (!strcmp(proxydev, "none"))
			return 0;
		return proxy_dev_init(proxy, proxydev);
	}

#ifdef AF_NETLINK
	if ((fd = proxy_tap_init(proxy, NULL)) >= 0)
		return fd;
#endif
	if ((fd = proxy_slip_init(proxy, NULL)) >= 0)
		return fd;
	mon_syslog(LOG_ERR, "Unable to get a proxy interface."
				" Manual control only.");
	return -1;
}