Compile DIAL client and server for macOS.

Changes:
* Added method to get mac and ip address for OSX. Current Linux method
of query via SIOCGIFCONF doesn't work. Added code to read via getifaddrs() API.
* Put non OSX specific code under #ifdef flags.
* Removed few linker libraries which are not required (lcares and lrt).
* Fixed many warnings.

Tested on: OSX 10.12
This commit is contained in:
Chintan Parikh
2017-12-26 14:20:12 -08:00
parent fc267fac62
commit ac3e488924
11 changed files with 55 additions and 14 deletions

View File

@@ -65,7 +65,6 @@ public:
string &outputFile ); string &outputFile );
private: private:
DialConformance(); DialConformance();
DialServer* _pServer;
static DialConformance* sConformance; static DialConformance* sConformance;
DialClientInput _input; DialClientInput _input;

View File

@@ -28,6 +28,7 @@
#include "DialServer.h" #include "DialServer.h"
#include <map> #include <map>
#include <pthread.h>
using namespace std; using namespace std;
@@ -82,9 +83,6 @@ private:
void cleanServerList(); void cleanServerList();
void resetDiscovery(); void resetDiscovery();
pthread_t _mcastThread;
pthread_t _responseThread;
typedef map<string, DialServer*> ServerMap; typedef map<string, DialServer*> ServerMap;
ServerMap mServerMap; ServerMap mServerMap;

View File

@@ -226,7 +226,7 @@ int DialServer::getStatus(
if (!status) return 0; if (!status) return 0;
ATRACE("Body: %s\n", responseBody.c_str()); ATRACE("Body: %s\n", responseBody.c_str());
unsigned found = responseBody.find("href="); size_t found = responseBody.find("href=");
if( found != string::npos ) if( found != string::npos )
{ {
// The start of href is after href= and the quote // The start of href is after href= and the quote

View File

@@ -136,7 +136,7 @@ static void runConformance()
else else
{ {
printf("DIAL server not found\n"); printf("DIAL server not found\n");
printf("%Zu available server(s): \n", list.size()); printf("%zu available server(s): \n", list.size());
printServerList(list); printServerList(list);
} }
} }

View File

@@ -8,7 +8,7 @@ OBJS := main.cpp DialServer.cpp DialDiscovery.cpp DialConformance.cpp DialClient
# You may not need all these libraries. This example uses a build of curl that needs crypto, ssl, cares, and zlib # You may not need all these libraries. This example uses a build of curl that needs crypto, ssl, cares, and zlib
dialclient: $(OBJS) ${includes} dialclient: $(OBJS) ${includes}
$(CC) -Wall -Werror -g $(OBJS) $(INCLUDES) $(LDFLAGS) -ldl -lpthread -lcurl -lz -lcrypto -lssl -lcares -o dialclient $(CC) -Wall -Werror -g $(OBJS) $(INCLUDES) $(LDFLAGS) -ldl -lpthread -lcurl -lz -lcrypto -lssl -o dialclient
dialclient_debug: $(OBJS) ${includes} dialclient_debug: $(OBJS) ${includes}
$(CC) -DDEBUG -Wall -Werror -g $(OBJS) $(INCLUDES) $(LDFLAGS) -ldl -lpthread -lcurl -lz -lcrypto -lssl -lcares -o dialclient_debug $(CC) -DDEBUG -Wall -Werror -g $(OBJS) $(INCLUDES) $(LDFLAGS) -ldl -lpthread -lcurl -lz -lcrypto -lssl -lcares -o dialclient_debug

View File

@@ -77,3 +77,4 @@ NetInterface getDefaultNetworkInterfaces()
} }
return defaultNet; return defaultNet;
} }

View File

@@ -1,10 +1,13 @@
#ifndef LINUXINTERFACES_H_ #ifndef LINUXINTERFACES_H_
#define LINUXINTERFACES_H_ #define LINUXINTERFACES_H_
#include <arpa/inet.h> #ifndef __APPLE__
#include <dirent.h>
#include <linux/limits.h> #include <linux/limits.h>
#include <linux/wireless.h> #include <linux/wireless.h>
#endif
#include <arpa/inet.h>
#include <dirent.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>

View File

@@ -3,7 +3,7 @@ CC=$(TARGET)gcc
.PHONY: clean .PHONY: clean
.DEFAULT_GOAL=all .DEFAULT_GOAL=all
OBJS := main.o dial_server.o mongoose.o quick_ssdp.o url_lib.o dial_data.o LinuxInterfaces.o OBJS := main.o dial_server.o mongoose.o quick_ssdp.o url_lib.o dial_data.o
HEADERS := $(wildcard *.h) HEADERS := $(wildcard *.h)
%.c: $(HEADERS) %.c: $(HEADERS)
@@ -15,10 +15,12 @@ HEADERS := $(wildcard *.h)
all: dialserver test all: dialserver test
nf_callbacks_lib: nf_callbacks.o nf_callbacks_lib: nf_callbacks.o
$(CC) -Wall -Werror -g nf_callbacks.o -o libnfCallbacks.so --shared # $(CC) -Wall -Werror -g nf_callbacks.o -o libnfCallbacks.so --shared
$(CC) -Wall -Werror -Wl,-undefined -Wl,dynamic_lookup -g nf_callbacks.o -o libnfCallbacks.so --shared
dialserver: nf_callbacks_lib $(OBJS) dialserver: nf_callbacks_lib $(OBJS)
$(CC) -Wall -Werror -Wl,-rpath,. -g $(OBJS) -ldl -lpthread -lrt -L. -lnfCallbacks -o dialserver $(CC) -Wall -Werror -Wl,-rpath,. -g $(OBJS) -ldl -lpthread -L. -lnfCallbacks -o dialserver
test: test:
make -C tests make -C tests

