1 /*
2 * stunnel TLS offloading and load-balancing proxy
3 * Copyright (C) 1998-2021 Michal Trojnara <Michal.Trojnara@stunnel.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses>.
17 *
18 * Linking stunnel statically or dynamically with other modules is making
19 * a combined work based on stunnel. Thus, the terms and conditions of
20 * the GNU General Public License cover the whole combination.
21 *
22 * In addition, as a special exception, the copyright holder of stunnel
23 * gives you permission to combine stunnel with free software programs or
24 * libraries that are released under the GNU LGPL and with code included
25 * in the standard release of OpenSSL under the OpenSSL License (or
26 * modified versions of such code, with unchanged license). You may copy
27 * and distribute such a system following the terms of the GNU GPL for
28 * stunnel and the licenses of the other code concerned.
29 *
30 * Note that people who make modified versions of stunnel are not obligated
31 * to grant this special exception for their modified versions; it is their
32 * choice whether to do so. The GNU General Public License gives permission
33 * to release a modified version without this exception; this exception
34 * also makes it possible to release a modified version which carries
35 * forward this exception.
36 */
37
38 /* getpeername() can't be declared in the following includes */
39 #define getpeername no_getpeername
40 #include <sys/types.h>
41 #include <sys/socket.h> /* for AF_INET */
42 #include <netinet/in.h>
43 #include <arpa/inet.h> /* for inet_addr() */
44 #include <stdlib.h> /* for getenv() */
45 #ifdef __BEOS__
46 #include <be/bone/arpa/inet.h> /* for AF_INET */
47 #include <be/bone/sys/socket.h> /* for AF_INET */
48 #else
49 #include <sys/socket.h> /* for AF_INET */
50 #endif
51 #undef getpeername
52
getpeername(int s,struct sockaddr_in * name,int * len)53 int getpeername(int s, struct sockaddr_in *name, int *len) {
54 char *value;
55
56 (void)s; /* squash the unused parameter warning */
57 (void)len; /* squash the unused parameter warning */
58 name->sin_family=AF_INET;
59 if((value=getenv("REMOTE_HOST")))
60 name->sin_addr.s_addr=inet_addr(value);
61 else
62 name->sin_addr.s_addr=htonl(INADDR_ANY);
63 if((value=getenv("REMOTE_PORT")))
64 name->sin_port=htons((uint16_t)atoi(value));
65 else
66 name->sin_port=htons(0); /* dynamic port allocation */
67 return 0;
68 }
69
70 /* end of env.c */
71