From dab475dab7352176a585dd4e432af6d4d60f763b Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 30 Jul 2012 14:17:42 +0200 Subject: [PATCH] Parameter to force hostname resolving into IPv6 Currently hostnames are resloved into IPv4 addresses by default. --- src/audio/audio.c | 14 ++++++++------ src/audio/audio.h | 2 +- src/main.c | 31 ++++++++++++++++++++++++------- src/rtp/net_udp.c | 8 ++++---- src/rtp/net_udp.h | 4 ++-- src/rtp/rtp.c | 12 +++++++----- src/rtp/rtp.h | 12 ++++++++++-- 7 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/audio/audio.c b/src/audio/audio.c index acce2a258..9bcb9ef10 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -120,7 +120,8 @@ typedef void (*audio_device_help_t)(void); static void *audio_sender_thread(void *arg); static void *audio_receiver_thread(void *arg); -static struct rtp *initialize_audio_network(char *addr, int recv_port, int send_port, struct pdb *participants); +static struct rtp *initialize_audio_network(char *addr, int recv_port, + int send_port, struct pdb *participants, bool use_ipv6); static void audio_channel_map_usage(void); static void audio_scale_usage(void); @@ -158,7 +159,7 @@ static void audio_scale_usage(void) */ struct state_audio * audio_cfg_init(char *addrs, int recv_port, int send_port, char *send_cfg, char *recv_cfg, char *jack_cfg, char *fec_cfg, char *audio_channel_map, const char *audio_scale, - bool echo_cancellation) + bool echo_cancellation, bool use_ipv6) { struct state_audio *s = NULL; char *tmp, *unused = NULL; @@ -226,8 +227,8 @@ struct state_audio * audio_cfg_init(char *addrs, int recv_port, int send_port, c addr = strtok_r(tmp, ",", &unused); if ((s->audio_network_device = initialize_audio_network(addr, recv_port, send_port, - s->audio_participants)) == - NULL) { + s->audio_participants, use_ipv6)) == + NULL) { printf("Unable to open audio network\n"); goto error; } @@ -342,13 +343,14 @@ void audio_done(struct state_audio *s) } } -static struct rtp *initialize_audio_network(char *addr, int recv_port, int send_port, struct pdb *participants) // GiX +static struct rtp *initialize_audio_network(char *addr, int recv_port, + int send_port, struct pdb *participants, bool use_ipv6) // GiX { struct rtp *r; double rtcp_bw = 1024 * 512; // FIXME: something about 5% for rtcp is said in rfc r = rtp_init(addr, recv_port, send_port, 255, rtcp_bw, FALSE, rtp_recv_callback, - (void *)participants); + (void *)participants, use_ipv6); if (r != NULL) { pdb_add(participants, rtp_my_ssrc(r)); rtp_set_option(r, RTP_OPT_WEAK_VALIDATION, TRUE); diff --git a/src/audio/audio.h b/src/audio/audio.h index b8c297b1a..0c34896b0 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -72,7 +72,7 @@ audio_frame; struct state_audio * audio_cfg_init(char *addrs, int recv_port, int send_port, char *send_cfg, char *recv_cfg, char *jack_cfg, char *fec_cfg, char *audio_channel_map, const char *audio_scale, - bool echo_cancellation); + bool echo_cancellation, bool use_ipv6); void audio_finish(struct state_audio *s); void audio_done(struct state_audio *s); void audio_join(struct state_audio *s); diff --git a/src/main.c b/src/main.c index fdc259c20..0b745d027 100644 --- a/src/main.c +++ b/src/main.c @@ -171,6 +171,12 @@ int uv_argc; char **uv_argv; static struct state_uv *uv_state; +// +// prototypes +// +static struct rtp **initialize_network(char *addrs, int recv_port_base, + int send_port_base, struct pdb *participants, bool use_ipv6); + void list_video_display_devices(void); void list_video_capture_devices(void); struct display *initialize_video_display(const char *requested_display, @@ -221,7 +227,7 @@ static void usage(void) /* TODO -c -p -b are deprecated options */ printf("\nUsage: uv [-d ] [-t ] [-r ]\n"); printf(" [-s ] [-l ] " - "[-m ] [-c] [-i]\n"); + "[-m ] [-c] [-i] [-6]\n"); printf(" [-M ] [-p ] " "[-f ] [-P ]\n"); printf(" address(es)\n\n"); @@ -237,6 +243,10 @@ static void usage(void) printf("\n"); printf("\t-i \tiHDTV compatibility mode\n"); printf("\n"); +#ifdef HAVE_IPv6 + printf("\t-6 \tUse IPv6\n"); + printf("\n"); +#endif // HAVE_IPv6 printf("\t-r \tAudio playback device (see '-r help')\n"); printf("\n"); printf("\t-s \tAudio capture device (see '-s help')\n"); @@ -403,7 +413,8 @@ static void display_buf_increase_warning(int size) } -static struct rtp **initialize_network(char *addrs, int recv_port_base, int send_port_base, struct pdb *participants) +static struct rtp **initialize_network(char *addrs, int recv_port_base, + int send_port_base, struct pdb *participants, bool use_ipv6) { struct rtp **devices = NULL; double rtcp_bw = 5 * 1024 * 1024; /* FIXME */ @@ -442,7 +453,7 @@ static struct rtp **initialize_network(char *addrs, int recv_port_base, int send devices[index] = rtp_init(addr, recv_port, send_port, ttl, rtcp_bw, FALSE, rtp_recv_callback, - (void *)participants); + (void *)participants, use_ipv6); if (devices[index] != NULL) { rtp_set_option(devices[index], RTP_OPT_WEAK_VALIDATION, TRUE); @@ -849,6 +860,7 @@ int main(int argc, char *argv[]) char *audio_scale = "mixauto"; bool echo_cancellation = false; + bool use_ipv6 = false; int bitrate = 0; @@ -877,6 +889,7 @@ int main(int argc, char *argv[]) {"display", required_argument, 0, 'd'}, {"capture", required_argument, 0, 't'}, {"mtu", required_argument, 0, 'm'}, + {"ipv6", no_argument, 0, '6'}, {"mode", required_argument, 0, 'M'}, {"version", no_argument, 0, 'v'}, {"compress", required_argument, 0, 'c'}, @@ -934,7 +947,7 @@ int main(int argc, char *argv[]) init_lib_common(); while ((ch = - getopt_long(argc, argv, "d:t:m:r:s:vc:ihj:M:p:f:P:l:", getopt_options, + getopt_long(argc, argv, "d:t:m:r:s:v6c:ihj:M:p:f:P:l:", getopt_options, &option_index)) != -1) { switch (ch) { case 'd': @@ -1013,7 +1026,9 @@ int main(int argc, char *argv[]) return EXIT_FAIL_USAGE; } break; - + case '6': + use_ipv6 = true; + break; case '?': break; case AUDIO_CHANNEL_MAP: @@ -1090,7 +1105,7 @@ int main(int argc, char *argv[]) char *tmp_requested_fec = strdup(DEFAULT_AUDIO_FEC); uv->audio = audio_cfg_init (network_device, uv->recv_port_number + 2, uv->send_port_number + 2, audio_send, audio_recv, jack_cfg, - tmp_requested_fec, audio_channel_map, audio_scale, echo_cancellation); + tmp_requested_fec, audio_channel_map, audio_scale, echo_cancellation, use_ipv6); free(tmp_requested_fec); if(!uv->audio) goto cleanup; @@ -1210,7 +1225,9 @@ int main(int argc, char *argv[]) sleep(1); } else { if ((uv->network_devices = - initialize_network(network_device, uv->recv_port_number, uv->send_port_number, uv->participants)) == NULL) { + initialize_network(network_device, uv->recv_port_number, + uv->send_port_number, uv->participants, use_ipv6)) + == NULL) { printf("Unable to open network\n"); exit_uv(EXIT_FAIL_NETWORK); goto cleanup_wait_display; diff --git a/src/rtp/net_udp.c b/src/rtp/net_udp.c index 496843b1f..cfcb372ac 100644 --- a/src/rtp/net_udp.c +++ b/src/rtp/net_udp.c @@ -818,9 +818,9 @@ int udp_addr_valid(const char *addr) * Returns: a pointer to a valid socket_udp structure on success, NULL otherwise. **/ socket_udp *udp_init(const char *addr, uint16_t rx_port, uint16_t tx_port, - int ttl) + int ttl, bool use_ipv6) { - return udp_init_if(addr, NULL, rx_port, tx_port, ttl); + return udp_init_if(addr, NULL, rx_port, tx_port, ttl, use_ipv6); } /** @@ -838,11 +838,11 @@ socket_udp *udp_init(const char *addr, uint16_t rx_port, uint16_t tx_port, * Return value: a pointer to a socket_udp structure on success, NULL otherwise. **/ socket_udp *udp_init_if(const char *addr, const char *iface, uint16_t rx_port, - uint16_t tx_port, int ttl) + uint16_t tx_port, int ttl, bool use_ipv6) { socket_udp *res; - if (strchr(addr, ':') == NULL) { + if (strchr(addr, ':') == NULL && !use_ipv6) { res = udp_init4(addr, iface, rx_port, tx_port, ttl); } else { res = udp_init6(addr, iface, rx_port, tx_port, ttl); diff --git a/src/rtp/net_udp.h b/src/rtp/net_udp.h index 3fc518939..3083220d4 100644 --- a/src/rtp/net_udp.h +++ b/src/rtp/net_udp.h @@ -46,8 +46,8 @@ extern "C" { #endif int udp_addr_valid(const char *addr); -socket_udp *udp_init(const char *addr, uint16_t rx_port, uint16_t tx_port, int ttl); -socket_udp *udp_init_if(const char *addr, const char *iface, uint16_t rx_port, uint16_t tx_port, int ttl); +socket_udp *udp_init(const char *addr, uint16_t rx_port, uint16_t tx_port, int ttl, bool use_ipv6); +socket_udp *udp_init_if(const char *addr, const char *iface, uint16_t rx_port, uint16_t tx_port, int ttl, bool use_ipv6); void udp_exit(socket_udp *s); int udp_peek(socket_udp *s, char *buffer, int buflen); diff --git a/src/rtp/rtp.c b/src/rtp/rtp.c index 9f41efe78..38856b0c7 100644 --- a/src/rtp/rtp.c +++ b/src/rtp/rtp.c @@ -1009,10 +1009,11 @@ static void init_rng(const char *s) struct rtp *rtp_init(const char *addr, uint16_t rx_port, uint16_t tx_port, int ttl, double rtcp_bw, - int tfrc_on, rtp_callback callback, uint8_t * userdata) + int tfrc_on, rtp_callback callback, uint8_t * userdata, + bool use_ipv6) { return rtp_init_if(addr, NULL, rx_port, tx_port, ttl, rtcp_bw, tfrc_on, - callback, userdata); + callback, userdata, use_ipv6); } /** @@ -1041,7 +1042,8 @@ struct rtp *rtp_init(const char *addr, struct rtp *rtp_init_if(const char *addr, char *iface, uint16_t rx_port, uint16_t tx_port, int ttl, double rtcp_bw, - int tfrc_on, rtp_callback callback, uint8_t * userdata) + int tfrc_on, rtp_callback callback, uint8_t * userdata, + bool use_ipv6) { struct rtp *session; int i, j; @@ -1070,10 +1072,10 @@ struct rtp *rtp_init_if(const char *addr, char *iface, session->rx_port = rx_port; session->tx_port = tx_port; session->ttl = min(ttl, 127); - session->rtp_socket = udp_init_if(addr, iface, rx_port, tx_port, ttl); + session->rtp_socket = udp_init_if(addr, iface, rx_port, tx_port, ttl, use_ipv6); session->rtcp_socket = udp_init_if(addr, iface, (uint16_t) (rx_port + 1), - (uint16_t) (tx_port + 1), ttl); + (uint16_t) (tx_port + 1), ttl, use_ipv6); init_opt(session); diff --git a/src/rtp/rtp.h b/src/rtp/rtp.h index 72d7babf8..f1eef8305 100644 --- a/src/rtp/rtp.h +++ b/src/rtp/rtp.h @@ -40,6 +40,12 @@ #ifndef __RTP_H__ #define __RTP_H__ +#ifdef HAVE_CONFIG_H +#include "config.h" // bool +#include "config_unix.h" +#include "config_win32.h" +#endif // HAVE_CONFIG_H + #define RTP_VERSION 2 #define RTP_PACKET_HEADER_SIZE ((sizeof(char *) * 2) + sizeof(uint32_t *) + (2 * sizeof(int))) #define RTP_MAX_PACKET_LEN 9000 @@ -206,13 +212,15 @@ rtp_t rtp_init(const char *addr, int ttl, double rtcp_bw, int tfrc_on, rtp_callback callback, - uint8_t *userdata); + uint8_t *userdata, + bool use_ipv6); rtp_t rtp_init_if(const char *addr, char *iface, uint16_t rx_port, uint16_t tx_port, int ttl, double rtcp_bw, int tfrc_on, rtp_callback callback, - uint8_t *userdata); + uint8_t *userdata, + bool use_ipv6); void rtp_send_bye(struct rtp *session); void rtp_done(struct rtp *session);