diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-08-05 06:27:22 +0800 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-08-08 07:21:22 +0800 |
commit | 5bf8f957015eb70e98e5a803229196ee962e0cb7 (patch) | |
tree | 8f0796776475256035f6d8a6bae4c767462bb3ca | |
parent | 6989b5735052bbb996e4880cdea6dde41458c084 (diff) |
mgcp: Remove the receive code into a new method.
-rw-r--r-- | openbsc/src/mgcp/mgcp_network.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index 76a60ee9c..395eabfb9 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,19 +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) { - LOGP(DMGCP, LOGL_DEBUG, "Unknown message on endpoint: 0x%x\n", ENDPOINT_NUMBER(endp)); - return -1; - } /* * Figure out where to forward it to. This code assumes that we @@ -212,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; |