summaryrefslogtreecommitdiffstats
path: root/openbsc/src/nat/bsc_nat.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-10-12 23:28:28 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-10-19 16:40:04 +0200
commitf961de1108407623aa2201df4710fecd9a3bf795 (patch)
tree8ee4e7a733b4dd7a498d3ca29f6aa33b6d6c02fd /openbsc/src/nat/bsc_nat.c
parenta09b966cd487885ed81ee9da0476211ef3a8149e (diff)
nat: Use the make_sock routine to listen for incoming connections.
Diffstat (limited to 'openbsc/src/nat/bsc_nat.c')
-rw-r--r--openbsc/src/nat/bsc_nat.c42
1 files changed, 4 insertions, 38 deletions
diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c
index 5403764f4..1baf3c928 100644
--- a/openbsc/src/nat/bsc_nat.c
+++ b/openbsc/src/nat/bsc_nat.c
@@ -42,6 +42,7 @@
#include <openbsc/bsc_nat_sccp.h>
#include <openbsc/ipaccess.h>
#include <openbsc/abis_nm.h>
+#include <openbsc/socket.h>
#include <openbsc/vty.h>
#include <osmocore/gsm0808.h>
@@ -1064,43 +1065,6 @@ static int ipaccess_listen_bsc_cb(struct bsc_fd *bfd, unsigned int what)
return 0;
}
-static int listen_for_bsc(struct bsc_fd *bfd, struct in_addr *in_addr, int port)
-{
- struct sockaddr_in addr;
- int ret, on = 1;
-
- bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- bfd->cb = ipaccess_listen_bsc_cb;
- bfd->when = BSC_FD_READ;
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- addr.sin_addr.s_addr = in_addr->s_addr;
-
- setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
-
- ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr));
- if (ret < 0) {
- fprintf(stderr, "Could not bind the BSC socket: %s\n",
- strerror(errno));
- return -EIO;
- }
-
- ret = listen(bfd->fd, 1);
- if (ret < 0) {
- perror("listen");
- return ret;
- }
-
- ret = bsc_register_fd(bfd);
- if (ret < 0) {
- perror("register_listen_fd");
- return ret;
- }
- return 0;
-}
-
static void print_usage()
{
printf("Usage: bsc_nat\n");
@@ -1293,7 +1257,9 @@ int main(int argc, char **argv)
bsc_msc_connect(nat->msc_con);
/* wait for the BSC */
- if (listen_for_bsc(&bsc_listen, &local_addr, 5000) < 0) {
+ rc = make_sock(&bsc_listen, IPPROTO_TCP, local_addr.s_addr,
+ 5000, ipaccess_listen_bsc_cb);
+ if (rc != 0) {
fprintf(stderr, "Failed to listen for BSC.\n");
exit(1);
}