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

Last change on this file since 2013 was 2013, checked in by achimha, 26 years ago

promoted new wsock32 as default

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