ntba2's tcpip-additions committable to svn?

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
Henk
Posts: 14
Joined: Fri Dec 29, 2006 10:19 am

ntba2's tcpip-additions committable to svn?

Post by Henk »

Heyas,

I am wondering if the tcpip-additions from ntba2 can be committed to svn. Basically they don't change any existing functionality, but only add 6 functions which are needed to compile myPS2.

I don't see any reason why they can't be commited since they don't change anything which might break existing applications, but having them in svn would make my life way easier since I wouldn't need to patch the sdk each time a new revision comes out. Below are the diff -ru changes.

Code: Select all

--- ps2sdk/common/include/tcpip.h	2007-01-18 02:58:32.000000000 +0100
+++ ps2sdksrc/common/include/tcpip.h	2007-01-18 02:56:41.000000000 +0100
@@ -361,4 +361,21 @@
 	u8					hw_addr[8];
 } t_ip_info;
 
+#ifndef FAR
+#define FAR
+#endif
+struct hostent {
+	char    FAR * h_name;				/* official name of host */
+	char    FAR * FAR * h_aliases;		/* alias list */
+	short   h_addrtype;					/* host address type */
+	short   h_length;					/* length of address */
+	char    FAR * FAR * h_addr_list;	/* list of addresses */
+#define h_addr  h_addr_list[0]				/* address, for backward compat */
+};
+
+#if !defined(INADDR_NONE)
+#define INADDR_NONE		((u32) 0xffffffff)  /* 255.255.255.255 */
+#endif
+
 #endif
+
--- ps2sdk/ee/rpc/tcpip/include/ps2ip.h	2007-01-18 02:58:33.000000000 +0100
+++ ps2sdksrc/ee/rpc/tcpip/include/ps2ip.h	2007-01-18 02:55:54.000000000 +0100
@@ -34,6 +34,12 @@
 int ps2ip_getconfig(char *netif_name, t_ip_info *ip_info);
 int select(int maxfdp1, struct fd_set *readset, struct fd_set *writeset, struct fd_set *exceptset, struct timeval *timeout);
 int ioctlsocket(int s, long cmd, void *argp);
+int getsockname(int s, struct sockaddr* name, int* namelen);
+int getpeername(int s, struct sockaddr *name, int *namelen);
+int getsockopt(int s, int level, int optname, void* optval, socklen_t* optlen);
+int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen);
+int gethostbyname(char *name, struct in_addr *ip);
+int ps2ip_dnslookup(char *name, struct in_addr *ip);
 
 #ifdef __cplusplus
 }
--- ps2sdk/ee/rpc/tcpip/src/ps2ipc.c	2007-01-18 02:58:33.000000000 +0100
+++ ps2sdksrc/ee/rpc/tcpip/src/ps2ipc.c	2007-01-18 02:55:29.000000000 +0100
@@ -35,6 +35,11 @@
 #define ID_GETCONFIG  13
 #define ID_SELECT  14
 #define ID_IOCTL   15
+#define ID_GETSOCKNAME	16
+#define ID_GETPEERNAME	17
+#define ID_GETSOCKOPT	18
+#define ID_SETSOCKOPT	19
+#define ID_GETHOSTBYNAME	20
 
 static int _init_check = 0;
 static SifRpcClientData_t _ps2ip;
@@ -422,3 +427,85 @@
 
 	return _rpc_buffer[0];
 }
