project_files/Android-build/SDL-android-project/jni/sdl_net/SDLnet.c
author Xeli
Thu, 23 Jun 2011 14:30:04 +0200
branchhedgeroid
changeset 5317 86984c1034a5
permissions -rw-r--r--
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5317
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     1
/*
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     2
    SDL_net:  An example cross-platform network library for use with SDL
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     3
    Copyright (C) 1997-2004 Sam Lantinga
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     4
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     6
    modify it under the terms of the GNU Library General Public
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     8
    version 2 of the License, or (at your option) any later version.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     9
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    13
    Library General Public License for more details.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    14
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    15
    You should have received a copy of the GNU Library General Public
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    16
    License along with this library; if not, write to the Free
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    18
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    19
    Sam Lantinga
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    20
    slouken@libsdl.org
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    21
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    22
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    23
/* $Id: SDLnet.c 2207 2006-04-20 16:48:25Z slouken $ */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    24
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    25
#include <string.h>
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    26
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    27
#include "SDL_endian.h"
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    28
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    29
#include "SDLnetsys.h"
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    30
#include "SDL_net.h"
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    31
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    32
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    33
const SDL_version *SDLNet_Linked_Version(void)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    34
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    35
	static SDL_version linked_version;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    36
	SDL_NET_VERSION(&linked_version);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    37
	return(&linked_version);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    38
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    39
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    40
/* Since the UNIX/Win32/BeOS code is so different from MacOS,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    41
   we'll just have two completely different sections here.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    42
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    43
static int SDLNet_started = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    44
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    45
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    46
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    47
#include <Events.h>
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    48
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    49
typedef struct
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    50
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    51
	Uint8	stat;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    52
	InetSvcRef dns;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    53
}DNSStatus, *DNSStatusRef;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    54
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    55
enum
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    56
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    57
	dnsNotReady = 0,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    58
	dnsReady = 1,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    59
	dnsResolved = 2,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    60
	dnsError = 255
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    61
};
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    62
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    63
//static InetSvcRef dns = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    64
static DNSStatus dnsStatus;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    65
Uint32 OTlocalhost = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    66
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    67
/* We need a notifier for opening DNS.*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    68
/* ( 010311 masahiro minami<elsur@aaa.letter.co.jp>) */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    69
static pascal void OpenDNSNotifier(
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    70
	void* context, OTEventCode code, OTResult result, void* cookie )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    71
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    72
	switch( code )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    73
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    74
		case T_OPENCOMPLETE:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    75
			// DNS is ready now.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    76
			if( result == kOTNoError )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    77
			{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    78
				dnsStatus.dns = (InetSvcRef)cookie;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    79
				dnsStatus.stat = dnsReady;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    80
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    81
			else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    82
			{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    83
				SDLNet_SetError("T_DNRSTRINGTOADDRCOMPLETE event returned an error");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    84
				dnsStatus.dns = NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    85
				dnsStatus.stat = dnsError;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    86
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    87
			break;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    88
		case T_DNRSTRINGTOADDRCOMPLETE:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    89
			// DNR resolved the name to address
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    90
			// WORK IN PROGRESS (TODO )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    91
			dnsStatus.stat = dnsResolved;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    92
			break;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    93
		default:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    94
			if( result != kOTNoError )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    95
				dnsStatus.stat = dnsError;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    96
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    97
	// Is there anything else to be done here ???
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    98
	// ( 010311 masahiro minami<elsur@aaa.letter.co.jp> )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    99
	// (TODO)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   100
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   101
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   102
/* Local functions for initializing and cleaning up the DNS resolver */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   103
static int OpenDNS(void)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   104
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   105
	int retval;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   106
	OSStatus status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   107
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   108
	retval = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   109
	status = OTAsyncOpenInternetServices(
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   110
		kDefaultInternetServicesPath, 0, OpenDNSNotifier, NULL);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   111
	if ( status == noErr ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   112
		InetInterfaceInfo	info;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   113
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   114
		dnsStatus.stat = dnsNotReady;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   115
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   116
		while( dnsStatus.stat != dnsError && dnsStatus.dns == NULL)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   117
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   118
			// what's to be done ? Yield ? WaitNextEvent ? or what ?
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   119
			// ( 010311 masahiro minami<elsur@aaa.letter.co.jp> )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   120
			//YieldToAnyThread();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   121
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   122
		/* Get the address of the local system -
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   123
		   What should it be if ethernet is off?
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   124
		 */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   125
		OTInetGetInterfaceInfo(&info, kDefaultInetInterface);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   126
		OTlocalhost = info.fAddress;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   127
	} else {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   128
		SDLNet_SetError("Unable to open DNS handle");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   129
		retval = status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   130
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   131
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   132
	return(retval);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   133
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   134
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   135
static void CloseDNS(void)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   136
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   137
	if ( dnsStatus.dns ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   138
		OTCloseProvider(dnsStatus.dns);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   139
		dnsStatus.dns = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   140
		dnsStatus.stat = dnsNotReady;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   141
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   142
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   143
	OTlocalhost = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   144
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   145
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   146
/* Initialize/Cleanup the network API */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   147
int  SDLNet_Init(void)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   148
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   149
	OSStatus status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   150
	int retval;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   151
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   152
	dnsStatus.stat = dnsNotReady;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   153
	dnsStatus.dns = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   154
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   155
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   156
	retval = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   157
	if ( ! SDLNet_started ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   158
		status = InitOpenTransport();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   159
		if ( status == noErr ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   160
			retval = OpenDNS();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   161
			if ( retval < 0 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   162
				SDLNet_Quit();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   163
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   164
		} else {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   165
			SDLNet_SetError("Unable to initialize Open Transport");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   166
			retval = status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   167
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   168
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   169
	if ( retval == 0 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   170
		++SDLNet_started;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   171
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   172
	return(retval);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   173
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   174
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   175
void SDLNet_Quit(void)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   176
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   177
	if ( SDLNet_started == 0 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   178
		return;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   179
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   180
	if ( --SDLNet_started == 0 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   181
		CloseDNS();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   182
		CloseOpenTransport();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   183
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   184
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   185
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   186
/* Resolve a host name and port to an IP address in network form */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   187
int SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   188
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   189
	int retval = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   190
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   191
	/* Perform the actual host resolution */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   192
	if ( host == NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   193
		address->host = INADDR_ANY;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   194
	} else {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   195
/*		int a[4];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   196
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   197
		address->host = INADDR_NONE;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   198
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   199
		if ( sscanf(host, "%d.%d.%d.%d", a, a+1, a+2, a+3) == 4 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   200
			if ( !(a[0] & 0xFFFFFF00) && !(a[1] & 0xFFFFFF00) &&
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   201
			     !(a[2] & 0xFFFFFF00) && !(a[3] & 0xFFFFFF00) ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   202
				address->host = ((a[0] << 24) |
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   203
				                 (a[1] << 16) |
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   204
				                 (a[2] <<  8) | a[3]);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   205
				if ( address->host == 0x7F000001 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   206
					address->host = OTlocalhost;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   207
				}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   208
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   209
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   210
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   211
		if ( address->host == INADDR_NONE ) {*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   212
			InetHostInfo hinfo;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   213
			
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   214
			/* Check for special case - localhost */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   215
			if ( strcmp(host, "localhost") == 0 )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   216
				return(SDLNet_ResolveHost(address, "127.0.0.1", port));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   217
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   218
			/* Have OpenTransport resolve the hostname for us */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   219
			retval = OTInetStringToAddress(dnsStatus.dns, (char *)host, &hinfo);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   220
			if (retval == noErr) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   221
				while( dnsStatus.stat != dnsResolved )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   222
					{WaitNextEvent(everyEvent, 0, 1, NULL );}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   223
				address->host = hinfo.addrs[0];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   224
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   225
		//}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   226
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   227
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   228
	address->port = SDL_SwapBE16(port);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   229
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   230
	/* Return the status */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   231
	return(retval);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   232
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   233
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   234
/* Resolve an ip address to a host name in canonical form.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   235
   If the ip couldn't be resolved, this function returns NULL,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   236
   otherwise a pointer to a static buffer containing the hostname
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   237
   is returned.  Note that this function is not thread-safe.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   238
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   239
/* MacOS implementation by Roy Wood
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   240
 */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   241
const char *SDLNet_ResolveIP(IPaddress *ip)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   242
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   243
	if (ip != nil)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   244
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   245
	InetHost				theIP;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   246
	static InetDomainName	theInetDomainName;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   247
	OSStatus				theOSStatus;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   248
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   249
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   250
		/*	Default result will be null string */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   251
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   252
		theInetDomainName[0] = '\0';	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   253
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   254
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   255
		/*	Do a reverse DNS lookup */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   256
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   257
		theIP = ip->host;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   258
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   259
		theOSStatus = OTInetAddressToName(dnsStatus.dns,theIP,theInetDomainName);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   260
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   261
		/*	If successful, return the result */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   262
			
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   263
		if (theOSStatus == kOTNoError)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   264
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   265
			while( dnsStatus.stat != dnsResolved )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   266
				{ /*should we yield or what ? */ }
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   267
			return(theInetDomainName);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   268
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   269
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   270
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   271
	SDLNet_SetError("Can't perform reverse DNS lookup");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   272
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   273
	return(NULL);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   274
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   275
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   276
#else /* !MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   277
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   278
#ifndef __USE_W32_SOCKETS
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   279
#include <signal.h>
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   280
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   281
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   282
/* Initialize/Cleanup the network API */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   283
int  SDLNet_Init(void)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   284
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   285
	if ( !SDLNet_started ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   286
#ifdef __USE_W32_SOCKETS
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   287
		/* Start up the windows networking */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   288
		WORD version_wanted = MAKEWORD(1,1);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   289
		WSADATA wsaData;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   290
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   291
		if ( WSAStartup(version_wanted, &wsaData) != 0 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   292
			SDLNet_SetError("Couldn't initialize Winsock 1.1\n");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   293
			return(-1);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   294
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   295
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   296
		/* SIGPIPE is generated when a remote socket is closed */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   297
		void (*handler)(int);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   298
		handler = signal(SIGPIPE, SIG_IGN);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   299
		if ( handler != SIG_DFL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   300
			signal(SIGPIPE, handler);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   301
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   302
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   303
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   304
	++SDLNet_started;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   305
	return(0);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   306
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   307
void SDLNet_Quit(void)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   308
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   309
	if ( SDLNet_started == 0 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   310
		return;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   311
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   312
	if ( --SDLNet_started == 0 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   313
#ifdef __USE_W32_SOCKETS
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   314
		/* Clean up windows networking */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   315
		if ( WSACleanup() == SOCKET_ERROR ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   316
			if ( WSAGetLastError() == WSAEINPROGRESS ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   317
				WSACancelBlockingCall();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   318
				WSACleanup();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   319
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   320
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   321
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   322
		/* Restore the SIGPIPE handler */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   323
		void (*handler)(int);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   324
		handler = signal(SIGPIPE, SIG_DFL);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   325
		if ( handler != SIG_IGN ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   326
			signal(SIGPIPE, handler);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   327
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   328
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   329
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   330
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   331
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   332
/* Resolve a host name and port to an IP address in network form */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   333
int SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   334
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   335
	int retval = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   336
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   337
	/* Perform the actual host resolution */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   338
	if ( host == NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   339
		address->host = INADDR_ANY;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   340
	} else {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   341
		address->host = inet_addr(host);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   342
		if ( address->host == INADDR_NONE ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   343
			struct hostent *hp;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   344
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   345
			hp = gethostbyname(host);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   346
			if ( hp ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   347
				memcpy(&address->host,hp->h_addr,hp->h_length);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   348
			} else {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   349
				retval = -1;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   350
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   351
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   352
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   353
	address->port = SDL_SwapBE16(port);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   354
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   355
	/* Return the status */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   356
	return(retval);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   357
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   358
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   359
/* Resolve an ip address to a host name in canonical form.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   360
   If the ip couldn't be resolved, this function returns NULL,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   361
   otherwise a pointer to a static buffer containing the hostname
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   362
   is returned.  Note that this function is not thread-safe.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   363
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   364
/* Written by Miguel Angel Blanch.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   365
 * Main Programmer of Arianne RPG.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   366
 * http://come.to/arianne_rpg
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   367
 */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   368
const char *SDLNet_ResolveIP(IPaddress *ip)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   369
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   370
	struct hostent *hp;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   371
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   372
	hp = gethostbyaddr((char *)&ip->host, 4, AF_INET);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   373
	if ( hp != NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   374
		return hp->h_name;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   375
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   376
  	return NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   377
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   378
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   379
#endif /* MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   380
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   381
#if !SDL_DATA_ALIGNED /* function versions for binary compatibility */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   382
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   383
/* Write a 16 bit value to network packet buffer */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   384
#undef SDLNet_Write16
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   385
void   SDLNet_Write16(Uint16 value, void *areap)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   386
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   387
	(*(Uint16 *)(areap) = SDL_SwapBE16(value));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   388
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   389
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   390
/* Write a 32 bit value to network packet buffer */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   391
#undef SDLNet_Write32
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   392
void   SDLNet_Write32(Uint32 value, void *areap)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   393
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   394
	*(Uint32 *)(areap) = SDL_SwapBE32(value);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   395
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   396
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   397
/* Read a 16 bit value from network packet buffer */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   398
#undef SDLNet_Read16
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   399
Uint16 SDLNet_Read16(void *areap)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   400
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   401
	return (SDL_SwapBE16(*(Uint16 *)(areap)));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   402
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   403
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   404
/* Read a 32 bit value from network packet buffer */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   405
#undef SDLNet_Read32
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   406
Uint32 SDLNet_Read32(void *areap)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   407
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   408
	return (SDL_SwapBE32(*(Uint32 *)(areap)));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   409
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   410
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   411
#endif /* !SDL_DATA_ALIGNED */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   412
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   413
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   414
#ifdef USE_GUSI_SOCKETS
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   415
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   416
/* Configure Socket Factories */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   417
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   418
void GUSISetupFactories()
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   419
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   420
	GUSIwithInetSockets();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   421
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   422
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   423
/* Configure File Devices */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   424
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   425
void GUSISetupDevices()
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   426
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   427
	return;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   428
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   429
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   430
#endif /* USE_GUSI_SOCKETS */