Skip to content

Commit

Permalink
SDP support for <proto> udp
Browse files Browse the repository at this point in the history
- As per RFC 8866, without rtpmap and possibly with fmtp
- This example shows [unregistered] media type application/vnd.wireguard
- Wireshark does not like the fmtp: line -- that would be a bug there

v=0
o=- 3280287138 1947228850 IN IP6 2001:db8:12::34
s=-
c=IN IP6 2001:db8:12::34
t=0 0
m=application 9638 udp vnd.wireguard
a=fmtp:vnd.wireguard pubkey=z7otO6+NKCOM/I7gq6mvcVqYyX3u27Z0WVKMY/juel8=
a=sendrecv
  • Loading branch information
vanrein committed Oct 4, 2022
1 parent 3708104 commit c34429a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/re_fmt.h
Expand Up @@ -114,6 +114,8 @@ void str_ncpy(char *dst, const char *src, size_t n);
int str_dup(char **dst, const char *src);
int str_x64dup(char **dst, uint64_t val);
int str_cmp(const char *s1, const char *s2);
int str_ncmp(const char *s1, const char *s2, size_t n);
const char *str_str(const char *s1, const char *s2);
int str_casecmp(const char *s1, const char *s2);
size_t str_len(const char *s);
const char *str_error(int errnum, char *buf, size_t sz);
Expand Down
37 changes: 37 additions & 0 deletions src/fmt/str.c
Expand Up @@ -129,6 +129,43 @@ int str_cmp(const char *s1, const char *s2)
}


/**
* Compare two 0-terminated strings up to n positions
*
* @param s1 First string
* @param s2 Second string
*
* @return an integer less than, equal to, or greater than zero if s1 is found
* respectively, to be less than, to match, or be greater than s2 in
* the first n positions
*/
int str_ncmp(const char *s1, const char *s2, size_t n)
{
if (!s1 || !s2)
return 1;

return strncmp(s1, s2, n);
}


/**
* Check if one 0-terminated string contains another
*
* @param s1 First string
* @param s2 Second string
*
* @return a position in s1 where it contains s2 as a substring, or NULL
* if s2 does not occur inside s1
*/
const char *str_str(const char *s1, const char *s2)
{
if (!s1 || !s2)
return NULL;

return strstr(s1, s2);
}


/**
* Compare two 0-terminated strings, ignoring case
*
Expand Down
15 changes: 10 additions & 5 deletions src/sdp/msg.c
Expand Up @@ -430,13 +430,18 @@ static int media_encode(const struct sdp_media *m, struct mbuf *mb, bool offer)
if (!fmt->sup && !offer)
continue;

err |= mbuf_printf(mb, "a=rtpmap:%s %s/%u",
fmt->id, fmt->name, fmt->srate);
if ((str_ncmp(m->proto, "RTP/", 4) == 0) ||
(str_str(m->proto, "/RTP/") != NULL)) {

if (fmt->ch > 1)
err |= mbuf_printf(mb, "/%u", fmt->ch);
err |= mbuf_printf(mb, "a=rtpmap:%s %s/%u",
fmt->id, fmt->name, fmt->srate);

err |= mbuf_printf(mb, "\r\n");
if (fmt->ch > 1)
err |= mbuf_printf(mb, "/%u", fmt->ch);

err |= mbuf_printf(mb, "\r\n");

}

if (str_isset(fmt->params))
err |= mbuf_printf(mb, "a=fmtp:%s %s\r\n",
Expand Down

0 comments on commit c34429a

Please sign in to comment.