2 This software is available to you under a choice of one of two
3 licenses. You may choose to be licensed under the terms of the GNU
4 General Public License (GPL) Version 2, available at
5 <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD
6 license, available in the LICENSE.TXT file accompanying this
7 software. These details are also available at
8 <http://openib.org/license.html>.
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
11 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
12 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
13 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
14 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
15 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 Copyright (c) 2004 Topspin Communications. All rights reserved.
20 Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
30 #endif /* HAVE_CONFIG_H */
33 For non-i386 systems, we pass socket() through to library code using
34 dlsym() instead of trying to make the system call directly. This
35 may cause problems if this library is LD_PRELOADed before the real C
36 library is available. Eventually we may want to add the same type
37 of system call assembly code as i386 has for IA64 and AMD64, but for
41 #define _GNU_SOURCE /* Get RTLD_NEXT */
44 #include <sys/syscall.h>
50 #include <sys/socket.h>
53 * SDP specific includes
55 #include "linux/sdp_inet.h"
58 #define _SDP_VERBOSE_PRELOAD
61 #define SOCKOP_socket 1
63 #define SOCKOP_connect 3
64 #define SOCKOP_listen 4
65 #define SOCKOP_accept 5
66 #define SOCKOP_getsockname 6
67 #define SOCKOP_getpeername 7
68 #define SOCKOP_socketpair 8
70 #define SOCKOP_recv 10
71 #define SOCKOP_sendto 11
72 #define SOCKOP_recvfrom 12
73 #define SOCKOP_shutdown 13
74 #define SOCKOP_setsockopt 14
75 #define SOCKOP_getsockopt 15
76 #define SOCKOP_sendmsg 16
77 #define SOCKOP_recvmsg 17
79 extern char * program_invocation_name;
80 extern char * program_invocation_short_name;
81 extern char ** const environ;
83 /* ========================================================================= */
84 /*..socket -- replacment socket call. */
101 #ifdef _SDP_VERBOSE_PRELOAD
105 * check for magic enviroment variable
107 if ((AF_INET == domain || AF_INET6 == domain) &&
108 SOCK_STREAM == type) {
112 for (test = *tenviron; NULL != test; test = *++tenviron) {
116 while (*inet == *test && '\0' != *inet) {
122 if ('\0' == *inet && '=' == *test) {
124 domain = AF_INET_SDP;
131 #ifdef _SDP_VERBOSE_PRELOAD
132 fd = fopen("/tmp/libsdp.log.txt", "a+");
134 fprintf(fd, "SOCKET: <%s> domain <%d> type <%d> protocol <%d>\n",
135 program_invocation_short_name, domain, type, protocol);
141 /* Make the socket() system call directly, as described above */
146 __asm__ __volatile__("movl %%ebx, %1\n" /* save %ebx */
147 "movl %3, %%ebx\n" /* put sockopt in %ebx as arg */
148 "int $0x80\n" /* do syscall */
149 "movl %1, %%ebx\n" /* restore %ebx */
150 : "=a" (__ret), "=r" (__scratch)
151 : "0" (__NR_socketcall),
156 /* Use the standard library socket() to pass through the call */
158 static int (*orig_socket)(int, int, int);
161 orig_socket = dlsym(RTLD_NEXT, "socket");
164 return orig_socket(domain, type, protocol);