forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sceNetInetConnect (PspPet please help!)

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Noobacide



Joined: 03 Jul 2005
Posts: 4

PostPosted: Sun Jul 03, 2005 12:27 pm    Post subject: sceNetInetConnect (PspPet please help!) Reply with quote

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
View user's profile Send private message
pspkrazy



Joined: 04 Jul 2005
Posts: 49

PostPosted: Mon Jul 04, 2005 1:43 am    Post subject: the same Reply with quote

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
View user's profile Send private message
PspPet



Joined: 30 Mar 2005
Posts: 210

PostPosted: Mon Jul 04, 2005 2:19 am    Post subject: Reply with quote

> 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
View user's profile Send private message Send e-mail Visit poster's website
Lex



Joined: 11 May 2005
Posts: 27
Location: Germany

PostPosted: Mon Jul 04, 2005 3:50 am    Post subject: Reply with quote

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
View user's profile Send private message
pspkrazy



Joined: 04 Jul 2005
Posts: 49

PostPosted: Mon Jul 04, 2005 6:56 am    Post subject: thanks Reply with quote

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
View user's profile Send private message
Noobacide



Joined: 03 Jul 2005
Posts: 4

PostPosted: Mon Jul 04, 2005 4:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
pspkrazy



Joined: 04 Jul 2005
Posts: 49

PostPosted: Mon Jul 04, 2005 5:11 pm    Post subject: works Reply with quote

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
View user's profile Send private message
PspPet



Joined: 30 Mar 2005
Posts: 210

PostPosted: Tue Jul 05, 2005 2:00 am    Post subject: Reply with quote

> 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
View user's profile Send private message Send e-mail Visit poster's website
Noobacide



Joined: 03 Jul 2005
Posts: 4

PostPosted: Tue Jul 05, 2005 3:06 pm    Post subject: Reply with quote

thanks everyone, I managed to get it to work

heres a screenshot i'm sure everyone will enjoy
(Note, its running on my linuxbox, then being exported to the psp with VNC)

http://www.xboxopensource.com/upload/NHD/pspdev/vnc_firefox.jpg
Back to top
View user's profile Send private message
pspkrazy



Joined: 04 Jul 2005
Posts: 49

PostPosted: Tue Jul 05, 2005 5:32 pm    Post subject: great !!! Reply with quote

A psp vnc client !!!

Great job ;)

WAR driving ? ;)
Back to top
View user's profile Send private message
flyingtux



Joined: 19 Oct 2005
Posts: 1

PostPosted: Wed Oct 19, 2005 9:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Thu Oct 20, 2005 12:06 am    Post subject: Reply with quote

You can't as there is no network support in PSPSDK.
Back to top
View user's profile Send private message
PspPet



Joined: 30 Mar 2005
Posts: 210

PostPosted: Thu Oct 20, 2005 1:03 am    Post subject: Reply with quote

> 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
View user's profile Send private message Send e-mail Visit poster's website
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Thu Oct 20, 2005 4:01 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group