Page 1 of 1

ps2ip connect to PC problem

Posted: Sat Sep 03, 2005 8:14 pm
by TJ
Hi guys,

I'm having trouble trying to write code to get my PS2 to connect to a PC using ps2ip.
I am using the latest ps2sdk.
I reset the iop and load the modules as follows:

Code: Select all

SifExitRpc();
SifIopReset("rom0:UDNL rom0:EELOADCNF", 0);
while(!SifIopSync());

SifInitRpc(0);

if(SifLoadFileInit() != 0)
    return; // bind failed.

log(LOG_SYSTEM, LOG_INFO, "Loading LIBSD module");
if &#40;SifLoadModule&#40;"rom0&#58;LIBSD", 0, NULL&#41; < 0&#41;
&#123;
    log&#40;LOG_SYSTEM, LOG_ERROR, "Failed to load LIBSD module"&#41;;
&#125;

log&#40;LOG_SYSTEM, LOG_INFO, "Loading AUDSRV module"&#41;;

if&#40;SifExecModuleBuffer&#40;audsrv_irx, size_audsrv_irx, 0, NULL, &i&#41; < 0&#41;
&#123;
    log&#40;LOG_SYSTEM, LOG_ERROR, "Failed to load AUDSRV module"&#41;;
&#125;

log&#40;LOG_SYSTEM, LOG_INFO, "Loading PS2IP module"&#41;;
if&#40;SifExecModuleBuffer&#40;ps2ip_irx, size_ps2ip_irx, 0, NULL, &i&#41; < 0&#41;
&#123;
    log&#40;LOG_SYSTEM, LOG_ERROR, "Failed to load PS2IP module"&#41;;
&#125;

log&#40;LOG_SYSTEM, LOG_INFO, "Loading PS2IPS module"&#41;;
if&#40;SifExecModuleBuffer&#40;ps2ips_irx, size_ps2ips_irx, 0, NULL, &i&#41; < 0&#41;
&#123;
    log&#40;LOG_SYSTEM, LOG_ERROR, "Failed to load PS2IPs module"&#41;;
&#125;

log&#40;LOG_SYSTEM, LOG_DEBUG, "Initialising ps2ip"&#41;;

ps2ip_init&#40;&#41;;
Everything seems to be fine here, all modules load OK. Next I try to connect to the PC using the following code:

Code: Select all

struct sockaddr_in server;
s32 socket = -1;
s32 retcount = 0;
ip_addr addr;

socket = socket&#40;AF_INET, SOCK_STREAM, 0&#41;;
if&#40;socket < 0&#41;
&#123;
    log&#40;LOG_DATASOURCE, LOG_ERROR, "HttpDataSource&#58;&#58;open failed to create socket"&#41;;
    return false;
&#125;

memset&#40;&server, 0, sizeof&#40;server&#41;&#41;;

server.sin_family = AF_INET;
IP4_ADDR&#40;&addr, 192, 168, 1, 2&#41;;
server.sin_addr.s_addr = addr.addr;

server.sin_port = htons&#40;80&#41;;

if&#40;connect&#40;m_socket, &#40;struct sockaddr*&#41;&server, sizeof&#40;server&#41;&#41; < 0&#41;
&#123;
    log&#40;LOG_DATASOURCE, LOG_ERROR, "HttpDataSource&#58;&#58;open failed to connect"&#41;;
    return false;
&#125;
According to the debug, the call to socket succeeds, whereas the call to connect fails. I can connect to
the port using telnet on ps2linux, so it shouldn't be a problem with the network etc.

Can anyone see anything obviously wrong with this code?

Does anyone know of any projects that use ps2ip to connect to servers on remote machines? Everything
I look at sets up a server on the ps2 and connects to it from the PC.

Also, does anyone know if gethostbyname works? This seems to be defined in the irx, but not in the
ps2ip ee code.

Thanks for any tips you can give.

// TJ

Posted: Sun Sep 04, 2005 10:23 am
by apache37
Maybe it's me but where's your SMAP setup?

Posted: Sun Sep 04, 2005 9:58 pm
by TJ
Thanks for the reply.

I'm not 100% sure what SMAP setup is, but I think you mean that I need to set my IP address etc. Now I have added a call to ps2ip_setconfig as follows, which seems to succeed, but still no success on connecting.

Code: Select all

log&#40;LOG_SYSTEM, LOG_DEBUG, "Initialising ps2ip"&#41;;

t_ip_info ipinfo;
ip_addr addr;


ps2ip_init&#40;&#41;;

memset&#40;&ipinfo, 0, sizeof&#40;ipinfo&#41;&#41;;
strcpy&#40;ipinfo.netif_name, "et"&#41;;

IP4_ADDR&#40;&addr, 192, 168, 1, 20&#41;;
ipinfo.ipaddr.s_addr = addr.addr;
IP4_ADDR&#40;&addr, 255, 255, 255, 0&#41;;
ipinfo.netmask.s_addr = addr.addr;

IP4_ADDR&#40;&addr, 192, 168, 1, 1&#41;;
ipinfo.gw.s_addr = addr.addr;
ipinfo.dns_server.s_addr = addr.addr;

if&#40;ps2ip_setconfig&#40;&ipinfo&#41; == 0&#41;
&#123;
    log&#40;LOG_SYSTEM, LOG_ERROR, "Failed to set ps2ip config"&#41;;
&#125;
Anything else I'm missing??

// TJ

Posted: Mon Sep 05, 2005 7:42 am
by apache37
Yes :p

Ok.. here's the order I use:

Code: Select all

   /* oppen the expansion bay */
	SifLoadModule&#40;"host&#58;/irx/PS2DEV9.IRX", 0, NULL&#41;;

	/* load the stack */
	SifLoadModule&#40;"host&#58;/irx/PS2IP.IRX", 0, NULL&#41;;
	SifLoadModule&#40;"host&#58;/irx/PS2IPS.IRX", 0, NULL&#41;;

	/* load up smap with static settings */
	strcpy&#40;&args&#91;a&#93;, IP&#41;; a += strlen&#40;IP&#41; + 1;
	strcpy&#40;&args&#91;a&#93;, NM&#41;; a += strlen&#40;NM&#41; + 1;
	strcpy&#40;&args&#91;a&#93;, GW&#41;; a += strlen&#40;GW&#41; + 1;
	SifLoadModule&#40;"host&#58;/irx/SMAPX.IRX", a, args&#41;;
After this you can do ps2ip_init(). You need DEV9 and SMAP to initialize the hardware side. Take a look at the ps2link source for more info.
Hope this helps.

BTW if anyone is reading what's the story with dns.irx?? It has gethostbyname() but no ee side export for this. Is it incomplete or can I make it work?

Posted: Mon Sep 05, 2005 11:45 pm
by TJ
Thanks for the help.

I was a bit thrown by the fact that the SMAP irx isnt in ps2sdk in svn, but I found it under ps2eth and now I can connect :)

// TJ