aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-08-05 06:27:22 +0800
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-08-05 06:57:29 +0800
commitb615164d7555977578a17849543e14a16319be41 (patch)
treeb44343bbfbe1cffca215817d8f2dbbcfae21119b
parent84e1c47f7416384bb652a997ffe8c6df5b494215 (diff)
mgcp: Remove the receive code into a new method.
-rw-r--r--openbsc/src/mgcp/mgcp_network.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c
index fcde0a43d..7de15aa6f 100644
--- a/openbsc/src/mgcp/mgcp_network.c
+++ b/openbsc/src/mgcp/mgcp_network.c
@@ -179,11 +179,33 @@ static int send_to(struct mgcp_endpoint *endp, int dest, int is_rtp,
}
}
+static int recevice_from(struct mgcp_endpoint *endp, int fd, struct sockaddr_in *addr,
+ char *buf, int bufsize)
+{
+ int rc;
+ socklen_t slen = sizeof(*addr);
+
+ rc = recvfrom(fd, buf, bufsize, 0,
+ (struct sockaddr *) addr, &slen);
+ if (rc < 0) {
+ LOGP(DMGCP, LOGL_ERROR, "Failed to receive message on: 0x%x errno: %d/%s\n",
+ ENDPOINT_NUMBER(endp), errno, strerror(errno));
+ return -1;
+ }
+
+ /* do not forward aynthing... maybe there is a packet from the bts */
+ if (endp->ci == CI_UNUSED)
+ return -1;
+
+ #warning "Slight spec violation. With connection mode recvonly we should attempt to forward."
+
+ return rc;
+}
+
static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
{
char buf[4096];
struct sockaddr_in addr;
- socklen_t slen = sizeof(addr);
struct mgcp_endpoint *endp;
struct mgcp_config *cfg;
int rc, dest, proto;
@@ -191,17 +213,10 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
endp = (struct mgcp_endpoint *) fd->data;
cfg = endp->cfg;
- rc = recvfrom(fd->fd, &buf, sizeof(buf), 0,
- (struct sockaddr *) &addr, &slen);
- if (rc < 0) {
- LOGP(DMGCP, LOGL_ERROR, "Failed to receive message on: 0x%x errno: %d/%s\n",
- ENDPOINT_NUMBER(endp), errno, strerror(errno));
+ rc = recevice_from(endp, fd->fd, &addr, buf, sizeof(buf));
+ if (rc <= 0)
return -1;
- }
- /* do not forward aynthing... maybe there is a packet from the bts */
- if (endp->ci == CI_UNUSED)
- return -1;
/*
* Figure out where to forward it to. This code assumes that we
@@ -210,7 +225,6 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
* after the Create Connection but we will not as we are not really
* able to tell if this is legitimate.
*/
- #warning "Slight spec violation. With connection mode recvonly we should attempt to forward."
dest = memcmp(&addr.sin_addr, &endp->net_end.addr, sizeof(addr.sin_addr)) == 0 &&
(endp->net_end.rtp_port == addr.sin_port || endp->net_end.rtcp_port == addr.sin_port)
? DEST_BTS : DEST_NETWORK;