Skip to content

Commit

Permalink
fix IPv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
abrasive committed Apr 2, 2013
1 parent e6e95a2 commit 4a752e6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
11 changes: 11 additions & 0 deletions common.h
Expand Up @@ -3,8 +3,19 @@

#include <openssl/rsa.h>
#include <stdint.h>
#include <sys/socket.h>
#include "audio.h"

// struct sockaddr_in6 is bigger than struct sockaddr. derp
#ifdef AF_INET6
#define SOCKADDR struct sockaddr_storage
#define SAFAMILY ss_family
#else
#define SOCKADDR struct sockaddr
#define SAFAMILY sa_family
#endif


typedef struct {
char *password;
char *apname;
Expand Down
20 changes: 10 additions & 10 deletions rtp.c
Expand Up @@ -37,7 +37,7 @@
static int running = 0;
static int please_shutdown;

static struct sockaddr rtp_client;
static SOCKADDR rtp_client;
static int sock;
static pthread_t rtp_thread;

Expand Down Expand Up @@ -86,11 +86,11 @@ static void *rtp_receiver(void *arg) {
return NULL;
}

static int bind_port(struct sockaddr *remote) {
static int bind_port(SOCKADDR *remote) {
struct addrinfo hints, *info;

memset(&hints, 0, sizeof(hints));
hints.ai_family = remote->sa_family;
hints.ai_family = remote->SAFAMILY;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE;

Expand All @@ -99,18 +99,18 @@ static int bind_port(struct sockaddr *remote) {
if (ret < 0)
die("failed to get usable addrinfo?! %s", gai_strerror(ret));

sock = socket(remote->sa_family, SOCK_DGRAM, IPPROTO_UDP);
sock = socket(remote->SAFAMILY, SOCK_DGRAM, IPPROTO_UDP);
ret = bind(sock, info->ai_addr, info->ai_addrlen);

if (ret < 0)
die("could not bind a UDP port!");

int sport;
struct sockaddr local;
SOCKADDR local;
socklen_t local_len = sizeof(local);
getsockname(sock, &local, &local_len);
getsockname(sock, (struct sockaddr*)&local, &local_len);
#ifdef AF_INET6
if (local.sa_family == AF_INET6) {
if (local.SAFAMILY == AF_INET6) {
struct sockaddr_in6 *sa6 = (struct sockaddr_in6*)&local;
sport = htons(sa6->sin6_port);
} else
Expand All @@ -124,7 +124,7 @@ static int bind_port(struct sockaddr *remote) {
}


int rtp_setup(struct sockaddr *remote, int cport, int tport) {
int rtp_setup(SOCKADDR *remote, int cport, int tport) {
if (running)
die("rtp_setup called with active stream!\n");

Expand All @@ -135,7 +135,7 @@ int rtp_setup(struct sockaddr *remote, int cport, int tport) {

memcpy(&rtp_client, remote, sizeof(rtp_client));
#ifdef AF_INET6
if (rtp_client.sa_family == AF_INET6) {
if (rtp_client.SAFAMILY == AF_INET6) {
struct sockaddr_in6 *sa6 = (struct sockaddr_in6*)&rtp_client;
sa6->sin6_port = htons(cport);
} else
Expand Down Expand Up @@ -179,5 +179,5 @@ void rtp_request_resend(seq_t first, seq_t last) {
*(unsigned short *)(req+4) = htons(first); // missed seqnum
*(unsigned short *)(req+6) = htons(last-first+1); // count

sendto(sock, req, sizeof(req), 0, &rtp_client, sizeof(rtp_client));
sendto(sock, req, sizeof(req), 0, (struct sockaddr*)&rtp_client, sizeof(rtp_client));
}
2 changes: 1 addition & 1 deletion rtp.h
Expand Up @@ -3,7 +3,7 @@

#include <sys/socket.h>

int rtp_setup(struct sockaddr *remote, int controlport, int timingport);
int rtp_setup(SOCKADDR *remote, int controlport, int timingport);
void rtp_shutdown(void);
void rtp_request_resend(seq_t first, seq_t last);

Expand Down
8 changes: 4 additions & 4 deletions rtsp.c
Expand Up @@ -52,7 +52,7 @@ static pthread_t playing_thread = 0;

typedef struct {
stream_cfg stream;
struct sockaddr remote;
SOCKADDR remote;
} rtsp_conn_info;

static inline int rtsp_playing(void) {
Expand Down Expand Up @@ -450,9 +450,9 @@ static void apple_challenge(int fd, rtsp_message *req, rtsp_message *resp) {
if (!hdr)
return;

struct sockaddr fdsa;
SOCKADDR fdsa;
socklen_t sa_len = sizeof(fdsa);
getsockname(fd, &fdsa, &sa_len);
getsockname(fd, (struct sockaddr*)&fdsa, &sa_len);

int chall_len;
uint8_t *chall = base64_dec(hdr, &chall_len);
Expand All @@ -470,7 +470,7 @@ static void apple_challenge(int fd, rtsp_message *req, rtsp_message *resp) {
bp += chall_len;

#ifdef AF_INET6
if (fdsa.sa_family == AF_INET6) {
if (fdsa.SAFAMILY == AF_INET6) {
struct sockaddr_in6 *sa6 = (struct sockaddr_in6*)(&fdsa);
memcpy(bp, sa6->sin6_addr.s6_addr, 16);
bp += 16;
Expand Down

0 comments on commit 4a752e6

Please sign in to comment.