Problems with sceNetResolverStartNtoA()

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
AlphaDingDong
Posts: 29
Joined: Fri Mar 21, 2008 2:51 pm
Location: The interwebs

Problems with sceNetResolverStartNtoA()

Post by AlphaDingDong »

I recently upgraded to 5.00m33-6 and also updated my toolchain to revision 2487.

I've been working to try and get net functionality into Lua Player Euphoria, but I'm having a hell of a time with the resolver.

I'm fairly certain this is the same code I used before, but suddenly it doesn't want to work. Specifically sceNetResolverStartNtoA() is simply hanging. It blocks the thread and never returns. Other threads continue running. I've let the thing sit for several minutes. I wrote up a quick test app to demonstrate. Is anyone aware of a change to the SDK/FW that's preventing this from working? Otherwise can anyone spot something I'm screwing up here?

Code: Select all

//{Inclusions
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <malloc.h>
#include <pspsdk.h>
#include <unistd.h>
#include <pspnet.h>
#include <psputility.h>
#include <pspnet_inet.h>
#include <pspnet_apctl.h>
#include <pspnet_resolver.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <pspwlan.h>
#include <errno.h>
#include <string.h>
#include <pspgu.h>
#include <stdarg.h>
//&#125;
PSP_MODULE_INFO&#40;"resolver", 0, 1, 1&#41;;
u32* list;

int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
  sceKernelExitGame&#40;&#41;;
  return 0;
&#125;

int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
  int cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
  sceKernelRegisterExitCallback&#40;cbid&#41;;
  sceKernelSleepThreadCB&#40;&#41;;
  return 0;
&#125;

void setupCallbacks&#40;&#41; &#123;
  int thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
  if&#40;thid >= 0&#41; &#123;sceKernelStartThread&#40;thid, 0, 0&#41;;&#125;
&#125;

void debug&#40;char* msg, ...&#41; &#123;
  va_list args;
  va_start&#40;args, msg&#41;;
  pspDebugScreenInit&#40;&#41;;
  pspDebugScreenPrintf&#40;msg, args&#41;;
  va_end&#40;args&#41;;
  sceKernelSleepThread&#40;&#41;;
&#125;

void startGfx&#40;&#41; &#123;
  list = &#40;unsigned*&#41;memalign&#40;16, 262144&#41;;
  sceGuInit&#40;&#41;;
  sceGuStart&#40;GU_DIRECT, list&#41;;
  sceGuDrawBuffer&#40;GU_PSM_8888, &#40;void*&#41;0, 512&#41;;
  sceGuDispBuffer&#40;480, 272, &#40;void*&#41;0x88000, 512&#41;;
  sceGuDepthBuffer&#40;&#40;void*&#41;0x110000, 512&#41;;
  sceGuOffset&#40;1808, 1912&#41;;
  sceGuViewport&#40;2048, 2048, 480, 272&#41;;
  sceGuDepthRange&#40;0xFFFF, 0&#41;;
  sceGuDepthFunc&#40;GU_GEQUAL&#41;;
  sceGuEnable&#40;GU_DEPTH_TEST&#41;;
  sceGuScissor&#40;0, 0, 480, 272&#41;;
  sceGuEnable&#40;GU_SCISSOR_TEST&#41;;
  sceGuAlphaFunc&#40;GU_GREATER, 0, 0xFF&#41;;
  sceGuEnable&#40;GU_ALPHA_TEST&#41;;
  sceGuTexMode&#40;GU_PSM_8888, 0, 0, 0&#41;;
  sceGuTexFunc&#40;GU_TFX_MODULATE, GU_TCC_RGBA&#41;;
  sceGuTexFilter&#40;GU_NEAREST, GU_NEAREST&#41;;
  sceGuEnable&#40;GU_TEXTURE_2D&#41;;
  sceGuBlendFunc&#40;GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0&#41;;
  sceGuEnable&#40;GU_BLEND&#41;;
  sceGuClearColor&#40;0xFF000000&#41;;
  sceGuClearDepth&#40;0&#41;;
  sceGuClear&#40;GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT&#41;;
  sceGuFinish&#40;&#41;;
  sceGuSync&#40;0, 0&#41;;
  sceGuDisplay&#40;GU_TRUE&#41;;
&#125;

void startNet&#40;&#41; &#123;
  int ret = sceUtilityLoadNetModule&#40;PSP_NET_MODULE_COMMON&#41;;
  if&#40;ret&#41; &#123;debug&#40;"Error loading common module, %x", ret&#41;;&#125;
  ret = sceUtilityLoadNetModule&#40;PSP_NET_MODULE_INET&#41;;
  if&#40;ret&#41; &#123;debug&#40;"Error loading inet module, %x", ret&#41;;&#125;
  ret = sceNetInit&#40;128*1024, 42, 4*1024, 42, 4*1024&#41;;
  if&#40;ret&#41; &#123;debug&#40;"Error in sceNetInit, %x", ret&#41;;&#125;
  ret = sceNetInetInit&#40;&#41;;
  //if&#40;ret&#41; &#123;debug&#40;"Error in sceNetInetInit &#40;?&#41; %x", ret&#41;;&#125; //no docs on return values, but I doubt this is the problem
  ret = sceNetApctlInit&#40;0x8000, 48&#41;;
  if&#40;ret < 0&#41; &#123;debug&#40;"Error in sceNetApctlInit, %x", ret&#41;;&#125;
  ret = sceNetResolverInit&#40;&#41;;
  if&#40;ret&#41; &#123;debug&#40;"Error in sceNetResolverInit, %x", ret&#41;;&#125;
