aboutsummaryrefslogtreecommitdiffstats
path: root/tools/gtp-link.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2016-05-10 18:00:51 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2016-05-10 18:19:49 +0200
commit50826a5667c53102dbb7be7c28f1944d4c9d2a70 (patch)
tree07fe8a7e10526a86120c51540b89b2ff7d404dbb /tools/gtp-link.c
parent7b30c5526aad7ffbe08f31c3803a2db2edc8192f (diff)
tools: gtp-link: bind to GTP UDP sockets
So we can fully test packet decapsulation without a full blown openggsn setup by injecting packets and using this simple tool. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tools/gtp-link.c')
-rw-r--r--tools/gtp-link.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/tools/gtp-link.c b/tools/gtp-link.c
index b82bd37..9c12f75 100644
--- a/tools/gtp-link.c
+++ b/tools/gtp-link.c
@@ -27,6 +27,8 @@
#include <unistd.h>
#include <string.h>
#include <time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include <libmnl/libmnl.h>
#include <linux/if.h>
@@ -72,6 +74,31 @@ int main(int argc, char *argv[])
int fd1 = socket(AF_INET, SOCK_DGRAM, 0);
int fd2 = socket(AF_INET, SOCK_DGRAM, 0);
+ struct sockaddr_in sockaddr_fd1 = {
+ .sin_family = AF_INET,
+ .sin_port = htons(3386),
+ .sin_addr = {
+ .s_addr = INADDR_ANY,
+ },
+ };
+ struct sockaddr_in sockaddr_fd2 = {
+ .sin_family = AF_INET,
+ .sin_port = htons(2152),
+ .sin_addr = {
+ .s_addr = INADDR_ANY,
+ },
+ };
+
+ if (bind(fd1, (struct sockaddr *) &sockaddr_fd1,
+ sizeof(sockaddr_fd1)) < 0) {
+ perror("bind");
+ exit(EXIT_FAILURE);
+ }
+ if (bind(fd2, (struct sockaddr *) &sockaddr_fd2,
+ sizeof(sockaddr_fd2)) < 0) {
+ perror("bind");
+ exit(EXIT_FAILURE);
+ }
mnl_attr_put_str(nlh, IFLA_IFNAME, argv[2]);
nest = mnl_attr_nest_start(nlh, IFLA_LINKINFO);
@@ -119,7 +146,15 @@ int main(int argc, char *argv[])
fprintf(stderr, "WARNING: attaching dummy socket descriptors. Keep "
"this process running for testing purposes.\n");
- pause();
+
+ while (1) {
+ struct sockaddr_in addr;
+ socklen_t len = sizeof(addr);
+
+ ret = recvfrom(fd1, buf, sizeof(buf), 0,
+ (struct sockaddr *)&addr, &len);
+ printf("received %d bytes via UDP socket\n", ret);
+ }
return 0;
}