| View previous topic :: View next topic |
| Author |
Message |
Noobacide
Joined: 03 Jul 2005 Posts: 4
|
Posted: Sun Jul 03, 2005 12:27 pm Post subject: sceNetInetConnect (PspPet please help!) |
|
|
I'm having trouble with getting sceNetInetConnect() to work, either I'm calling it wrong or sony messed with sockaddr_in structure for the psp.
| Code: |
struct sockaddr_in {
unsigned short sin_family; // REVIEW: is this correct ?
unsigned short sin_port; // use htons()
unsigned char sin_addr[4];
char sin_zero[8];
};
int sceNetInetConnect(SOCKET s, const void *name, int namelen);
int ConnectToTcpAddr (unsigned long host, int port) {
int sock, err;
struct sockaddr_in addr;
_memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
*(u32*)addr.sin_addr = htonl(host);
sock = sceNetInetSocket(AF_INET, SOCK_STREAM, 0);
if(sock < 0) {
printf("Socket error %i\n", sceNetInetGetErrno());
} else {
printf("Socket %i ok\n", sock);
}
err = sceNetInetConnect(sock, &addr, sizeof(addr));
if (err < 0) {
printf("Connect error %i\n", sceNetInetGetErrno());
} else {
printf("Connect ok\n");
}
return sock;
}
|
what I get when calling ConnectToTcpAddr(0xc0a80001, 5900):
(192.168.0.1)
| Code: |
Socket 8 ok
Connect error 106
|
since from what I've read, sony uses newlib, I looked up the error code in newlib's errno.h and i find 106 = EAFNOSUPPORT
which doesnt make much sense to me unless the prototype for sceNetInetConnect is wrong or the struct for sockaddr_in is wrong |
|
| Back to top |
|
 |
pspkrazy
Joined: 04 Jul 2005 Posts: 49
|
Posted: Mon Jul 04, 2005 1:43 am Post subject: the same |
|
|
I've played a little with psppet's sample in a hope of making a little ftp server.
I've got the same problems with sceNetInetConnect.
So i decided to reverse the situation (PASV) and to open another socket on the psp (bind, listen, accept...).
It didn't work.
So in my mind, the problem is not connect or accept. Maybe security problems or threads... I don't know.
Why psppet can open a socket and i can't add another with the same code ? ;)
psppet pleaaaaaaaaaase !!! |
|
| Back to top |
|
 |
PspPet
Joined: 30 Mar 2005 Posts: 210
|
Posted: Mon Jul 04, 2005 2:19 am Post subject: |
|
|
> I'm calling it wrong or sony messed with sockaddr_in structure for the psp.
You got it right - the Sony PSP structure is a little non-standard (hence the REVIEW comment). Extra byte out front (apparently unused, at least according to TwistedMetal game code)
Will be updating the sample and header later.
In the mean time, try this [also be sure the structure packs to a size of 16 bytes]. Should make sceNetInetConnect and other APIs work properly now (the old version worked somewhat accidentally)
----
| Code: |
struct sockaddr_in {
unsigned char sin_reserved; // PSP specific - ignored
unsigned char sin_family; // usually AF_INET
unsigned short sin_port; // use htons()
unsigned char sin_addr[4];
char sin_zero[8];
};
|
|
|
| Back to top |
|
 |
