From b615164d7555977578a17849543e14a16319be41 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 5 Aug 2010 06:27:22 +0800 Subject: mgcp: Remove the receive code into a new method. --- openbsc/src/mgcp/mgcp_network.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'openbsc/src/mgcp/mgcp_network.c') 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; -- cgit v1.2.3