If I do have to set the IP for the PS2, I have attempted to use the 'ps2ip_setconfig()' function using a code snippet from http://forums.ps2dev.org/viewtopic.p...tconfighttp:// (3rd post). It seems to freeze on "strcpy(ipinfo->netif_name, "et");". PS2IP seems to use the same method in a function called IFLoop I believe.
main.c:
Code:
#include <stdio.h>
#include <debug.h>
#include <kernel.h>
#include "ps2ip.h"
#include "smap/smap.h"
#include <sifrpc.h>
#include <iopcontrol.h>
#include <loadfile.h>
#include "Obj/PS2IP_IRX.c"
#include "Obj/PS2IPS_IRX.c"
#include "Obj/PS2DEV9_IRX.c"
#include "Obj/SMAP_IRX.c"
#include "Obj/DNS_IRX.c"
#include "Obj/POWEROFF_IRX.c"
int Initialize(void);
int StartServer();
int main(void)
{
if (Initialize() != 0)
{
scr_printf(" Did not successfully initialize!\n");
return -1;
}
scr_printf(" Initialized!\n");
if (StartServer() != 0)
{
scr_printf(" Some error(s) have occurred!\n");
return -1;
}
return 0;
}
int Initialize(void)
{
int a;
SifInitRpc(0);
init_scr();
scr_printf(" Beginning initialization!\n");
a = SifExecModuleBuffer(&POWEROFF_IRX, size_POWEROFF_IRX, 0, NULL, &a);
if (a <= 0 )
{
scr_printf(" Could not load POWEROFF.IRX! %d\n", a);
return -1;
}
scr_printf(" Loaded POWEROFF.IRX!\n");
a = SifExecModuleBuffer(&PS2DEV9_IRX, size_PS2DEV9_IRX, 0, NULL, &a);
if (a <= 0 )
{
scr_printf(" Could not load PS2DEV9.IRX! %d\n", a);
return -1;
}
scr_printf(" Loaded PS2DEV9.IRX!\n");
a = SifExecModuleBuffer(&PS2IP_IRX, size_PS2IP_IRX, 0, NULL, &a);
if (a <= 0 )
{
scr_printf(" Could not load PS2IP.IRX!\n %d", a);
return -1;
}
scr_printf(" Loaded PS2IP.IRX!\n");
a = SifExecModuleBuffer(&DNS_IRX, size_DNS_IRX, 0, NULL, &a);
if (a <= 0)
{
scr_printf(" Could not load DNS.IRX! %d\n", a);
return -1;
}
scr_printf(" Loaded DNS.IRX!\n");
a = SifExecModuleBuffer(&PS2IPS_IRX, size_PS2IPS_IRX, 0, NULL, &a);
if (a <= 0)
{
scr_printf(" Could not load PS2IPS.IRX! %d\n", a);
return -1;
}
scr_printf(" Loaded PS2IPS.IRX!\n");
a = SifExecModuleBuffer(&SMAP_IRX, size_SMAP_IRX, 0, NULL, &a);
if (a <= 0)
{
scr_printf(" Could not load SMAP.IRX! %d\n", a);
return -1;
}
scr_printf(" Loaded SMAP.IRX!\n");
scr_printf(" Loaded irx modules\n");
a = ps2ip_init();
if (a != 0)
{
scr_printf(" Could not initialize! %d\n", a);
return -1;
}
/*t_ip_info *info;
struct ip_addr ip, nm, gw;
char* name = "test";
scr_printf(" memset\n");
memset(&info, 0, sizeof(info));
scr_printf(" netif_name\n");
strcpy(info->netif_name, name);
scr_printf(" ip address\n");
IP4_ADDR(&ip, 10, 0, 1, 100);
scr_printf(" storing ip in ipinfo\n");
info->ipaddr.s_addr = ip.addr;
scr_printf(" net mask\n");
IP4_ADDR(&nm, 255, 255, 255, 0);
scr_printf(" storing netmask\n");
info->netmask.s_addr = nm.addr;
scr_printf(" gateway\n");
IP4_ADDR(&gw, 10, 0, 1, 1);
scr_printf(" storing gateway\n");
info->gw.s_addr = gw.addr;
scr_printf(" storing dns\n");
info->dns_server.s_addr = gw.addr;
scr_printf(" setting config\n");
a = ps2ip_setconfig(info);
if (a <= 0)
{
scr_printf(" Could not set IP config for PS2IP! %d\n", a);
return -1;
}
scr_printf(" PS2 IP set!\n");*/
return 0;
}
int StartServer()
{
int x;
struct ip_addr addr;
for (x = 0; x < 200000000; x++) //Delay so I can see if there are any initialization errors
{
}
scr_clear();
scr_printf(" Creating socket...\n");
int sockfd, newsockfd, portno = 2345;
socklen_t clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP );
if (sockfd < 0)
{
scr_printf(" Could not create socket!\n");
return -1;
}
scr_printf(" Socket created!\n Binding Socket...\n");
memset((char *) &serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
IP4_ADDR(&addr, 10, 0, 1, 100);
serv_addr.sin_addr.s_addr = addr.addr;
serv_addr.sin_port = htons(portno);
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
{
scr_printf(" Could not bind socket!\n");
return -1;
}
scr_printf(" Socket binded!\n");
scr_printf(" Port: %d\n", portno);
scr_printf(" Listening for any incoming connection...\n");
listen(sockfd,5);
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
scr_printf(" Accepting incoming connection...\n");
if (newsockfd < 0)
{
scr_printf(" An error occured while trying to accept the connection!\n");
return -1;
}
scr_printf(" Connected accepted!\n");
scr_printf(" Waiting for data to be sent...\n");
memset(buffer, 0, 256);
n = read(newsockfd,buffer,255);
if (n <= 0) { scr_printf(" Data could not be recieved!\n"); return -1; }
scr_printf(" Here is the message: %s\n", buffer);
//n = write(newsockfd,"I got your message",18);
//if (n <= 0) { scr_printf(" Data could not be sent!\n"); }
close(newsockfd);
close(sockfd);
return 0;
}
Leave a comment: