Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multicast module #77

Merged
merged 2 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/re_rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ int rtp_alloc(struct rtp_sock **rsp);
int rtp_listen(struct rtp_sock **rsp, int proto, const struct sa *ip,
uint16_t min_port, uint16_t max_port, bool enable_rtcp,
rtp_recv_h *recvh, rtcp_recv_h *rtcph, void *arg);
int rtp_open(struct rtp_sock **rsp, int af);
int rtp_hdr_encode(struct mbuf *mb, const struct rtp_header *hdr);
int rtp_hdr_decode(struct rtp_header *hdr, struct mbuf *mb);
int rtp_encode(struct rtp_sock *rs, bool ext, bool marker, uint8_t pt,
Expand Down
1 change: 1 addition & 0 deletions include/re_udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef void (udp_error_h)(int err, void *arg);
int udp_listen(struct udp_sock **usp, const struct sa *local,
udp_recv_h *rh, void *arg);
int udp_connect(struct udp_sock *us, const struct sa *peer);
int udp_open(struct udp_sock **usp, int af);
int udp_send(struct udp_sock *us, const struct sa *dst, struct mbuf *mb);
int udp_send_anon(const struct sa *dst, struct mbuf *mb);
int udp_local_get(const struct udp_sock *us, struct sa *local);
Expand Down
33 changes: 33 additions & 0 deletions src/rtp/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,39 @@ int rtp_listen(struct rtp_sock **rsp, int proto, const struct sa *ip,
}


/**
* Open RTP Socket without bind.
*
* @param rsp Pointer to returned RTP socket
* @param af Address family AF_INET or AF_INET6
*
* @return 0 for success, otherwise errorcode
*/
int rtp_open(struct rtp_sock **rsp, int af)
{
struct rtp_sock *rs;
struct udp_sock *us_rtp;
int err;

err = rtp_alloc(&rs);
if (err)
return err;

rs->proto = IPPROTO_UDP;

us_rtp = NULL;
err = udp_open(&us_rtp, af);
rs->sock_rtp = us_rtp;

if (err)
mem_deref(rs);
else
*rsp = rs;

return err;
}


/**
* Encode a new RTP header into the beginning of the buffer
*
Expand Down
45 changes: 45 additions & 0 deletions src/udp/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,51 @@ int udp_listen(struct udp_sock **usp, const struct sa *local,
}


/**
* Create an UDP socket with specified address family.
*
* @param usp Pointer to returned UDP Socket
* @param af Address family AF_INET or AF_INET6
*
* @return 0 if success, otherwise errorcode
*/
int udp_open(struct udp_sock **usp, int af)
{
struct udp_sock *us = NULL;
int err = 0;
int fd = -1;

if (!usp)
return EINVAL;

us = mem_zalloc(sizeof(*us), udp_destructor);
if (!us)
return ENOMEM;

us->fd = -1;
us->fd6 = -1;

fd = SOK_CAST socket(af, SOCK_DGRAM, IPPROTO_UDP);
if (fd < 0) {
err = errno;
goto out;
}

if (af == AF_INET)
us->fd = fd;
else
us->fd6 = fd;

out:
if (err)
mem_deref(us);
else
*usp = us;

return err;
}


/**
* Connect a UDP Socket to a specific peer.
* When connected, this UDP Socket will only receive data from that peer.
Expand Down