View File

@@ -800,7 +800,9 @@ static void worker_thread(struct mg_context *ctx) {
// required in the DIAL specification. // required in the DIAL specification.
int buf_size = MAX_REQUEST_SIZE; int buf_size = MAX_REQUEST_SIZE;
#ifndef __APPLE__
pthread_setname_np( pthread_self(), __func__); pthread_setname_np( pthread_self(), __func__);
#endif
conn = (struct mg_connection *) calloc(1, sizeof(*conn) + buf_size); conn = (struct mg_connection *) calloc(1, sizeof(*conn) + buf_size);
conn->buf_size = buf_size; conn->buf_size = buf_size;
conn->buf = (char *) (conn + 1); conn->buf = (char *) (conn + 1);
@@ -860,7 +862,9 @@ static void produce_socket(struct mg_context *ctx, const struct socket *sp) {
static void master_thread(struct mg_context *ctx) { static void master_thread(struct mg_context *ctx) {
struct socket accepted; struct socket accepted;
#ifndef __APPLE__
pthread_setname_np( pthread_self(), __func__); pthread_setname_np( pthread_self(), __func__);
#endif
socklen_t sock_len = sizeof(accepted.local_addr); socklen_t sock_len = sizeof(accepted.local_addr);
memcpy(&accepted.local_addr, &ctx->local_address, sock_len); memcpy(&accepted.local_addr, &ctx->local_address, sock_len);

View File

@@ -8,6 +8,7 @@
#include <regex.h> #include <regex.h>
#include "dial_server.h" #include "dial_server.h"
#include "url_lib.h" #include "url_lib.h"
#include "nf_callbacks.h"
extern char *spAppNetflix; extern char *spAppNetflix;
extern char spNetflix[]; extern char spNetflix[];

View File

@@ -35,6 +35,13 @@
#include "mongoose.h" #include "mongoose.h"
#include <stdbool.h> #include <stdbool.h>
#ifdef __APPLE__
#include <ifaddrs.h>
#include <net/if.h>
#include <net/if_dl.h>
#endif
// TODO: Partners should define this port // TODO: Partners should define this port
#define SSDP_PORT (56790) #define SSDP_PORT (56790)
static char gBuf[4096]; static char gBuf[4096];
@@ -108,6 +115,30 @@ static void *request_handler(enum mg_event event,
return NULL; return NULL;
} }
#ifdef __APPLE__
static void get_local_address() {
struct ifaddrs* iflist;
char *if_name= "en0";
char buf[INET6_ADDRSTRLEN];
if (getifaddrs(&iflist) == 0) {
for (struct ifaddrs* cur = iflist; cur; cur = cur->ifa_next) {
if (strcmp(cur->ifa_name, if_name) == 0) {
if ((cur->ifa_addr->sa_family == AF_LINK) && cur->ifa_addr) {
struct sockaddr_dl* sdl = (struct sockaddr_dl*)cur->ifa_addr;
memcpy(hw_addr, LLADDR(sdl), sdl->sdl_alen);
}
if (cur->ifa_addr->sa_family == AF_INET) {
void *tmp = &((struct sockaddr_in *)cur->ifa_addr)->sin_addr;
strcpy(ip_addr, inet_ntop(cur->ifa_addr->sa_family, tmp, buf, sizeof(buf)));
}
}
}
freeifaddrs(iflist);
}
}
#else
static void get_local_address() { static void get_local_address() {
struct ifconf ifc; struct ifconf ifc;
char buf[4096]; char buf[4096];
@@ -152,6 +183,7 @@ static void get_local_address() {
} }
close(s); close(s);
} }
#endif
static void handle_mcast() { static void handle_mcast() {
int s, one = 1, bytes; int s, one = 1, bytes;
@@ -174,8 +206,9 @@ static void handle_mcast() {
exit(1); exit(1);
} }
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = inet_addr("239.255.255.250"); saddr.sin_addr.s_addr = INADDR_ANY; //inet_addr("239.255.255.250");
saddr.sin_port = htons(1900); saddr.sin_port = htons(1900);
if (-1 == bind(s, (struct sockaddr *)&saddr, sizeof(saddr))) { if (-1 == bind(s, (struct sockaddr *)&saddr, sizeof(saddr))) {
perror("bind"); perror("bind");
exit(1); exit(1);