diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-04-04 15:24:11 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-04-04 15:24:11 +0200 |
commit | 860c8955c3bc15b59c0c85188e66f630f38f0563 (patch) | |
tree | 884c52c506039167dc518e56809ec7439c2d38ea /openbsc | |
parent | c33701c4e557da47974f370ea93f3e7d88efb241 (diff) |
Revert "bsc_msc_ip: Use the autobind functionality of the kernel"
The autobind is not working as I wanted it to work. So we will
revert this for now and then try something else.
This reverts commit fd876b7488a8ae924f1a09144265d4474495408f.
Diffstat (limited to 'openbsc')
-rw-r--r-- | openbsc/src/bsc_msc_ip.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/openbsc/src/bsc_msc_ip.c b/openbsc/src/bsc_msc_ip.c index 535445a4a..0bdb8ba54 100644 --- a/openbsc/src/bsc_msc_ip.c +++ b/openbsc/src/bsc_msc_ip.c @@ -642,6 +642,7 @@ static void mgcp_forward(struct msgb *msg) static int mgcp_create_port(void) { int on; + int port; struct sockaddr_in addr; mgcp_agent.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0); @@ -653,10 +654,26 @@ static int mgcp_create_port(void) on = 1; setsockopt(mgcp_agent.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); - /* connect to the remote by using autobind */ + /* try to bind the socket */ memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + + for (port = 2727; port < 3000; ++port) { + addr.sin_port = htons(port); + if (bind(mgcp_agent.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) == 0) + break; + perror("foo"); + } + + if (port >= 3000) { + LOGP(DMGCP, LOGL_FATAL, "Failed to bind to any port.\n"); + close(mgcp_agent.bfd.fd); + mgcp_agent.bfd.fd = -1; + return -1; + } + + /* connect to the remote */ addr.sin_port = htons(2427); if (connect(mgcp_agent.bfd.fd, (struct sockaddr *) & addr, sizeof(addr)) < 0) { LOGP(DMGCP, LOGL_FATAL, "Failed to connect to local MGCP GW. %d\n", errno); |