From 7c2d0d03d2bb8f2105e5ebafc75e63c2b83e5df5 Mon Sep 17 00:00:00 2001 From: Richard Aas Date: Tue, 9 Dec 2014 08:48:52 +0000 Subject: [PATCH] stun/dtls: adding stun_transp_name() and dtls_udp_sock() functions --- include/re_stun.h | 1 + include/re_tls.h | 1 + src/stun/stunstr.c | 19 +++++++++++++++++++ src/tls/openssl/tls_udp.c | 13 +++++++++++++ 4 files changed, 34 insertions(+) diff --git a/include/re_stun.h b/include/re_stun.h index cc645cc..4b8092a 100644 --- a/include/re_stun.h +++ b/include/re_stun.h @@ -225,6 +225,7 @@ void stun_msg_dump(const struct stun_msg *msg); const char *stun_class_name(uint16_t cls); const char *stun_method_name(uint16_t method); const char *stun_attr_name(uint16_t type); +const char *stun_transp_name(enum stun_transp tp); /* DNS Discovery of a STUN Server */ diff --git a/include/re_tls.h b/include/re_tls.h index d9d63e4..ed8f29d 100644 --- a/include/re_tls.h +++ b/include/re_tls.h @@ -60,6 +60,7 @@ struct dtls_sock; int dtls_listen(struct dtls_sock **sockp, const struct sa *laddr, struct udp_sock *us, uint32_t htsize, int layer, dtls_conn_h *connh, void *arg); +struct udp_sock *dtls_udp_sock(struct dtls_sock *sock); int dtls_connect(struct tls_conn **ptc, struct tls *tls, struct dtls_sock *sock, const struct sa *peer, dtls_estab_h *estabh, dtls_recv_h *recvh, diff --git a/src/stun/stunstr.c b/src/stun/stunstr.c index eaa4970..2d0de09 100644 --- a/src/stun/stunstr.c +++ b/src/stun/stunstr.c @@ -25,3 +25,22 @@ const char *stun_reason_443 = "Peer Address Family Mismatch"; const char *stun_reason_486 = "Allocation Quota Reached"; const char *stun_reason_500 = "Server Error"; const char *stun_reason_508 = "Insufficient Capacity"; + + +/** + * Get the name of a given STUN Transport + * + * @param tp STUN Transport + * + * @return Name of the corresponding STUN Transport + */ +const char *stun_transp_name(enum stun_transp tp) +{ + switch (tp) { + + case STUN_TRANSP_UDP: return "UDP"; + case STUN_TRANSP_TCP: return "TCP"; + case STUN_TRANSP_DTLS: return "DTLS"; + default: return "???"; + } +} diff --git a/src/tls/openssl/tls_udp.c b/src/tls/openssl/tls_udp.c index 6d72120..67a13e4 100644 --- a/src/tls/openssl/tls_udp.c +++ b/src/tls/openssl/tls_udp.c @@ -715,3 +715,16 @@ int dtls_listen(struct dtls_sock **sockp, const struct sa *laddr, return err; } + + +/** + * Get the underlying UDP socket of a DTLS Socket + * + * @param sock DTLS Socket + * + * @return UDP Socket + */ +struct udp_sock *dtls_udp_sock(struct dtls_sock *sock) +{ + return sock ? sock->us : NULL; +}