libports: add SDL_net

Fixes #936.
This commit is contained in:
Josef Söntgen 2013-10-22 23:35:05 +02:00 committed by Norman Feske
parent 1a22664fee
commit 1306915879
6 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,12 @@
include $(REP_DIR)/ports/sdl_net.inc
SDL_NET_DIR = $(REP_DIR)/contrib/$(SDL_NET)
SRC_C = $(notdir $(wildcard $(SDL_NET_DIR)/SDLnet*.c))
vpath %.c $(SDL_NET_DIR)
INC_DIR += $(SDL_NET_DIR)
LIBS += libc sdl
SHARED_LIB = yes

View File

@ -0,0 +1,2 @@
SDL_NET_VERSION = 1.2.8
SDL_NET = SDL_net-$(SDL_NET_VERSION)

42
libports/ports/sdl_net.mk Normal file
View File

@ -0,0 +1,42 @@
include ports/sdl_net.inc
SDL_NET_TGZ = $(SDL_NET).tar.gz
SDL_NET_URL = http://www.libsdl.org/projects/SDL_net/release/$(SDL_NET_TGZ)
#
# Interface to top-level prepare Makefile
#
# Register SDL_net port as lower case to be consistent with the
# other libraries.
#
PORTS += sdl_net-$(SDL_NET_VERSION)
prepare-sdl_net: $(CONTRIB_DIR)/$(SDL_NET) include/SDL/SDL_net.h
$(CONTRIB_DIR)/$(SDL_NET): clean-sdl_net
#
# Port-specific local rules
#
$(DOWNLOAD_DIR)/$(SDL_NET_TGZ):
$(VERBOSE)wget -c -P $(DOWNLOAD_DIR) $(SDL_NET_URL) && touch $@
$(CONTRIB_DIR)/$(SDL_NET): $(DOWNLOAD_DIR)/$(SDL_NET_TGZ)
$(VERBOSE)tar xfz $< \
--exclude Xcode --exclude VisualC --exclude Xcode-iOS \
--exclude VisualCE --exclude Watcom-OS2.zip --exclude debian \
-C $(CONTRIB_DIR) && touch $@
$(VERBOSE)patch -N -p0 < src/lib/sdl_net/SDLnet.patch
$(VERBOSE)patch -N -p0 < src/lib/sdl_net/SDL_net.h.patch
#
# Install SDL_net headers
#
include/SDL/SDL_net.h:
$(VERBOSE)mkdir -p $(dir $@)
$(VERBOSE)ln -fs ../../$(CONTRIB_DIR)/$(SDL_NET)/SDL_net.h include/SDL/
clean-sdl_net:
$(VERBOSE)rm -rf include/SDL/SDL_net.h
$(VERBOSE)rmdir include/SDL 2>/dev/null || true
$(VERBOSE)rm -rf $(CONTRIB_DIR)/$(SDL_NET)

View File

@ -0,0 +1,16 @@
--- contrib/SDL_net-1.2.8/SDL_net.h.orig 2013-10-30 15:17:11.391825241 +0100
+++ contrib/SDL_net-1.2.8/SDL_net.h 2013-10-30 15:17:55.108447538 +0100
@@ -350,6 +350,13 @@
extern no_parse_DECLSPEC char * SDLCALL SDLNet_GetError(void);
*/
+#ifdef __cplusplus
+#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
+#define SDL_static_cast(type, expression) static_cast<type>(expression)
+#else
+#define SDL_reinterpret_cast(type, expression) ((type)(expression))
+#define SDL_static_cast(type, expression) ((type)(expression))
+#endif
/* Inline macro functions to read/write network data */

View File

@ -0,0 +1,38 @@
--- contrib/SDL_net-1.2.8/SDLnet.c.orig 2013-10-22 23:17:40.135873087 +0200
+++ contrib/SDL_net-1.2.8/SDLnet.c 2013-10-22 23:28:28.845485683 +0200
@@ -122,11 +122,11 @@
} else {
address->host = inet_addr(host);
if ( address->host == INADDR_NONE ) {
- struct hostent *hp;
+ struct addrinfo *ai;
- hp = gethostbyname(host);
- if ( hp ) {
- memcpy(&address->host,hp->h_addr,hp->h_length);
+ retval = getaddrinfo(host, NULL, NULL, &ai);
+ if ( retval == 0 ) {
+ memcpy(&address->host,ai->ai_addr,ai->ai_addrlen);
} else {
retval = -1;
}
@@ -149,12 +149,15 @@
*/
const char *SDLNet_ResolveIP(const IPaddress *ip)
{
- struct hostent *hp;
+ static char host[256];
struct in_addr in;
+ int err;
- hp = gethostbyaddr((const char *)&ip->host, sizeof(ip->host), AF_INET);
- if ( hp != NULL ) {
- return hp->h_name;
+ err = getnameinfo((const struct sockaddr*) &ip->host,
+ sizeof (struct sockaddr), host, sizeof (host),
+ NULL, 0, 0);
+ if ( err == 0 ) {
+ return host;
}
in.s_addr = ip->host;

View File

@ -0,0 +1,5 @@
TARGET = test-sdl_net
LIBS = libc sdl_net
SRC_CC = main.cc
vpath main.cc $(PRG_DIR)/..