&#125;

void connectAP&#40;&#41; &#123;
  pspUtilityNetconfData data;
  memset&#40;&data, 0, sizeof&#40;data&#41;&#41;;
  data.base.size = sizeof&#40;data&#41;;
  data.base.language = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH;
  data.base.buttonSwap = PSP_UTILITY_ACCEPT_CROSS;
  data.base.graphicsThread = 18;
  data.base.accessThread = 20;
  data.base.fontThread = 19;
  data.base.soundThread = 17;
  data.action = PSP_NETCONF_ACTION_CONNECTAP;
  struct pspUtilityNetconfAdhoc adhocparam;
  memset&#40;&adhocparam, 0, sizeof&#40;adhocparam&#41;&#41;;
  data.adhocparam = &adhocparam;
  sceUtilityNetconfInitStart&#40;&data&#41;;
  int running = 1;
  while&#40;running&#41; &#123;
    sceGuStart&#40;GU_DIRECT, list&#41;;
    sceGuClear&#40;GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT&#41;;
    sceGuFinish&#40;&#41;;
    sceGuSync&#40;0,0&#41;;
    switch&#40;sceUtilityNetconfGetStatus&#40;&#41;&#41; &#123;
      case PSP_UTILITY_DIALOG_VISIBLE&#58; sceUtilityNetconfUpdate&#40;1&#41;; break;
      case PSP_UTILITY_DIALOG_QUIT&#58; sceUtilityNetconfShutdownStart&#40;&#41;; break;
      case PSP_UTILITY_DIALOG_NONE&#58; running = 0; break;
    &#125;
    sceGuSwapBuffers&#40;&#41;;
  &#125;
&#125;

uint32_t resolve&#40;&#41; &#123;
  int rid = 0;
  char buf&#91;1024&#93;;
  struct in_addr addr;
  memset&#40;&addr, 0, sizeof&#40;addr&#41;&#41;;
  int ret = sceNetResolverCreate&#40;&rid, buf, 1024&#41;;
  if&#40;ret&#41; &#123;debug&#40;"Error in sceNetResolverCreate&#58; %x", ret&#41;;&#125;
  ret = sceNetResolverStartNtoA&#40;rid, "google.com", &addr, 3, 3&#41;; //this function never returns
  if&#40;ret&#41; &#123;debug&#40;"Error in sceNetResolverStartNtoA&#58; %x", ret&#41;;&#125;
  ret = sceNetResolverDelete&#40;rid&#41;;
  if&#40;ret&#41; &#123;debug&#40;"Error in sceNetResolverDelete&#58; %x", ret&#41;;&#125;
  return addr.s_addr;
&#125;

int main&#40;&#41; &#123;
  setupCallbacks&#40;&#41;;
  startGfx&#40;&#41;;
  startNet&#40;&#41;;
  connectAP&#40;&#41;;
  uint32_t address = resolve&#40;&#41;;
  char str&#91;INET_ADDRSTRLEN&#93;;
  inet_ntop&#40;AF_INET, &#40;void*&#41;&address, str, INET_ADDRSTRLEN&#41;;
  debug&#40;"Success.\nAddress is&#58; %s", str&#41;;
  return 0;
&#125;

Code: Select all

TARGET = resolver
TARGET_FOLDER = K&#58;/PSP/GAME/$&#40;TARGET&#41;
OBJS = main.o
CFLAGS = -O3 -G0 -Wall -Werror
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;
LIBDIR =
LIBS = -lpspgu
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Resolver Test
PSP_LARGE_MEMORY = 1
PSP_FW_VERSION = 371
PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

eboot&#58;
	@if &#91; -f EBOOT.PBP &#93;; then echo "Found EBOOT.PBP."; else $&#40;MAKE&#41; --no-print-directory all; fi
	@echo "Moving EBOOT to PSP..."
	@mv EBOOT.PBP $&#40;TARGET_FOLDER&#41;

update&#58;
	@$&#40;MAKE&#41; --no-print-directory eboot
	@echo "Done."

install&#58;
	@echo "&#91;Installing to PSP&#93;"
	@if &#91; -d $&#40;TARGET_FOLDER&#41; &#93;; then echo "Found project folder."; else echo "Creating project folder..."; mkdir $&#40;TARGET_FOLDER&#41;; fi
	@$&#40;MAKE&#41; --no-print-directory eboot
	@echo "&#91;Installation complete&#93;"
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi! :)

I had the same problem, I didn't solve it, but using the standard

Code: Select all

struct hostent *host;
host = gethostbyname&#40;address&#41;;
seems to work.

Ciaooo
Sakya
AlphaDingDong
Posts: 29
Joined: Fri Mar 21, 2008 2:51 pm
Location: The interwebs

Post by AlphaDingDong »

Thanks, sakya.

I'll give it a shot. :)
AlphaDingDong
Posts: 29
Joined: Fri Mar 21, 2008 2:51 pm
Location: The interwebs

Post by AlphaDingDong »

Hmm... I'm getting the same behavior. ???

It tried this:

Code: Select all

uint32_t resolve&#40;&#41; &#123;
  struct hostent* host = gethostbyname&#40;"google.com"&#41;;
  if&#40;host == NULL&#41; &#123;debug&#40;"Failed to resolve host address."&#41;;&#125;
  struct in_addr* addr = &#40;struct in_addr*&#41;host->h_addr;
  return addr->s_addr;
&#125;
But it hangs when it reaches gethostbyname(). This is completly bizzare.

Am I doing that lookup correctly? Still, I'd expect it to give an error rather than just sitting there like this.
Post Reply