Lex
Joined: 11 May 2005 Posts: 27 Location: Germany
|
Posted: Mon Jul 04, 2005 3:50 am Post subject: |
|
|
Maybe the unknown value is the socketaddr length ?
In BSD manuals I found:
The sockaddr_in structure, defined in <netinet/in.h>, is the IPv4 sockaddr
variant, and is as follows:
| Code: |
struct sockaddr_in {
u_short sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
|
If the compile-time option _SOCKADDR_LEN is defined before the sys/socket.h
header file is included, however, the 4.4BSD sockaddr_in structure is
defined, which is as follows:
| Code: |
struct sockaddr_in {
u_char sin_len;
sa_family_t sin_family;
in_port_t sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
|
|
|
| Back to top |
|
 |
pspkrazy
Joined: 04 Jul 2005 Posts: 49
|
Posted: Mon Jul 04, 2005 6:56 am Post subject: thanks |
|
|
It seems that the modification of the struct changed the behaviour of the connect function.
Don't know actually if it works or not.
Thanx psppet for your comment. You're really the king of psp's net.
Will you code socket.h ?
Keep the good work. |
|
| Back to top |
|
 |
Noobacide
Joined: 03 Jul 2005 Posts: 4
|
Posted: Mon Jul 04, 2005 4:58 pm Post subject: |
|
|
ok, I've modified my headers to match. but now instead of connect() returning and error, it never returns :(
not even throwing an exception. |
|
| Back to top |
|
 |
pspkrazy
Joined: 04 Jul 2005 Posts: 49
|
Posted: Mon Jul 04, 2005 5:11 pm Post subject: works |
|
|
it does work.
If your connect doesn't return it is because it is trying to connect somewhere.
Maybe the inet address is not ok.
You don't have to htonl it.
Hope it helps |
|
| Back to top |
|
 |
PspPet
Joined: 30 Mar 2005 Posts: 210
|
Posted: Tue Jul 05, 2005 2:00 am Post subject: |
|
|
> Maybe the unknown value is the socketaddr length ?
That's my guess too -- as a place-holder. But it doesn't appear to be set or checked. [ie. you should be able to ignore it, and with the new alignment many more 'socket.h' APIs should work]
The true length of the structure (16 bytes) is passed the system APIs.
> Will you code socket.h ?
Yes there will be a socket.h work-alike
| Code: |
#define socket sceNetInetSocket
#define bind sceNetInetBind
...
|
> You're really the king of psp's net.
FWIW: Actually it was embarrasingly easy. The big stumbling block was the lazy import problem [I still think there is one bit being missed]
Having the SHA1 generated names for disassembling the system and programs makes it very easy!
> ok, I've modified my headers to match. but now instead of connect() returning and error, it never returns :(
As mentioned, you probably aren't connecting to a true IP address. If it doesn't find the target IP address, it doesn't return. If it does find it but can't open the specified port, it should return an error.
The error recovery is still minimal. |
|
| Back to top |
|
 |
Noobacide
Joined: 03 Jul 2005 Posts: 4
|
|
| Back to top |
|
 |
pspkrazy
Joined: 04 Jul 2005 Posts: 49
|
Posted: Tue Jul 05, 2005 5:32 pm Post subject: great !!! |
|
|
A psp vnc client !!!
Great job ;)
WAR driving ? ;) |
|
| Back to top |
|
 |
flyingtux
Joined: 19 Oct 2005 Posts: 1
|
Posted: Wed Oct 19, 2005 9:15 pm Post subject: |
|
|
hi,
I'm a newbie in pspdev and would like to port a socket based lib named ivybus on psp
I've installed pspsdk but doen't find any sceNetInet headers or lib inside
Could you explain if there is no headers yet , how to compile and link socket based program with the pspsdk ;-)
Regards,
Flyingtux |
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Thu Oct 20, 2005 12:06 am Post subject: |
|
|
| You can't as there is no network support in PSPSDK. |
|
| Back to top |
|
 |
PspPet
Joined: 30 Mar 2005 Posts: 210
|
Posted: Thu Oct 20, 2005 1:03 am Post subject: |
|
|
> I've installed pspsdk but doen't find any sceNetInet headers or lib inside
There is currently a sample layered on top of the PSPSDK. Most of the WiFi programs have been created based on that.
Creating a general purpose lib may be a little tricky. See the WiFi .02 sample (it requires specialized startup):
http://www.aibohack.com/psp/wifitest.htm
[BTW: domain has been flakey if so -> http://66.70.136.74/psp/wifitest.htm ] |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Thu Oct 20, 2005 4:01 am Post subject: |
|
|
It is worth pointing out that psplink allows you to run normal user mode apps which allows the net libs to link in correctly, I am too lazy to actually write a full blown net test app so I have only tried sceNetInit which works fine ;) Something like this would at least reduce the burden on the normal applications programmer as you could just link in the libs and it _should_ work.
That said it is still not a general solution, for a start it requires you to have psplink, I will at some point get around to implementing psplink to act as a simple bootstrap for your app so you don't actually need things like a sio cable to use it. Even that doesn't necessarily help, even with various kernel patches you still cannot load the encrypted net modules from flash as the kernel falls over, you either must load decrypted copies from ms or get psplink to pre-load them before you app. And then there is vsh mode...
Nothing is ever simple. |
|
| Back to top |
|
 |
|