| 1 |
/* Load the real underlying functions for withsctp and related scripts. |
| 2 |
* |
| 3 |
* Copyright 2003 La Monte HP Yarroll <[email protected]> |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions |
| 7 |
* are met: |
| 8 |
* |
| 9 |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer. |
| 11 |
* 2. Redistributions in binary form must reproduce the above |
| 12 |
* copyright notice, this list of conditions and the following |
| 13 |
* disclaimer in the documentation and/or other materials provided with |
| 14 |
* the distribution. |
| 15 |
* 3. The name of the author may not be used to endorse or promote |
| 16 |
* products derived from this software without specific prior written |
| 17 |
* permission. |
| 18 |
* |
| 19 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 20 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 23 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 25 |
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 27 |
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 28 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 29 |
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 |
*/ |
| 31 |
#include <stdio.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include "sctp_socket.h" |
| 34 |
|
| 35 |
int (*real_bind)(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen); |
| 36 |
int (*real_socket)(int domain, int type, int protocol); |
| 37 |
int (*real_setsockopt)(int s, int level, int optname, const void *optval, |
| 38 |
socklen_t optlen); |
| 39 |
static void *lib_handle = NULL; |
| 40 |
|
| 41 |
void |
| 42 |
_sctp_load_libs(void) |
| 43 |
{ |
| 44 |
if (NULL != lib_handle) return; /* Only init once. */ |
| 45 |
|
| 46 |
if (!(lib_handle = dlopen("libc.so", RTLD_LAZY))) { |
| 47 |
if (!(lib_handle = dlopen("libc.so.6", RTLD_LAZY))) { |
| 48 |
fprintf(stderr, "error loading libc!\n"); |
| 49 |
exit (1); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
if (!(real_socket = dlsym(lib_handle, "socket"))) { |
| 54 |
fprintf(stderr, "socket() not found in libc!\n"); |
| 55 |
exit (1); |
| 56 |
} |
| 57 |
|
| 58 |
if (!(real_bind = dlsym(lib_handle, "bind"))) { |
| 59 |
fprintf(stderr, "bind() not found in libc!\n"); |
| 60 |
exit (1); |
| 61 |
} |
| 62 |
|
| 63 |
if (!(real_setsockopt = dlsym(lib_handle, "setsockopt"))) { |
| 64 |
fprintf(stderr, "setsockopt() not found in libc!\n"); |
| 65 |
exit (1); |
| 66 |
} |
| 67 |
} |