source: trunk/src/wsock32/wsock32.cpp@ 3107

Last change on this file since 3107 was 3107, checked in by sandervl, 25 years ago

changed setsockopt bugfix

File size: 37.6 KB
Line 
1/* $Id: wsock32.cpp,v 1.19 2000-03-14 14:59:43 sandervl Exp $ */
2
3/*
4 *
5 * Project Odin Software License can be found in LICENSE.TXT
6 *
7 * Win32 SOCK32 for OS/2
8 *
9 * Copyright (C) 1999 Patrick Haller <phaller@gmx.net>
10 *
11 */
12
13/* Remark:
14 * 1999/11/21 experimental rewrite using IBM's PMWSock only
15 * -> some structural differences remain! (hostent)
16 * 1999/12/01 experimental rewrite works (TELNET)
17 * -> open issue: WSASetLastError / WSAGetLastError
18 * call SetLastError / GetLastError according to docs
19 *
20 * identical structures:
21 * - sockaddr_in
22 * - WSADATA
23 * - sockaddr
24 * - fd_set
25 * - timeval
26 *
27 * incompatible structures:
28 * - hostent
29 * - netent
30 * - servent
31 * - protent
32 * - linger
33 */
34
35
36/*****************************************************************************
37 * Includes *
38 *****************************************************************************/
39
40#include <pmwsock.h>
41#include <odin.h>
42#include <odinwrap.h>
43#include <os2sel.h>
44#include <misc.h>
45#include <wprocess.h>
46#include <heapstring.h>
47#include <win32wnd.h>
48#include <stdlib.h>
49#include <win32api.h>
50
51#include "wsock32.h"
52#include "relaywin.h"
53
54
55ODINDEBUGCHANNEL(WSOCK32-WSOCK32)
56
57
58/*****************************************************************************
59 * Local variables *
60 *****************************************************************************/
61
62#define ERROR_SUCCESS 0
63
64
65static WSOCKTHREADDATA wstdFallthru; // for emergency only
66
67static HWND hwndRelay = NULL; // handle to our relay window
68
69
70/*****************************************************************************
71 * Prototypes *
72 *****************************************************************************/
73
74/*****************************************************************************
75 * Name :
76 * Purpose :
77 * Parameters:
78 * Variables :
79 * Result :
80 * Remark : free memory when thread dies
81 * Status : UNTESTED STUB
82 *
83 * Author : Patrick Haller [Tue, 1998/06/16 23:00]
84 *****************************************************************************/
85
86PWSOCKTHREADDATA iQueryWsockThreadData(void)
87{
88 struct _THDB* pThreadDB = (struct _THDB*)GetThreadTHDB();
89 PWSOCKTHREADDATA pwstd;
90
91 // check for existing pointer
92 if (pThreadDB != NULL)
93 {
94 if (pThreadDB->pWsockData == NULL)
95 {
96 // allocate on demand + initialize
97 pwstd = (PWSOCKTHREADDATA)HEAP_malloc (sizeof(WSOCKTHREADDATA));
98 pThreadDB->pWsockData = (LPVOID)pwstd;
99 }
100 else
101 // use already allocated memory
102 pwstd = (PWSOCKTHREADDATA)pThreadDB->pWsockData;
103 }
104
105 if (pwstd == NULL)
106 pwstd = &wstdFallthru; // no memory and not allocated already
107
108 return pwstd;
109}
110
111
112#if 0
113/*****************************************************************************
114 * Name :
115 * Purpose :
116 * Parameters:
117 * Variables :
118 * Result :
119 * Remark :
120 * Status : UNTESTED STUB
121 *
122 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
123 *****************************************************************************/
124
125#define CASEERR2(a) case SOC##a: case a: return WSA##a;
126#define CASEERR1(a) case SOC##a: return WSA##a;
127
128int iTranslateSockErrToWSock(int iError)
129{
130 switch(iError)
131 {
132 CASEERR2(EINTR)
133 CASEERR2(EBADF)
134 CASEERR2(EACCES)
135 CASEERR2(EINVAL)
136 CASEERR2(EMFILE)
137
138 CASEERR1(EWOULDBLOCK)
139 CASEERR1(EINPROGRESS)
140 CASEERR1(EALREADY)
141 CASEERR1(ENOTSOCK)
142// CASEERR1(EDESTADRREQ)
143 CASEERR1(EMSGSIZE)
144 CASEERR1(EPROTOTYPE)
145 CASEERR1(ENOPROTOOPT)
146 CASEERR1(EPROTONOSUPPORT)
147 CASEERR1(ESOCKTNOSUPPORT)
148 CASEERR1(EOPNOTSUPP)
149 CASEERR1(EPFNOSUPPORT)
150 CASEERR1(EAFNOSUPPORT)
151 CASEERR1(EADDRINUSE)
152 CASEERR1(EADDRNOTAVAIL)
153 CASEERR1(ENETDOWN)
154 CASEERR1(ENETUNREACH)
155 CASEERR1(ENETRESET)
156 CASEERR1(ECONNABORTED)
157 CASEERR1(ECONNRESET)
158 CASEERR1(ENOBUFS)
159 CASEERR1(EISCONN)
160 CASEERR1(ENOTCONN)
161 CASEERR1(ESHUTDOWN)
162 CASEERR1(ETOOMANYREFS)
163 CASEERR1(ETIMEDOUT)
164 CASEERR1(ECONNREFUSED)
165 CASEERR1(ELOOP)
166 CASEERR1(ENAMETOOLONG)
167 CASEERR1(EHOSTDOWN)
168 CASEERR1(EHOSTUNREACH)
169
170 CASEERR1(ENOTEMPTY)
171// CASEERR(EPROCLIM)
172// CASEERR(EUSERS)
173// CASEERR(EDQUOT)
174// CASEERR(ESTALE)
175// CASEERR(EREMOTE)
176// CASEERR(EDISCON)
177
178
179 default:
180 dprintf(("WSOCK32: Unknown error condition: %d\n",
181 iError));
182 return iError;
183 }
184}
185
186#endif
187
188
189
190
191
192
193
194/*****************************************************************************
195 * Name :
196 * Purpose :
197 * Parameters:
198 * Variables :
199 * Result :
200 * Remark :
201 * Status : UNTESTED STUB
202 *
203 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
204 *****************************************************************************/
205
206
207ODINPROCEDURE1(OS2WSASetLastError,
208 int,iError)
209{
210 // according to the docs, WSASetLastError() is just a call-through
211 // to SetLastError()
212 WSASetLastError(iError);
213 SetLastError(iError);
214}
215
216
217/*****************************************************************************
218 * Name :
219 * Purpose :
220 * Parameters:
221 * Variables :
222 * Result :
223 * Remark :
224 * Status : UNTESTED STUB
225 *
226 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
227 *****************************************************************************/
228
229ODINFUNCTION0(int,OS2WSAGetLastError)
230{
231 // according to the docs, WSASetLastError() is just a call-through
232 // to SetLastError(). However, what can be implemented here?
233 return WSAGetLastError();
234}
235
236
237/*****************************************************************************
238 * Name :
239 * Purpose :
240 * Parameters:
241 * Variables :
242 * Result :
243 * Remark :
244 * Status : UNTESTED STUB
245 *
246 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
247 *****************************************************************************/
248
249ODINFUNCTION2(int,OS2__WSAFDIsSet,SOCKET, s,
250 fd_set*,fds)
251{
252 return (__WSAFDIsSet(s,fds));
253}
254
255
256/*****************************************************************************
257 * Name :
258 * Purpose :
259 * Parameters:
260 * Variables :
261 * Result :
262 * Remark :
263 * Status : UNTESTED STUB
264 *
265 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
266 *****************************************************************************/
267
268ODINFUNCTION3(SOCKET,OS2accept, SOCKET, s,
269 struct sockaddr *,addr,
270 int *, addrlen)
271{
272 return(accept(s,addr,addrlen));
273}
274
275
276/*****************************************************************************
277 * Name :
278 * Purpose :
279 * Parameters:
280 * Variables :
281 * Result :
282 * Remark :
283 * Status : UNTESTED STUB
284 *
285 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
286 *****************************************************************************/
287
288ODINFUNCTION3(int,OS2bind,
289 SOCKET ,s,
290 const struct sockaddr *,addr,
291 int, namelen)
292{
293 return(bind(s,addr,namelen));
294}
295
296
297/*****************************************************************************
298 * Name :
299 * Purpose :
300 * Parameters:
301 * Variables :
302 * Result :
303 * Remark :
304 * Status : UNTESTED STUB
305 *
306 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
307 *****************************************************************************/
308
309ODINFUNCTION1(int,OS2closesocket,SOCKET, s)
310{
311 return(closesocket(s));
312}
313
314
315/*****************************************************************************
316 * Name :
317 * Purpose :
318 * Parameters:
319 * Variables :
320 * Result :
321 * Remark :
322 * Status : UNTESTED STUB
323 *
324 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
325 *****************************************************************************/
326
327ODINFUNCTION3(int,OS2connect,
328 SOCKET, s,
329 const struct sockaddr *,name,
330 int, namelen)
331{
332 return(connect(s,name,namelen));
333}
334
335
336/*****************************************************************************
337 * Name :
338 * Purpose :
339 * Parameters:
340 * Variables :
341 * Result :
342 * Remark :
343 * Status : UNTESTED STUB
344 *
345 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
346 *****************************************************************************/
347
348ODINFUNCTION3(int,OS2ioctlsocket,
349 SOCKET,s,
350 long, cmd,
351 u_long *,argp)
352{
353 return(ioctlsocket(s,cmd,argp));
354}
355
356
357/*****************************************************************************
358 * Name :
359 * Purpose :
360 * Parameters:
361 * Variables :
362 * Result :
363 * Remark :
364 * Status : UNTESTED STUB
365 *
366 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
367 *****************************************************************************/
368
369ODINFUNCTION3(int,OS2getpeername,
370 SOCKET, s,
371 struct sockaddr *,name,
372 int *, namelen)
373{
374 return(getpeername(s,name,namelen));
375}
376
377
378/*****************************************************************************
379 * Name :
380 * Purpose :
381 * Parameters:
382 * Variables :
383 * Result :
384 * Remark :
385 * Status : UNTESTED STUB
386 *
387 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
388 *****************************************************************************/
389
390ODINFUNCTION3(int,OS2getsockname,
391 SOCKET,s,
392 struct sockaddr *,name,
393 int *, namelen)
394{
395 return(getsockname(s,name,namelen));
396}
397
398
399/*****************************************************************************
400 * Name :
401 * Purpose :
402 * Parameters:
403 * Variables :
404 * Result :
405 * Remark :
406 * Status : UNTESTED STUB
407 *
408 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
409 *****************************************************************************/
410
411ODINFUNCTION5(int,OS2getsockopt,
412 SOCKET, s,
413 int, level,
414 int, optname,
415 char *, optval,
416 int *,optlen)
417{
418 return(getsockopt(s,
419 level,
420 optname,
421 optval,
422 optlen));
423}
424
425
426/*****************************************************************************
427 * Name :
428 * Purpose :
429 * Parameters:
430 * Variables :
431 * Result :
432 * Remark :
433 * Status : UNTESTED STUB
434 *
435 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
436 *****************************************************************************/
437
438ODINFUNCTION1(u_long,OS2htonl,
439 u_long,hostlong)
440{
441 return(htonl(hostlong));
442}
443
444
445/*****************************************************************************
446 * Name :
447 * Purpose :
448 * Parameters:
449 * Variables :
450 * Result :
451 * Remark :
452 * Status : UNTESTED STUB
453 *
454 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
455 *****************************************************************************/
456
457ODINFUNCTION1(u_short,OS2htons,
458 u_short,hostshort)
459{
460 return(htons(hostshort));
461}
462
463
464/*****************************************************************************
465 * Name :
466 * Purpose :
467 * Parameters:
468 * Variables :
469 * Result :
470 * Remark :
471 * Status : UNTESTED STUB
472 *
473 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
474 *****************************************************************************/
475
476ODINFUNCTION1(unsigned long,OS2inet_addr,
477 const char *, cp)
478{
479 dprintf(("WSOCK32: OS2inet_addr(%s)\n",
480 cp));
481
482 return (inet_addr(cp));
483}
484
485
486/*****************************************************************************
487 * Name :
488 * Purpose :
489 * Parameters:
490 * Variables :
491 * Result :
492 * Remark :
493 * Status : UNTESTED STUB
494 *
495 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
496 *****************************************************************************/
497
498ODINFUNCTION1(char *,OS2inet_ntoa,
499 struct in_addr, in)
500{
501 return(inet_ntoa(in));
502}
503
504
505/*****************************************************************************
506 * Name :
507 * Purpose :
508 * Parameters:
509 * Variables :
510 * Result :
511 * Remark :
512 * Status : UNTESTED STUB
513 *
514 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
515 *****************************************************************************/
516
517ODINFUNCTION2(int,OS2listen,
518 SOCKET, s,
519 int, backlog)
520{
521 return(listen(s,backlog));
522}
523
524
525/*****************************************************************************
526 * Name :
527 * Purpose :
528 * Parameters:
529 * Variables :
530 * Result :
531 * Remark :
532 * Status : UNTESTED STUB
533 *
534 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
535 *****************************************************************************/
536
537ODINFUNCTION1(u_long,OS2ntohl,
538 u_long,netlong)
539{
540 return(ntohl(netlong));
541}
542
543
544/*****************************************************************************
545 * Name :
546 * Purpose :
547 * Parameters:
548 * Variables :
549 * Result :
550 * Remark :
551 * Status : UNTESTED STUB
552 *
553 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
554 *****************************************************************************/
555
556ODINFUNCTION1(u_short,OS2ntohs,
557 u_short,netshort)
558{
559 return(ntohs(netshort));
560}
561
562
563/*****************************************************************************
564 * Name :
565 * Purpose :
566 * Parameters:
567 * Variables :
568 * Result :
569 * Remark :
570 * Status : UNTESTED STUB
571 *
572 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
573 *****************************************************************************/
574
575ODINFUNCTION4(int,OS2recv,
576 SOCKET,s,
577 char *,buf,
578 int,len,
579 int,flags)
580{
581 return(recv(s,
582 buf,
583 len,
584 flags));
585}
586
587
588/*****************************************************************************
589 * Name :
590 * Purpose :
591 * Parameters:
592 * Variables :
593 * Result :
594 * Remark :
595 * Status : UNTESTED STUB
596 *
597 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
598 *****************************************************************************/
599
600ODINFUNCTION6(int,OS2recvfrom,
601 SOCKET,s,
602 char *,buf,
603 int,len,
604 int,flags,
605 struct sockaddr *,from,
606 int *,fromlen)
607{
608
609 return(recvfrom(s,
610 buf,
611 len,
612 flags,
613 from,
614 fromlen));
615}
616
617
618/*****************************************************************************
619 * Name :
620 * Purpose :
621 * Parameters:
622 * Variables :
623 * Result :
624 * Remark :
625 * Status : UNTESTED STUB
626 *
627 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
628 *****************************************************************************/
629
630ODINFUNCTION5(int,OS2select,
631 int,nfds,
632 fd_set *,readfds,
633 fd_set *,writefds,
634 fd_set *,exceptfds,
635 const struct timeval *,timeout)
636{
637 return(select(nfds,
638 readfds,
639 writefds,
640 exceptfds,
641 timeout));
642}
643
644
645/*****************************************************************************
646 * Name :
647 * Purpose :
648 * Parameters:
649 * Variables :
650 * Result :
651 * Remark :
652 * Status : UNTESTED STUB
653 *
654 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
655 *****************************************************************************/
656
657ODINFUNCTION4(int,OS2send,
658 SOCKET,s,
659 const char *,buf,
660 int,len,
661 int,flags)
662{
663 return(send(s,
664 buf,
665 len,
666 flags));
667}
668
669
670/*****************************************************************************
671 * Name :
672 * Purpose :
673 * Parameters:
674 * Variables :
675 * Result :
676 * Remark :
677 * Status : UNTESTED STUB
678 *
679 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
680 *****************************************************************************/
681
682ODINFUNCTION6(int,OS2sendto,
683 SOCKET,s,
684 const char *,buf,
685 int,len,
686 int,flags,
687 const struct sockaddr *,to,
688 int,tolen)
689{
690 return(sendto(s,
691 buf,
692 len,
693 flags,
694 to,
695 tolen));
696}
697
698
699/*****************************************************************************
700 * Name :
701 * Purpose :
702 * Parameters:
703 * Variables :
704 * Result :
705 * Remark :
706 * Status : UNTESTED STUB
707 *
708 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
709 *****************************************************************************/
710
711ODINFUNCTION5(int,OS2setsockopt,
712 SOCKET,s,
713 int,level,
714 int,optname,
715 const char *,optval,
716 int,optlen)
717{
718 struct Wlinger *yy;
719 struct linger xx;
720 int rc;
721
722 if(level == SOL_SOCKET &&
723 optname == SO_LINGER)
724 {
725 yy = (struct Wlinger *)optval;
726 xx.l_onoff = (int)yy->l_onoff;
727 xx.l_linger = (int)yy->l_linger;
728
729 rc = setsockopt(s,level,optname,(char *)&xx, sizeof(xx));
730 }
731 else
732 if(level == SOL_SOCKET && (optname == SO_SNDBUF || optname == SO_RCVBUF)) {
733 ULONG size;
734
735 size = *(ULONG *)optval;
736tryagain:
737 rc = setsockopt(s,level,optname, (char *)&size, sizeof(ULONG));
738 if(rc == SOCKET_ERROR && size > 65535) {
739 //SvL: Limit send & receive buffer length to 64k
740 // (only happens with 16 bits tcpip stack?)
741 size = 65000;
742 goto tryagain;
743 }
744
745 }
746 else {
747 rc = setsockopt(s,level,optname,(char *)optval,optlen);
748 }
749
750 if (rc == SOCKET_ERROR)
751 //OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno()));
752 OS2WSASetLastError(WSAEINVAL);
753 else
754 OS2WSASetLastError(ERROR_SUCCESS);
755
756 return rc;
757}
758
759
760/*****************************************************************************
761 * Name :
762 * Purpose :
763 * Parameters:
764 * Variables :
765 * Result :
766 * Remark :
767 * Status : UNTESTED STUB
768 *
769 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
770 *****************************************************************************/
771
772ODINFUNCTION2(int,OS2shutdown,
773 SOCKET,s,
774 int,how)
775{
776 return(shutdown(s,
777 how));
778}
779
780
781/*****************************************************************************
782 * Name :
783 * Purpose :
784 * Parameters:
785 * Variables :
786 * Result :
787 * Remark :
788 * Status : UNTESTED STUB
789 *
790 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
791 *****************************************************************************/
792
793ODINFUNCTION3(SOCKET,OS2socket,
794 int,af,
795 int,type,
796 int,protocol)
797{
798 return(socket(af,
799 type,
800 protocol));
801}
802
803
804/* Database function prototypes */
805
806/*****************************************************************************
807 * Name :
808 * Purpose :
809 * Parameters:
810 * Variables :
811 * Result :
812 * Remark :
813 * Status : UNTESTED STUB
814 *
815 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
816 *****************************************************************************/
817
818ODINFUNCTION3(struct Whostent *,OS2gethostbyaddr,
819 const char *,addr,
820 int,len,
821 int,type)
822{
823 WHOSTENT *yy;
824 struct hostent *xx;
825 PWSOCKTHREADDATA pwstd;
826
827 xx = gethostbyaddr((char *)addr,len,type);
828 //PH: we assume PMWSOCK sets WSASetLastError correctly!
829
830 if(xx == NULL)
831 return (WHOSTENT *)NULL;
832
833 // access current thread wsock data block
834 pwstd = iQueryWsockThreadData();
835
836 pwstd->whsnt.h_name = xx->h_name;
837 pwstd->whsnt.h_aliases = xx->h_aliases;
838 pwstd->whsnt.h_addrtype = (short)xx->h_addrtype;
839 pwstd->whsnt.h_length = (short)xx->h_length;
840 pwstd->whsnt.h_addr_list = xx->h_addr_list;
841
842 return &pwstd->whsnt;
843}
844
845
846/*****************************************************************************
847 * Name :
848 * Purpose :
849 * Parameters:
850 * Variables :
851 * Result :
852 * Remark :
853 * Status : UNTESTED STUB
854 *
855 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
856 *****************************************************************************/
857
858ODINFUNCTION1(struct Whostent *,OS2gethostbyname,
859 const char *,name)
860{
861 WHOSTENT *yy;
862 struct hostent *xx;
863 PWSOCKTHREADDATA pwstd;
864
865
866 xx = gethostbyname((char *)name);
867 //PH: we assume PMWSOCK sets WSASetLastError correctly!
868
869 if(xx == NULL)
870 return (WHOSTENT *)NULL;
871
872 // access current thread wsock data block
873 pwstd = iQueryWsockThreadData();
874
875 pwstd->whsnt.h_name = xx->h_name;
876 pwstd->whsnt.h_aliases = xx->h_aliases;
877 pwstd->whsnt.h_addrtype = (short)xx->h_addrtype;
878 pwstd->whsnt.h_length = (short)xx->h_length;
879 pwstd->whsnt.h_addr_list = xx->h_addr_list;
880
881 return &pwstd->whsnt;
882}
883
884
885/*****************************************************************************
886 * Name :
887 * Purpose :
888 * Parameters:
889 * Variables :
890 * Result :
891 * Remark :
892 * Status : UNTESTED STUB
893 *
894 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
895 *****************************************************************************/
896
897ODINFUNCTION2(int,OS2gethostname,
898 char *,name,
899 int,namelen)
900{
901 //PH: we assume PMWSOCK sets WSASetLastError correctly!
902 return(gethostname(name,
903 namelen));
904}
905
906
907/*****************************************************************************
908 * Name :
909 * Purpose :
910 * Parameters:
911 * Variables :
912 * Result :
913 * Remark :
914 * Status : UNTESTED STUB
915 *
916 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
917 *****************************************************************************/
918
919ODINFUNCTION2(struct Wservent *,OS2getservbyport,
920 int, port,
921 const char *, proto)
922{
923 struct servent *xx;
924 PWSOCKTHREADDATA pwstd;
925
926 //PH: we assume PMWSOCK sets WSASetLastError correctly!
927 xx = getservbyport(port,(char *)proto);
928
929 if(xx == NULL)
930 return (WSERVENT *)NULL;
931
932 // access current thread wsock data block
933 pwstd = iQueryWsockThreadData();
934
935 pwstd->wsvnt.s_name = xx->s_name;
936 pwstd->wsvnt.s_aliases = xx->s_aliases;
937 pwstd->wsvnt.s_port = (short)xx->s_port;
938 pwstd->wsvnt.s_proto = xx->s_proto;
939
940 return &pwstd->wsvnt;
941}
942
943
944/*****************************************************************************
945 * Name :
946 * Purpose :
947 * Parameters:
948 * Variables :
949 * Result :
950 * Remark :
951 * Status : UNTESTED STUB
952 *
953 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
954 *****************************************************************************/
955
956ODINFUNCTION2(struct Wservent *,OS2getservbyname,
957 const char *, name,
958 const char *, proto)
959{
960 WSERVENT *yy;
961 struct servent *xx;
962 PWSOCKTHREADDATA pwstd;
963
964
965 //PH: we assume PMWSOCK sets WSASetLastError correctly!
966 xx = getservbyname((char *)name,(char *)proto);
967
968 if(xx == NULL)
969 return (WSERVENT *)NULL;
970
971 // access current thread wsock data block
972 pwstd = iQueryWsockThreadData();
973
974 pwstd->wsvnt.s_name = xx->s_name;
975 pwstd->wsvnt.s_aliases = xx->s_aliases;
976 pwstd->wsvnt.s_port = (short)xx->s_port;
977 pwstd->wsvnt.s_proto = xx->s_proto;
978
979 return &pwstd->wsvnt;
980}
981
982
983/*****************************************************************************
984 * Name :
985 * Purpose :
986 * Parameters:
987 * Variables :
988 * Result :
989 * Remark :
990 * Status : UNTESTED STUB
991 *
992 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
993 *****************************************************************************/
994
995ODINFUNCTION1(struct Wprotoent *,OS2getprotobynumber,
996 int,proto)
997{
998 struct protoent *xx;
999 PWSOCKTHREADDATA pwstd;
1000
1001 //PH: we assume PMWSOCK sets WSASetLastError correctly!
1002 xx = getprotobynumber(proto);
1003
1004 if(xx == NULL)
1005 return (WPROTOENT *)NULL;
1006
1007 // access current thread wsock data block
1008 pwstd = iQueryWsockThreadData();
1009
1010 pwstd->wptnt.p_name = xx->p_name;
1011 pwstd->wptnt.p_aliases = xx->p_aliases;
1012 pwstd->wptnt.p_proto = (short)xx->p_proto;
1013
1014 return &pwstd->wptnt;
1015}
1016
1017
1018/*****************************************************************************
1019 * Name :
1020 * Purpose :
1021 * Parameters:
1022 * Variables :
1023 * Result :
1024 * Remark :
1025 * Status : UNTESTED STUB
1026 *
1027 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1028 *****************************************************************************/
1029
1030ODINFUNCTION1(struct Wprotoent *,OS2getprotobyname,
1031 const char *,name)
1032{
1033 struct protoent *xx;
1034 PWSOCKTHREADDATA pwstd;
1035
1036 //PH: we assume PMWSOCK sets WSASetLastError correctly!
1037 xx = getprotobyname((char *)name);
1038
1039 if(xx == NULL)
1040 return (WPROTOENT *)NULL;
1041
1042 // access current thread wsock data block
1043 pwstd = iQueryWsockThreadData();
1044
1045 pwstd->wptnt.p_name = xx->p_name;
1046 pwstd->wptnt.p_aliases = xx->p_aliases;
1047 pwstd->wptnt.p_proto = (short)xx->p_proto;
1048
1049 return &pwstd->wptnt;
1050}
1051
1052
1053
1054/* Microsoft Windows Extension function prototypes */
1055
1056/*****************************************************************************
1057 * Name :
1058 * Purpose :
1059 * Parameters:
1060 * Variables :
1061 * Result :
1062 * Remark :
1063 * Status : UNTESTED STUB
1064 *
1065 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1066 *****************************************************************************/
1067
1068ODINFUNCTION2(int,OS2WSAStartup,
1069 USHORT,wVersionRequired,
1070 LPWSADATA,lpWSAData)
1071{
1072 return(WSAStartup(wVersionRequired,
1073 lpWSAData));
1074}
1075
1076
1077/*****************************************************************************
1078 * Name :
1079 * Purpose :
1080 * Parameters:
1081 * Variables :
1082 * Result :
1083 * Remark :
1084 * Status : UNTESTED STUB
1085 *
1086 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1087 *****************************************************************************/
1088
1089ODINFUNCTION0(int,OS2WSACleanup)
1090{
1091 return(WSACleanup());
1092}
1093
1094
1095/*****************************************************************************
1096 * Name :
1097 * Purpose :
1098 * Parameters:
1099 * Variables :
1100 * Result :
1101 * Remark :
1102 * Status : UNTESTED STUB
1103 *
1104 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1105 *****************************************************************************/
1106
1107ODINFUNCTION0(BOOL,OS2WSAIsBlocking)
1108{
1109 return WSAIsBlocking();
1110}
1111
1112
1113/*****************************************************************************
1114 * Name :
1115 * Purpose :
1116 * Parameters:
1117 * Variables :
1118 * Result :
1119 * Remark :
1120 * Status : UNTESTED STUB
1121 *
1122 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1123 *****************************************************************************/
1124
1125ODINFUNCTION0(int,OS2WSAUnhookBlockingHook)
1126{
1127 return WSAUnhookBlockingHook();
1128}
1129
1130
1131/*****************************************************************************
1132 * Name :
1133 * Purpose :
1134 * Parameters:
1135 * Variables :
1136 * Result :
1137 * Remark :
1138 * Status : UNTESTED STUB
1139 *
1140 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1141 *****************************************************************************/
1142
1143ODINFUNCTION1(PFN,OS2WSASetBlockingHook,
1144 PFN,lpBlockFunc)
1145{
1146 return(WSASetBlockingHook(lpBlockFunc));
1147}
1148
1149
1150/*****************************************************************************
1151 * Name :
1152 * Purpose :
1153 * Parameters:
1154 * Variables :
1155 * Result :
1156 * Remark :
1157 * Status : UNTESTED STUB
1158 *
1159 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1160 *****************************************************************************/
1161
1162ODINFUNCTION0(int,OS2WSACancelBlockingCall)
1163{
1164 return(WSACancelBlockingCall());
1165}
1166
1167
1168/*****************************************************************************
1169 * Name :
1170 * Purpose :
1171 * Parameters:
1172 * Variables :
1173 * Result :
1174 * Remark :
1175 * Status : UNTESTED STUB
1176 *
1177 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1178 *****************************************************************************/
1179
1180ODINFUNCTION6(LHANDLE,OS2WSAAsyncGetServByName,
1181 HWND,hWnd,
1182 u_int,wMsg,
1183 const char *,name,
1184 const char *,proto,
1185 char *,buf,
1186 int,buflen)
1187{
1188 int rc;
1189 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1190 ULONG ulNewID;
1191
1192 if (hwndRelay == NULL) // already initialized ?
1193 hwndRelay = RelayInitialize(hwndOS2);
1194
1195 // add entry to list, we need to store both our temp buffer and the apps buffer
1196 ulNewID = RelayAlloc(hWnd,
1197 wMsg,
1198 ASYNCREQUEST_GETSERVBYNAME,
1199 FALSE,
1200 buf);
1201
1202 // call pmwsock function, will fill our temp buffer
1203 rc = WSAAsyncGetServByName(hwndRelay,
1204 ulNewID,
1205 name,
1206 proto,
1207 buf,
1208 buflen);
1209
1210 // if an error occurs, free the allocated relay entry
1211 if (rc == SOCKET_ERROR)
1212 RelayFree(ulNewID);
1213
1214 return (rc);
1215}
1216
1217
1218/*****************************************************************************
1219 * Name :
1220 * Purpose :
1221 * Parameters:
1222 * Variables :
1223 * Result :
1224 * Remark :
1225 * Status : UNTESTED STUB
1226 *
1227 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1228 *****************************************************************************/
1229
1230ODINFUNCTION6(LHANDLE,OS2WSAAsyncGetServByPort,
1231 HWND,hWnd,
1232 u_int,wMsg,
1233 int,port,
1234 const char *,proto,
1235 char *,buf,
1236 int,buflen)
1237{
1238 int rc;
1239 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1240 ULONG ulNewID;
1241
1242 if (hwndRelay == NULL) // already initialized ?
1243 hwndRelay = RelayInitialize(hwndOS2);
1244
1245 // add entry to list, we need to store both our temp buffer and the apps buffer
1246 ulNewID = RelayAlloc(hWnd,
1247 wMsg,
1248 ASYNCREQUEST_GETSERVBYPORT,
1249 FALSE,
1250 buf);
1251
1252 // call pmwsock function, will fill our temp buffer
1253 rc = WSAAsyncGetServByPort(hwndRelay,
1254 ulNewID,
1255 port,
1256 proto,
1257 buf,
1258 buflen);
1259
1260 // if an error occurs, free the allocated relay entry
1261 if (rc == SOCKET_ERROR)
1262 RelayFree(ulNewID);
1263
1264 return rc;
1265}
1266
1267
1268/*****************************************************************************
1269 * Name :
1270 * Purpose :
1271 * Parameters:
1272 * Variables :
1273 * Result :
1274 * Remark :
1275 * Status : UNTESTED STUB
1276 *
1277 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1278 *****************************************************************************/
1279
1280ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetProtoByName,
1281 HWND,hWnd,
1282 u_int,wMsg,
1283 const char *,name,
1284 char *,buf,
1285 int,buflen)
1286{
1287 int rc;
1288 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1289 ULONG ulNewID;
1290
1291 if (hwndRelay == NULL) // already initialized ?
1292 hwndRelay = RelayInitialize(hwndOS2);
1293
1294 // add entry to list, we need to store both our temp buffer and the apps buffer
1295 ulNewID = RelayAlloc(hWnd,
1296 wMsg,
1297 ASYNCREQUEST_GETPROTOBYNAME,
1298 FALSE,
1299 buf);
1300
1301 // call pmwsock function, will fill our temp buffer
1302 rc = WSAAsyncGetProtoByName(hwndRelay,
1303 ulNewID,
1304 name,
1305 buf,
1306 buflen);
1307
1308 // if an error occurs, free the allocated relay entry
1309 if (rc == SOCKET_ERROR)
1310 RelayFree(ulNewID);
1311
1312 return (rc);
1313}
1314
1315
1316/*****************************************************************************
1317 * Name :
1318 * Purpose :
1319 * Parameters:
1320 * Variables :
1321 * Result :
1322 * Remark :
1323 * Status : UNTESTED STUB
1324 *
1325 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1326 *****************************************************************************/
1327
1328ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetProtoByNumber,
1329 HWND,hWnd,
1330 u_int,wMsg,
1331 int,number,
1332 char *,buf,
1333 int,buflen)
1334{
1335 int rc;
1336 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1337 ULONG ulNewID;
1338
1339 if (hwndRelay == NULL) // already initialized ?
1340 hwndRelay = RelayInitialize(hwndOS2);
1341
1342 // add entry to list, we need to store both our temp buffer and the apps buffer
1343 ulNewID = RelayAlloc(hWnd,
1344 wMsg,
1345 ASYNCREQUEST_GETPROTOBYNUMBER,
1346 FALSE,
1347 buf);
1348
1349 // call pmwsock function, will fill our temp buffer
1350 rc = WSAAsyncGetProtoByNumber(hwndRelay,
1351 ulNewID,
1352 number,
1353 buf,
1354 buflen);
1355
1356 // if an error occurs, free the allocated relay entry
1357 if (rc == SOCKET_ERROR)
1358 RelayFree(ulNewID);
1359
1360 return rc;
1361}
1362
1363
1364/*****************************************************************************
1365 * Name :
1366 * Purpose :
1367 * Parameters:
1368 * Variables :
1369 * Result :
1370 * Remark :
1371 * Status : UNTESTED STUB
1372 *
1373 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1374 *****************************************************************************/
1375
1376ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetHostByName,
1377 HWND,hWnd,
1378 u_int,wMsg,
1379 const char *,name,
1380 char *,buf,
1381 int,buflen)
1382{
1383 int rc;
1384 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1385 ULONG ulNewID;
1386
1387 dprintf(("WSAAsyncGetHostByName %s", name));
1388
1389 if (hwndRelay == NULL) // already initialized ?
1390 hwndRelay = RelayInitialize(hwndOS2);
1391
1392 // add entry to list, we need to store both our temp buffer and the apps buffer
1393 ulNewID = RelayAlloc(hWnd,
1394 wMsg,
1395 ASYNCREQUEST_GETHOSTBYNAME,
1396 FALSE,
1397 (PVOID)buf, (PVOID)buflen);
1398
1399 // call pmwsock function, will fill our temp buffer
1400 rc = WSAAsyncGetHostByName(hwndRelay,
1401 ulNewID,
1402 name,
1403 buf,
1404 buflen);
1405
1406 // if an error occurs, free the allocated relay entry
1407 if (rc == SOCKET_ERROR)
1408 RelayFree(ulNewID);
1409
1410 return rc;
1411}
1412
1413
1414/*****************************************************************************
1415 * Name :
1416 * Purpose :
1417 * Parameters:
1418 * Variables :
1419 * Result :
1420 * Remark :
1421 * Status : UNTESTED STUB
1422 *
1423 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1424 *****************************************************************************/
1425
1426ODINFUNCTION7(LHANDLE,OS2WSAAsyncGetHostByAddr,
1427 HWND,hWnd,
1428 u_int,wMsg,
1429 const char *,addr,
1430 int,len,
1431 int,type,
1432 char *,buf,
1433 int,buflen)
1434{
1435 int rc;
1436 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1437 ULONG ulNewID;
1438
1439 if (hwndRelay == NULL) // already initialized ?
1440 hwndRelay = RelayInitialize(hwndOS2);
1441
1442 // add entry to list, we need to store both our temp buffer and the apps buffer
1443 ulNewID = RelayAlloc(hWnd,
1444 wMsg,
1445 ASYNCREQUEST_GETHOSTBYADDR,
1446 FALSE,
1447 buf);
1448
1449 // call pmwsock function, will fill our temp buffer
1450 rc = WSAAsyncGetHostByAddr(hwndRelay,
1451 ulNewID,
1452 addr,
1453 len,
1454 type,
1455 buf,
1456 buflen);
1457
1458 // if an error occurs, free the allocated relay entry
1459 if (rc == SOCKET_ERROR)
1460 RelayFree(ulNewID);
1461
1462 return (rc);
1463}
1464
1465
1466/*****************************************************************************
1467 * Name :
1468 * Purpose :
1469 * Parameters:
1470 * Variables :
1471 * Result :
1472 * Remark :
1473 * Status : UNTESTED STUB
1474 *
1475 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1476 *****************************************************************************/
1477
1478ODINFUNCTION1(int,OS2WSACancelAsyncRequest,
1479 LHANDLE,hAsyncTaskHandle)
1480{
1481 return(WSACancelAsyncRequest(hAsyncTaskHandle));
1482}
1483
1484
1485/*****************************************************************************
1486 * Name :
1487 * Purpose :
1488 * Parameters:
1489 * Variables :
1490 * Result :
1491 * Remark :
1492 * Status : UNTESTED STUB
1493 *
1494 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1495 *****************************************************************************/
1496
1497ODINFUNCTION4(int,OS2WSAAsyncSelect,
1498 SOCKET,s,
1499 HWND,hWnd,
1500 u_int,wMsg,
1501 long,lEvent)
1502{
1503 int rc;
1504// int iError;
1505 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1506 ULONG ulNewID;
1507
1508 if (hwndRelay == NULL) // already initialized ?
1509 hwndRelay = RelayInitialize(hwndOS2);
1510
1511 /* @@@PH: our source window doesn't seem to have an anchor block.
1512 Docs suggest we've missed to call WinInitialize on the
1513 caller thread.
1514
1515 Cause however is the Open32 handle is (of course!) invalid
1516 in plain PM Window Manager! -> use DAPWSOCK
1517
1518 Unfortunately, DAPWSOCK calls WinQueryAnchorBlock(hOpen32), too.
1519 So, we're stuck until I resolve hWnd to it's valid PM
1520 counterpart.
1521
1522 new problem: we've ultimately got to use PostMessageA instead
1523 anything else. => create invisible msg relay window:
1524 - hMsg = registerMessage(hWnd, wMsg)
1525 - call WSAAsyncSelect with object window handle
1526 - overwrite hWnd relay for "same handles"
1527 */
1528
1529 // add event to list or remove any list entry in case of WSAAsyncSelect(hwnd,0,0)
1530 if ( (wMsg == 0) && (lEvent == 0) )
1531 {
1532 // remove entry from list
1533 RelayFreeByHwnd(hWnd);
1534 }
1535 else
1536 // add entry to list
1537 ulNewID = RelayAlloc(hWnd,
1538 wMsg,
1539 ASYNCREQUEST_SELECT,
1540 TRUE);
1541
1542 rc = WSAAsyncSelect(s,
1543 hwndRelay,
1544 ulNewID,
1545 lEvent);
1546
1547// iError = WSAGetLastError();
1548// dprintf(("res=%d, err=%d\n",
1549// rc,
1550// iError));
1551 return (rc);
1552}
Note: See TracBrowser for help on using the repository browser.