summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/FWTK/tproxy.diff
blob: 234404bf23645bdcfc46aa32ea52e73234ab25b6 (plain)
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
*** tproxy.c.orig	Fri Dec 20 10:53:24 1996
--- tproxy.c	Sun Jan  3 11:33:55 1999
***************
*** 135,140 ****
--- 135,144 ----
  #include	<netinet/in.h>
  #include	<sys/signal.h>
  #include	<syslog.h>
+ #include	<unistd.h>
+ #include	<fcntl.h>
+ #include	<sys/ioctl.h>
+ #include	<net/if.h>
  #include	"tproxy.h"
  
  #ifdef AIX
***************
*** 147,152 ****
--- 151,159 ----
  #define bzero(buf,size) memset(buf, '\0', size);
  #endif /* SYSV */
  
+ #include "ip_compat.h"
+ #include "ip_fil.h"
+ #include "ip_nat.h"
  
  
  /* socket to audio server */
***************
*** 324,329 ****
--- 331,369 ----
  	char localbuf[2048];   
  	void timeout();
  	extern int errno;
+ 	/*
+ 	 * IP-Filter block
+ 	 */
+ 	struct sockaddr_in laddr, faddr;
+ 	struct natlookup natlookup;
+ 	int slen, natfd;
+ 
+ 	bzero((char *)&laddr, sizeof(laddr));
+ 	bzero((char *)&faddr, sizeof(faddr));
+ 	slen = sizeof(laddr);
+ 	if (getsockname(0, (struct sockaddr *)&laddr, &slen) < 0)
+ 		return -1;
+ 	slen = sizeof(faddr);
+ 	if (getpeername(0, (struct sockaddr *)&faddr, &slen) < 0)
+ 		return -1;
+ 	natlookup.nl_inport = laddr.sin_port;
+ 	natlookup.nl_outport = faddr.sin_port;
+ 	natlookup.nl_inip = laddr.sin_addr;
+ 	natlookup.nl_outip = faddr.sin_addr;
+ 	natlookup.nl_flags = IPN_TCP;
+ 	if ((natfd = open(IPL_NAT, O_RDONLY)) < 0)
+ 		return -1;
+ 	if (ioctl(natfd, SIOCGNATL, &natlookup) == -1) {
+ 		syslog(LOG_ERR, "SIOCGNATL failed: %m\n");
+ 		close(natfd);
+ 		return -1;
+ 	}
+ 	close(natfd);
+ 	strcpy(hostname, inet_ntoa(natlookup.nl_realip));
+ 	serverport = ntohs(natlookup.nl_realport);
+ 	/*
+ 	 * End of IP-Filter block
+ 	 */
  
  	/* setup a timeout in case dialog doesn't finish */
  	signal(SIGALRM, timeout);
***************
*** 337,344 ****
--- 377,386 ----
  	 * and modify the call to (and subroutine) serverconnect() as 
  	 * appropriate.
  	 */
+ #if 0
  	strcpy(hostname, "randomhostname");
  	serverport = 7070;
+ #endif
  	/* Can we connect to the server */
  	if ( (serverfd = serverconnect(hostname, serverport)) < 0 ) {
  		/* errno may still be set from previous call */
OpenPOWER on IntegriCloud