+
+int getsockname(int s, struct sockaddr *name, int *namelen)
+{
+	cmd_pkt *pkt = (cmd_pkt *)_rpc_buffer;
+
+	if(!_init_check) return -1;
+
+	pkt->socket = s;
+
+	SifCallRpc(&_ps2ip, ID_GETSOCKNAME, 0, (void*)_rpc_buffer, 4, (void*)_rpc_buffer, sizeof(cmd_pkt), 0, 0);
+
+	if&#40;pkt->len < *namelen&#41; *namelen = pkt->len;
+	memcpy&#40;&#40;void *&#41;name, &#40;void *&#41;&pkt->sockaddr, *namelen&#41;;
+
+	return pkt->socket;
+&#125;
+
+int getpeername&#40;int s, struct sockaddr *name, int *namelen&#41;
+&#123;
+	cmd_pkt *pkt = &#40;cmd_pkt *&#41;_rpc_buffer;
+
+	if&#40;!_init_check&#41; return -1;
+
+	pkt->socket = s;
+
+	SifCallRpc&#40;&_ps2ip, ID_GETPEERNAME, 0, &#40;void*&#41;_rpc_buffer, 4, &#40;void*&#41;_rpc_buffer, sizeof&#40;cmd_pkt&#41;, 0, 0&#41;;
+
+	if&#40;pkt->len < *namelen&#41; *namelen = pkt->len;
+	memcpy&#40;&#40;void *&#41;name, &#40;void *&#41;&pkt->sockaddr, *namelen&#41;;
+
+	return pkt->socket;
+&#125;
+
+// return buffer&#58;
+// Offset 0 = getsockopt return value
+// 0ffset 1 = optlen
+// Offset 2 = optval &#40;max 128 bytes&#41;
+int getsockopt&#40;int s, int level, int optname, void* optval, socklen_t* optlen&#41;
+&#123;
+	&#40;&#40;int*&#41;_rpc_buffer&#41;&#91;0&#93; = s;
+	&#40;&#40;int*&#41;_rpc_buffer&#41;&#91;1&#93; = level;
+	&#40;&#40;int*&#41;_rpc_buffer&#41;&#91;2&#93; = optname;
+
+	SifCallRpc&#40;&_ps2ip, ID_GETSOCKOPT, 0, &#40;void*&#41;_rpc_buffer, 12, &#40;void*&#41;_rpc_buffer, 136, 0, 0&#41;;
+
+	if&#40;_rpc_buffer&#91;1&#93; < *optlen&#41; *optlen = _rpc_buffer&#91;1&#93;;
+	memcpy&#40;&#40;void*&#41;optval, &_rpc_buffer&#91;2&#93;, *optlen&#41;;
+
+	return _rpc_buffer&#91;0&#93;;
+&#125;
+
+int setsockopt&#40;int s, int level, int optname, const void *optval, socklen_t optlen&#41;
+&#123;
+	&#40;&#40;int*&#41;_rpc_buffer&#41;&#91;0&#93; = s;
+	&#40;&#40;int*&#41;_rpc_buffer&#41;&#91;1&#93; = level;
+	&#40;&#40;int*&#41;_rpc_buffer&#41;&#91;2&#93; = optname;
+	&#40;&#40;int*&#41;_rpc_buffer&#41;&#91;3&#93; = optlen;
+
+	memcpy&#40;&_rpc_buffer&#91;4&#93;, optval, optlen&#41;;
+
+	SifCallRpc&#40;&_ps2ip, ID_SETSOCKOPT, 0, &#40;void*&#41;_rpc_buffer, 16 + optlen, &#40;void*&#41;_rpc_buffer, 4, 0, 0&#41;;
+
+	return _rpc_buffer&#91;0&#93;;
+&#125;
+
+int gethostbyname&#40;char *name, struct in_addr *ip&#41;
+&#123;
+	int ret;
+
+	memcpy&#40;_rpc_buffer, name, 256&#41;;
+	SifCallRpc&#40;&_ps2ip, ID_GETHOSTBYNAME, 0, &#40;void*&#41;_rpc_buffer, 256, &#40;void*&#41;_rpc_buffer, 4 + sizeof&#40;struct in_addr&#41;, 0, 0&#41;;
+
+	ret = _rpc_buffer&#91;0&#93;;
+	memcpy&#40;ip, &_rpc_buffer&#91;1&#93;, sizeof&#40;struct in_addr&#41;&#41;;
+
+	return ret;
+&#125;
+
+int ps2ip_dnslookup&#40;char *name, struct in_addr *ip&#41;
+&#123;
+	return gethostbyname&#40;name, ip&#41;;
+&#125;
--- ps2sdk/iop/tcpip/tcpip/include/ps2ip.h	2007-01-18 02&#58;57&#58;58.000000000 +0100
+++ ps2sdksrc/iop/tcpip/tcpip/include/ps2ip.h	2007-01-18 02&#58;43&#58;49.000000000 +0100
@@ -144,3 +144,8 @@
 #define I_ps2ip_input DECLARE_IMPORT&#40;22, ps2ip_input&#41;
 
 #endif /* IOP_PS2IP_H */
+// ntba2
+#define getsockname		lwip_getsockname
+#define getpeername		lwip_getpeername
+#define getsockopt		lwip_getsockopt
+#define setsockopt		lwip_setsockopt
\ No newline at end of file
--- ps2sdk/iop/tcpip/tcpips/src/imports.lst	2007-01-18 02&#58;57&#58;58.000000000 +0100
+++ ps2sdksrc/iop/tcpip/tcpips/src/imports.lst	2007-01-18 02&#58;45&#58;19.000000000 +0100
@@ -41,6 +41,10 @@
 I_lwip_bind
 I_lwip_close
 I_lwip_connect
+I_lwip_getpeername
+I_lwip_getsockname
+I_lwip_getsockopt
+I_lwip_setsockopt
 I_lwip_listen
 I_lwip_recv
 I_lwip_recvfrom
@@ -52,3 +56,7 @@
 I_ps2ip_getconfig
 I_ps2ip_setconfig
 ps2ip_IMPORTS_end
+
+dns_IMPORTS_start
+I_gethostbyname
+dns_IMPORTS_end
\ No newline at end of file
--- ps2sdk/iop/tcpip/tcpips/src/irx_imports.h	2007-01-18 02&#58;57&#58;58.000000000 +0100
+++ ps2sdksrc/iop/tcpip/tcpips/src/irx_imports.h	2007-01-18 02&#58;46&#58;17.000000000 +0100
@@ -17,6 +17,7 @@
 #include "irx.h"
 
 /* Please keep these in alphabetical order!  */
+#include "../../dns/include/dns.h"
 #include "intrman.h"
 #include "ps2ip.h"
 #include "sifcmd.h"
--- ps2sdk/iop/tcpip/tcpips/src/ps2ips.c	2007-01-18 02&#58;57&#58;58.000000000 +0100
+++ ps2sdksrc/iop/tcpip/tcpips/src/ps2ips.c	2007-01-18 02&#58;51&#58;47.000000000 +0100
@@ -31,6 +31,8 @@
 #include <intrman.h>
 #include <ps2ip.h>
 
+#include "../../dns/include/dns.h"
+
 #define PS2IP_IRX 0xB0125F2
 
 #define ID_ACCEPT 1
@@ -47,6 +49,11 @@
 #define ID_GETCONFIG  13
 #define ID_SELECT   14
 #define ID_IOCTL    15
+#define ID_GETSOCKNAME	16
+#define ID_GETPEERNAME	17
+#define ID_GETSOCKOPT	18
+#define ID_SETSOCKOPT	19
+#define ID_GETHOSTBYNAME	20
 
 #define BUFF_SIZE	&#40;1024&#41;
 
@@ -743,7 +750,87 @@
 	ret = ioctlsocket&#40; s, cmd, argp &#41;;
 	ptr&#91;0&#93; = ret;
 &#125;
-
+void do_getsockname&#40; void *rpcBuffer, int size &#41;
+&#123;
+	int *ptr = rpcBuffer;
+	cmd_pkt *pkt = &#40;cmd_pkt *&#41;ptr;
+	struct sockaddr addr;
+	int addrlen, ret;
+
+	ret = getsockname&#40;pkt->socket, &addr, &addrlen&#41;;
+
+	pkt->socket = ret;
+	memcpy&#40;&pkt->sockaddr, &addr, sizeof&#40;struct sockaddr&#41;&#41;;
+	pkt->len = sizeof&#40;struct sockaddr&#41;;
+&#125;
+  
+void do_getpeername&#40; void *rpcBuffer, int size &#41;
+&#123;
+	int *ptr = rpcBuffer;
+	cmd_pkt *pkt = &#40;cmd_pkt *&#41;ptr;
+	struct sockaddr addr;
+	int addrlen, ret;
+
+	ret = getpeername&#40;pkt->socket, &addr, &addrlen&#41;;
+
+	pkt->socket = ret;
+	memcpy&#40;&pkt->sockaddr, &addr, sizeof&#40;struct sockaddr&#41;&#41;;
+	pkt->len = sizeof&#40;struct sockaddr&#41;;
+&#125;
+
+void do_getsockopt&#40; void *rpcBuffer, int size &#41;
+&#123;
+	int *ptr = rpcBuffer, ret;
+	int s;
+	int level;
+	int optname;
+	unsigned char optval&#91;128&#93;;
+	int optlen;
+
+	s		= &#40;&#40;int*&#41;_rpc_buffer&#41;&#91;0&#93;;
+	level	= &#40;&#40;int*&#41;_rpc_buffer&#41;&#91;1&#93;;
+	optname	= &#40;&#40;int*&#41;_rpc_buffer&#41;&#91;2&#93;;
+	optlen	= sizeof&#40;optval&#41;;
+
+	ret = getsockopt&#40;s, level, optname, optval, &optlen&#41;;
+
+	ptr&#91;0&#93; = ret;						// 4
+	ptr&#91;1&#93; = optlen;					// 4
+	memcpy&#40; &ptr&#91;2&#93;, optval, 128 &#41;;		// 128
+
+	// 136 bytes returned
+&#125;
+
+void do_setsockopt&#40; void *rpcBuffer, int size &#41;
+&#123;
+	int *ptr = rpcBuffer, ret;
+	int s;
+	int level;
+	int optname;
+	int optlen;
+	unsigned char optval&#91;128&#93;;
+
+	s		= &#40;&#40;int*&#41;_rpc_buffer&#41;&#91;0&#93;;
+	level	= &#40;&#40;int*&#41;_rpc_buffer&#41;&#91;1&#93;;
+	optname	= &#40;&#40;int*&#41;_rpc_buffer&#41;&#91;2&#93;;
+	optlen	= &#40;&#40;int*&#41;_rpc_buffer&#41;&#91;3&#93;;
+	memcpy&#40;optval, &_rpc_buffer&#91;4&#93;, optlen&#41;;
+
+	ret = setsockopt&#40;s, level, optname, optval, optlen&#41;;
+	ptr&#91;0&#93; = ret;
+&#125;
+
+void do_gethostbyname&#40; void *rpcBuffer, int size &#41;
+&#123;
+	int *ptr = rpcBuffer, ret;
+	struct in_addr addr;
+
+	ret = gethostbyname&#40;&#40;char*&#41;_rpc_buffer, &addr&#41;;
+
+	ptr&#91;0&#93; = ret;
+	memcpy&#40;&ptr&#91;1&#93;, &addr, sizeof&#40;struct in_addr&#41;&#41;;
+&#125;
+
 void * rpcHandlerFunction&#40;unsigned int command, void * rpcBuffer, int size&#41;
 &#123;
 
@@ -791,6 +878,21 @@
   case ID_IOCTL&#58;
 		do_ioctlsocket&#40;rpcBuffer, size&#41;;
 		break;
+  case ID_GETSOCKNAME&#58;
+		do_getsockname&#40;rpcBuffer, size&#41;;
+		break;
+  case ID_GETPEERNAME&#58;
+		do_getpeername&#40;rpcBuffer, size&#41;;
+		break;
+  case ID_GETSOCKOPT&#58;
+		do_getsockopt&#40;rpcBuffer, size&#41;;
+		break;
+  case ID_SETSOCKOPT&#58;
+		do_setsockopt&#40;rpcBuffer, size&#41;;
+		break;
+  case ID_GETHOSTBYNAME&#58;
+		do_gethostbyname&#40;rpcBuffer, size&#41;;
+		break;
   default&#58;
         printf&#40;"PS2IPS&#58; Unknown Function called!\n"&#41;;
 
@@ -850,3 +952,4 @@
   
    return 0;
 &#125; 
+
User avatar
evilo
Posts: 230
Joined: Thu Apr 22, 2004 8:40 pm
Contact:

Post by evilo »

The ntba's libtime (available @ http://www.ntba2.de/) should also make his way into the ps2sdk in order to fully implement time functions from libc.

The lib is almost directly reusable, the only thing IMO would be to check if the library is initialized (timer started) as soon as one of the time function is called. Avoiding to have timer running if you never use them.
User avatar
jbit
Site Admin
Posts: 293
Joined: Sat May 28, 2005 3:11 am
Location: København, Danmark
Contact:

Post by jbit »

I will look into this tomorrow if nobody else does it in the mean time.
Thanks
[22/01] I havn't forgotten about this, just been a little busy, sorry!
user112
Posts: 14
Joined: Tue Apr 11, 2006 5:23 pm

Post by user112 »

Any progress with that?
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

I've added this patch to the repository.

What's the scoop on the other library?
user112
Posts: 14
Joined: Tue Apr 11, 2006 5:23 pm

Post by user112 »

Nice, but I think that it's better to move the definitions inside the IOP_PS2IP_H guards at iop/ps2ip.h.
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Do up a quick patch and I'll change whatever you want. :)
user112
Posts: 14
Joined: Tue Apr 11, 2006 5:23 pm

Post by user112 »

Sorry, but I'm of no help with all that Linux stuff.
radad
Posts: 246
Joined: Wed May 19, 2004 4:54 pm
Location: Melbourne, Australia

Post by radad »

Done.
Post Reply