Holger Hans Peter Freyther | 97602d9 | 2012-11-11 14:21:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
Holger Hans Peter Freyther | 53aa0f5 | 2017-12-09 13:03:29 +0000 | [diff] [blame] | 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
Holger Hans Peter Freyther | 97602d9 | 2012-11-11 14:21:26 +0100 | [diff] [blame] | 8 | * (at your 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. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
Holger Hans Peter Freyther | 53aa0f5 | 2017-12-09 13:03:29 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Holger Hans Peter Freyther | 97602d9 | 2012-11-11 14:21:26 +0100 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
| 21 | #define _GNU_SOURCE |
| 22 | #include <osmocom/core/application.h> |
| 23 | |
| 24 | #include <osmocom/gprs/gprs_ns.h> |
| 25 | |
Holger Hans Peter Freyther | 49f4e5b | 2013-01-15 21:18:02 +0100 | [diff] [blame] | 26 | #include <sys/types.h> |
| 27 | #include <sys/socket.h> |
| 28 | |
Holger Hans Peter Freyther | 97602d9 | 2012-11-11 14:21:26 +0100 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | |
| 32 | #include <dlfcn.h> |
| 33 | |
| 34 | int (*real_socket)(int, int, int); |
| 35 | |
| 36 | static int GR_SOCKET = -1; |
| 37 | |
| 38 | static void resolve_real(void) |
| 39 | { |
| 40 | if (real_socket) |
| 41 | return; |
| 42 | real_socket = dlsym(RTLD_NEXT, "socket"); |
| 43 | } |
| 44 | |
| 45 | int socket(int domain, int type, int protocol) |
| 46 | { |
| 47 | int fd; |
| 48 | |
| 49 | resolve_real(); |
| 50 | if (domain != AF_INET || type != SOCK_RAW || protocol != IPPROTO_GRE) |
| 51 | return (*real_socket)(domain, type, protocol); |
| 52 | |
| 53 | /* Now call socket with a normal UDP/IP socket and assign to GR_SOCKET */ |
| 54 | fd = (*real_socket)(domain, SOCK_DGRAM, IPPROTO_UDP); |
| 55 | GR_SOCKET = fd; |
| 56 | return fd; |
| 57 | } |
| 58 | |
| 59 | void bssgp_prim_cb() |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | static const struct log_info log_info = {}; |
| 64 | |
| 65 | int main(int argc, char **argv) |
| 66 | { |
| 67 | int rc; |
| 68 | struct gprs_ns_inst *nsi; |
| 69 | |
| 70 | log_init(&log_info, NULL); |
| 71 | |
| 72 | nsi = gprs_ns_instantiate(NULL, NULL); |
| 73 | nsi->frgre.enabled = 1; |
| 74 | |
| 75 | rc = gprs_ns_frgre_listen(nsi); |
| 76 | printf("Result: %s\n", rc == GR_SOCKET ? "PASSED" : "FAILED"); |
| 77 | return rc == GR_SOCKET ? EXIT_SUCCESS : EXIT_FAILURE; |
| 78 | } |
| 79 | |
| 80 | |