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

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

Fixed bug in setsockopt for SO_SNDBUF/SO_RCVBUF

File size: 37.4 KB
Line 
1/* $Id: wsock32.cpp,v 1.18 2000-03-13 20:32:24 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
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, sizeof(xx));
732 }
733 else
734 if(level == SOL_SOCKET && (optname == SO_SNDBUF || optname == SO_RCVBUF)) {
735 ULONG size;
736
737 //SvL: Limit send & receive buffer length to 64k
738 size = min(*(ULONG *)optval, 65000);
739 rc = setsockopt(s,level,optname, (char *)&size,optlen);
740 }
741 else {
742 rc = setsockopt(s,level,optname,(char *)optval,optlen);
743 }
744
745 if (rc == SOCKET_ERROR)
746 //OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno()));
747 OS2WSASetLastError(WSAEINVAL);
748 else
749 OS2WSASetLastError(ERROR_SUCCESS);
750
751 return rc;
752}
753
754
755/*****************************************************************************
756 * Name :
757 * Purpose :
758 * Parameters:
759 * Variables :
760 * Result :
761 * Remark :
762 * Status : UNTESTED STUB
763 *
764 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
765 *****************************************************************************/
766
767ODINFUNCTION2(int,OS2shutdown,
768 SOCKET,s,
769 int,how)
770{
771 return(shutdown(s,
772 how));
773}
774
775
776/*****************************************************************************
777 * Name :
778 * Purpose :
779 * Parameters:
780 * Variables :
781 * Result :
782 * Remark :
783 * Status : UNTESTED STUB
784 *
785 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
786 *****************************************************************************/
787
788ODINFUNCTION3(SOCKET,OS2socket,
789 int,af,
790 int,type,
791 int,protocol)
792{
793 return(socket(af,
794 type,
795 protocol));
796}
797
798
799/* Database function prototypes */
800
801/*****************************************************************************
802 * Name :
803 * Purpose :
804 * Parameters:
805 * Variables :
806 * Result :
807 * Remark :
808 * Status : UNTESTED STUB
809 *
810 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
811 *****************************************************************************/
812
813ODINFUNCTION3(struct Whostent *,OS2gethostbyaddr,
814 const char *,addr,
815 int,len,
816 int,type)
817{
818 WHOSTENT *yy;
819 struct hostent *xx;
820 PWSOCKTHREADDATA pwstd;
821
822 xx = gethostbyaddr((char *)addr,len,type);
823 //PH: we assume PMWSOCK sets WSASetLastError correctly!
824
825 if(xx == NULL)
826 return (WHOSTENT *)NULL;
827
828 // access current thread wsock data block
829 pwstd = iQueryWsockThreadData();
830
831 pwstd->whsnt.h_name = xx->h_name;
832 pwstd->whsnt.h_aliases = xx->h_aliases;
833 pwstd->whsnt.h_addrtype = (short)xx->h_addrtype;
834 pwstd->whsnt.h_length = (short)xx->h_length;
835 pwstd->whsnt.h_addr_list = xx->h_addr_list;
836
837 return &pwstd->whsnt;
838}
839
840
841/*****************************************************************************
842 * Name :
843 * Purpose :
844 * Parameters:
845 * Variables :
846 * Result :
847 * Remark :
848 * Status : UNTESTED STUB
849 *
850 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
851 *****************************************************************************/
852
853ODINFUNCTION1(struct Whostent *,OS2gethostbyname,
854 const char *,name)
855{
856 WHOSTENT *yy;
857 struct hostent *xx;
858 PWSOCKTHREADDATA pwstd;
859
860
861 xx = gethostbyname((char *)name);
862 //PH: we assume PMWSOCK sets WSASetLastError correctly!
863
864 if(xx == NULL)
865 return (WHOSTENT *)NULL;
866
867 // access current thread wsock data block
868 pwstd = iQueryWsockThreadData();
869
870 pwstd->whsnt.h_name = xx->h_name;
871 pwstd->whsnt.h_aliases = xx->h_aliases;
872 pwstd->whsnt.h_addrtype = (short)xx->h_addrtype;
873 pwstd->whsnt.h_length = (short)xx->h_length;
874 pwstd->whsnt.h_addr_list = xx->h_addr_list;
875
876 return &pwstd->whsnt;
877}
878
879
880/*****************************************************************************
881 * Name :
882 * Purpose :
883 * Parameters:
884 * Variables :
885 * Result :
886 * Remark :
887 * Status : UNTESTED STUB
888 *
889 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
890 *****************************************************************************/
891
892ODINFUNCTION2(int,OS2gethostname,
893 char *,name,
894 int,namelen)
895{
896 //PH: we assume PMWSOCK sets WSASetLastError correctly!
897 return(gethostname(name,
898 namelen));
899}
900
901
902/*****************************************************************************
903 * Name :
904 * Purpose :
905 * Parameters:
906 * Variables :
907 * Result :
908 * Remark :
909 * Status : UNTESTED STUB
910 *
911 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
912 *****************************************************************************/
913
914ODINFUNCTION2(struct Wservent *,OS2getservbyport,
915 int, port,
916 const char *, proto)
917{
918 struct servent *xx;
919 PWSOCKTHREADDATA pwstd;
920
921 //PH: we assume PMWSOCK sets WSASetLastError correctly!
922 xx = getservbyport(port,(char *)proto);
923
924 if(xx == NULL)
925 return (WSERVENT *)NULL;
926
927 // access current thread wsock data block
928 pwstd = iQueryWsockThreadData();
929
930 pwstd->wsvnt.s_name = xx->s_name;
931 pwstd->wsvnt.s_aliases = xx->s_aliases;
932 pwstd->wsvnt.s_port = (short)xx->s_port;
933 pwstd->wsvnt.s_proto = xx->s_proto;
934
935 return &pwstd->wsvnt;
936}
937
938
939/*****************************************************************************
940 * Name :
941 * Purpose :
942 * Parameters:
943 * Variables :
944 * Result :
945 * Remark :
946 * Status : UNTESTED STUB
947 *
948 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
949 *****************************************************************************/
950
951ODINFUNCTION2(struct Wservent *,OS2getservbyname,
952 const char *, name,
953 const char *, proto)
954{
955 WSERVENT *yy;
956 struct servent *xx;
957 PWSOCKTHREADDATA pwstd;
958
959
960 //PH: we assume PMWSOCK sets WSASetLastError correctly!
961 xx = getservbyname((char *)name,(char *)proto);
962
963 if(xx == NULL)
964 return (WSERVENT *)NULL;
965
966 // access current thread wsock data block
967 pwstd = iQueryWsockThreadData();
968
969 pwstd->wsvnt.s_name = xx->s_name;
970 pwstd->wsvnt.s_aliases = xx->s_aliases;
971 pwstd->wsvnt.s_port = (short)xx->s_port;
972 pwstd->wsvnt.s_proto = xx->s_proto;
973
974 return &pwstd->wsvnt;
975}
976
977
978/*****************************************************************************
979 * Name :
980 * Purpose :
981 * Parameters:
982 * Variables :
983 * Result :
984 * Remark :
985 * Status : UNTESTED STUB
986 *
987 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
988 *****************************************************************************/
989
990ODINFUNCTION1(struct Wprotoent *,OS2getprotobynumber,
991 int,proto)
992{
993 struct protoent *xx;
994 PWSOCKTHREADDATA pwstd;
995
996 //PH: we assume PMWSOCK sets WSASetLastError correctly!
997 xx = getprotobynumber(proto);
998
999 if(xx == NULL)
1000 return (WPROTOENT *)NULL;
1001
1002 // access current thread wsock data block
1003 pwstd = iQueryWsockThreadData();
1004
1005 pwstd->wptnt.p_name = xx->p_name;
1006 pwstd->wptnt.p_aliases = xx->p_aliases;
1007 pwstd->wptnt.p_proto = (short)xx->p_proto;
1008
1009 return &pwstd->wptnt;
1010}
1011
1012
1013/*****************************************************************************
1014 * Name :
1015 * Purpose :
1016 * Parameters:
1017 * Variables :
1018 * Result :
1019 * Remark :
1020 * Status : UNTESTED STUB
1021 *
1022 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1023 *****************************************************************************/
1024
1025ODINFUNCTION1(struct Wprotoent *,OS2getprotobyname,
1026 const char *,name)
1027{
1028 struct protoent *xx;
1029 PWSOCKTHREADDATA pwstd;
1030
1031 //PH: we assume PMWSOCK sets WSASetLastError correctly!
1032 xx = getprotobyname((char *)name);
1033
1034 if(xx == NULL)
1035 return (WPROTOENT *)NULL;
1036
1037 // access current thread wsock data block
1038 pwstd = iQueryWsockThreadData();
1039
1040 pwstd->wptnt.p_name = xx->p_name;
1041 pwstd->wptnt.p_aliases = xx->p_aliases;
1042 pwstd->wptnt.p_proto = (short)xx->p_proto;
1043
1044 return &pwstd->wptnt;
1045}
1046
1047
1048
1049/* Microsoft Windows Extension function prototypes */
1050
1051/*****************************************************************************
1052 * Name :
1053 * Purpose :
1054 * Parameters:
1055 * Variables :
1056 * Result :
1057 * Remark :
1058 * Status : UNTESTED STUB
1059 *
1060 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1061 *****************************************************************************/
1062
1063ODINFUNCTION2(int,OS2WSAStartup,
1064 USHORT,wVersionRequired,
1065 LPWSADATA,lpWSAData)
1066{
1067 return(WSAStartup(wVersionRequired,
1068 lpWSAData));
1069}
1070
1071
1072/*****************************************************************************
1073 * Name :
1074 * Purpose :
1075 * Parameters:
1076 * Variables :
1077 * Result :
1078 * Remark :
1079 * Status : UNTESTED STUB
1080 *
1081 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1082 *****************************************************************************/
1083
1084ODINFUNCTION0(int,OS2WSACleanup)
1085{
1086 return(WSACleanup());
1087}
1088
1089
1090/*****************************************************************************
1091 * Name :
1092 * Purpose :
1093 * Parameters:
1094 * Variables :
1095 * Result :
1096 * Remark :
1097 * Status : UNTESTED STUB
1098 *
1099 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1100 *****************************************************************************/
1101
1102ODINFUNCTION0(BOOL,OS2WSAIsBlocking)
1103{
1104 return WSAIsBlocking();
1105}
1106
1107
1108/*****************************************************************************
1109 * Name :
1110 * Purpose :
1111 * Parameters:
1112 * Variables :
1113 * Result :
1114 * Remark :
1115 * Status : UNTESTED STUB
1116 *
1117 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1118 *****************************************************************************/
1119
1120ODINFUNCTION0(int,OS2WSAUnhookBlockingHook)
1121{
1122 return WSAUnhookBlockingHook();
1123}
1124
1125
1126/*****************************************************************************
1127 * Name :
1128 * Purpose :
1129 * Parameters:
1130 * Variables :
1131 * Result :
1132 * Remark :
1133 * Status : UNTESTED STUB
1134 *
1135 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1136 *****************************************************************************/
1137
1138ODINFUNCTION1(PFN,OS2WSASetBlockingHook,
1139 PFN,lpBlockFunc)
1140{
1141 return(WSASetBlockingHook(lpBlockFunc));
1142}
1143
1144
1145/*****************************************************************************
1146 * Name :
1147 * Purpose :
1148 * Parameters:
1149 * Variables :
1150 * Result :
1151 * Remark :
1152 * Status : UNTESTED STUB
1153 *
1154 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1155 *****************************************************************************/
1156
1157ODINFUNCTION0(int,OS2WSACancelBlockingCall)
1158{
1159 return(WSACancelBlockingCall());
1160}
1161
1162
1163/*****************************************************************************
1164 * Name :
1165 * Purpose :
1166 * Parameters:
1167 * Variables :
1168 * Result :
1169 * Remark :
1170 * Status : UNTESTED STUB
1171 *
1172 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1173 *****************************************************************************/
1174
1175ODINFUNCTION6(LHANDLE,OS2WSAAsyncGetServByName,
1176 HWND,hWnd,
1177 u_int,wMsg,
1178 const char *,name,
1179 const char *,proto,
1180 char *,buf,
1181 int,buflen)
1182{
1183 int rc;
1184 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1185 ULONG ulNewID;
1186
1187 if (hwndRelay == NULL) // already initialized ?
1188 hwndRelay = RelayInitialize(hwndOS2);
1189
1190 // add entry to list, we need to store both our temp buffer and the apps buffer
1191 ulNewID = RelayAlloc(hWnd,
1192 wMsg,
1193 ASYNCREQUEST_GETSERVBYNAME,
1194 FALSE,
1195 buf);
1196
1197 // call pmwsock function, will fill our temp buffer
1198 rc = WSAAsyncGetServByName(hwndRelay,
1199 ulNewID,
1200 name,
1201 proto,
1202 buf,
1203 buflen);
1204
1205 // if an error occurs, free the allocated relay entry
1206 if (rc == SOCKET_ERROR)
1207 RelayFree(ulNewID);
1208
1209 return (rc);
1210}
1211
1212
1213/*****************************************************************************
1214 * Name :
1215 * Purpose :
1216 * Parameters:
1217 * Variables :
1218 * Result :
1219 * Remark :
1220 * Status : UNTESTED STUB
1221 *
1222 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1223 *****************************************************************************/
1224
1225ODINFUNCTION6(LHANDLE,OS2WSAAsyncGetServByPort,
1226 HWND,hWnd,
1227 u_int,wMsg,
1228 int,port,
1229 const char *,proto,
1230 char *,buf,
1231 int,buflen)
1232{
1233 int rc;
1234 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1235 ULONG ulNewID;
1236
1237 if (hwndRelay == NULL) // already initialized ?
1238 hwndRelay = RelayInitialize(hwndOS2);
1239
1240 // add entry to list, we need to store both our temp buffer and the apps buffer
1241 ulNewID = RelayAlloc(hWnd,
1242 wMsg,
1243 ASYNCREQUEST_GETSERVBYPORT,
1244 FALSE,
1245 buf);
1246
1247 // call pmwsock function, will fill our temp buffer
1248 rc = WSAAsyncGetServByPort(hwndRelay,
1249 ulNewID,
1250 port,
1251 proto,
1252 buf,
1253 buflen);
1254
1255 // if an error occurs, free the allocated relay entry
1256 if (rc == SOCKET_ERROR)
1257 RelayFree(ulNewID);
1258
1259 return rc;
1260}
1261
1262
1263/*****************************************************************************
1264 * Name :
1265 * Purpose :
1266 * Parameters:
1267 * Variables :
1268 * Result :
1269 * Remark :
1270 * Status : UNTESTED STUB
1271 *
1272 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1273 *****************************************************************************/
1274
1275ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetProtoByName,
1276 HWND,hWnd,
1277 u_int,wMsg,
1278 const char *,name,
1279 char *,buf,
1280 int,buflen)
1281{
1282 int rc;
1283 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1284 ULONG ulNewID;
1285
1286 if (hwndRelay == NULL) // already initialized ?
1287 hwndRelay = RelayInitialize(hwndOS2);
1288
1289 // add entry to list, we need to store both our temp buffer and the apps buffer
1290 ulNewID = RelayAlloc(hWnd,
1291 wMsg,
1292 ASYNCREQUEST_GETPROTOBYNAME,
1293 FALSE,
1294 buf);
1295
1296 // call pmwsock function, will fill our temp buffer
1297 rc = WSAAsyncGetProtoByName(hwndRelay,
1298 ulNewID,
1299 name,
1300 buf,
1301 buflen);
1302
1303 // if an error occurs, free the allocated relay entry
1304 if (rc == SOCKET_ERROR)
1305 RelayFree(ulNewID);
1306
1307 return (rc);
1308}
1309
1310
1311/*****************************************************************************
1312 * Name :
1313 * Purpose :
1314 * Parameters:
1315 * Variables :
1316 * Result :
1317 * Remark :
1318 * Status : UNTESTED STUB
1319 *
1320 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1321 *****************************************************************************/
1322
1323ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetProtoByNumber,
1324 HWND,hWnd,
1325 u_int,wMsg,
1326 int,number,
1327 char *,buf,
1328 int,buflen)
1329{
1330 int rc;
1331 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1332 ULONG ulNewID;
1333
1334 if (hwndRelay == NULL) // already initialized ?
1335 hwndRelay = RelayInitialize(hwndOS2);
1336
1337 // add entry to list, we need to store both our temp buffer and the apps buffer
1338 ulNewID = RelayAlloc(hWnd,
1339 wMsg,
1340 ASYNCREQUEST_GETPROTOBYNUMBER,
1341 FALSE,
1342 buf);
1343
1344 // call pmwsock function, will fill our temp buffer
1345 rc = WSAAsyncGetProtoByNumber(hwndRelay,
1346 ulNewID,
1347 number,
1348 buf,
1349 buflen);
1350
1351 // if an error occurs, free the allocated relay entry
1352 if (rc == SOCKET_ERROR)
1353 RelayFree(ulNewID);
1354
1355 return rc;
1356}
1357
1358
1359/*****************************************************************************
1360 * Name :
1361 * Purpose :
1362 * Parameters:
1363 * Variables :
1364 * Result :
1365 * Remark :
1366 * Status : UNTESTED STUB
1367 *
1368 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1369 *****************************************************************************/
1370
1371ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetHostByName,
1372 HWND,hWnd,
1373 u_int,wMsg,
1374 const char *,name,
1375 char *,buf,
1376 int,buflen)
1377{
1378 int rc;
1379 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1380 ULONG ulNewID;
1381
1382 if (hwndRelay == NULL) // already initialized ?
1383 hwndRelay = RelayInitialize(hwndOS2);
1384
1385 // add entry to list, we need to store both our temp buffer and the apps buffer
1386 ulNewID = RelayAlloc(hWnd,
1387 wMsg,
1388 ASYNCREQUEST_GETHOSTBYNAME,
1389 FALSE,
1390 (PVOID)buf, (PVOID)buflen);
1391
1392 // call pmwsock function, will fill our temp buffer
1393 rc = WSAAsyncGetHostByName(hwndRelay,
1394 ulNewID,
1395 name,
1396 buf,
1397 buflen);
1398
1399 // if an error occurs, free the allocated relay entry
1400 if (rc == SOCKET_ERROR)
1401 RelayFree(ulNewID);
1402
1403 return rc;
1404}
1405
1406
1407/*****************************************************************************
1408 * Name :
1409 * Purpose :
1410 * Parameters:
1411 * Variables :
1412 * Result :
1413 * Remark :
1414 * Status : UNTESTED STUB
1415 *
1416 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1417 *****************************************************************************/
1418
1419ODINFUNCTION7(LHANDLE,OS2WSAAsyncGetHostByAddr,
1420 HWND,hWnd,
1421 u_int,wMsg,
1422 const char *,addr,
1423 int,len,
1424 int,type,
1425 char *,buf,
1426 int,buflen)
1427{
1428 int rc;
1429 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1430 ULONG ulNewID;
1431
1432 if (hwndRelay == NULL) // already initialized ?
1433 hwndRelay = RelayInitialize(hwndOS2);
1434
1435 // add entry to list, we need to store both our temp buffer and the apps buffer
1436 ulNewID = RelayAlloc(hWnd,
1437 wMsg,
1438 ASYNCREQUEST_GETHOSTBYADDR,
1439 FALSE,
1440 buf);
1441
1442 // call pmwsock function, will fill our temp buffer
1443 rc = WSAAsyncGetHostByAddr(hwndRelay,
1444 ulNewID,
1445 addr,
1446 len,
1447 type,
1448 buf,
1449 buflen);
1450
1451 // if an error occurs, free the allocated relay entry
1452 if (rc == SOCKET_ERROR)
1453 RelayFree(ulNewID);
1454
1455 return (rc);
1456}
1457
1458
1459/*****************************************************************************
1460 * Name :
1461 * Purpose :
1462 * Parameters:
1463 * Variables :
1464 * Result :
1465 * Remark :
1466 * Status : UNTESTED STUB
1467 *
1468 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1469 *****************************************************************************/
1470
1471ODINFUNCTION1(int,OS2WSACancelAsyncRequest,
1472 LHANDLE,hAsyncTaskHandle)
1473{
1474 return(WSACancelAsyncRequest(hAsyncTaskHandle));
1475}
1476
1477
1478/*****************************************************************************
1479 * Name :
1480 * Purpose :
1481 * Parameters:
1482 * Variables :
1483 * Result :
1484 * Remark :
1485 * Status : UNTESTED STUB
1486 *
1487 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1488 *****************************************************************************/
1489
1490ODINFUNCTION4(int,OS2WSAAsyncSelect,
1491 SOCKET,s,
1492 HWND,hWnd,
1493 u_int,wMsg,
1494 long,lEvent)
1495{
1496 int rc;
1497// int iError;
1498 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1499 ULONG ulNewID;
1500
1501 if (hwndRelay == NULL) // already initialized ?
1502 hwndRelay = RelayInitialize(hwndOS2);
1503
1504 /* @@@PH: our source window doesn't seem to have an anchor block.
1505 Docs suggest we've missed to call WinInitialize on the
1506 caller thread.
1507
1508 Cause however is the Open32 handle is (of course!) invalid
1509 in plain PM Window Manager! -> use DAPWSOCK
1510
1511 Unfortunately, DAPWSOCK calls WinQueryAnchorBlock(hOpen32), too.
1512 So, we're stuck until I resolve hWnd to it's valid PM
1513 counterpart.
1514
1515 new problem: we've ultimately got to use PostMessageA instead
1516 anything else. => create invisible msg relay window:
1517 - hMsg = registerMessage(hWnd, wMsg)
1518 - call WSAAsyncSelect with object window handle
1519 - overwrite hWnd relay for "same handles"
1520 */
1521
1522 // add event to list or remove any list entry in case of WSAAsyncSelect(hwnd,0,0)
1523 if ( (wMsg == 0) && (lEvent == 0) )
1524 {
1525 // remove entry from list
1526 RelayFreeByHwnd(hWnd);
1527 }
1528 else
1529 // add entry to list
1530 ulNewID = RelayAlloc(hWnd,
1531 wMsg,
1532 ASYNCREQUEST_SELECT,
1533 TRUE);
1534
1535 rc = WSAAsyncSelect(s,
1536 hwndRelay,
1537 ulNewID,
1538 lEvent);
1539
1540// iError = WSAGetLastError();
1541// dprintf(("res=%d, err=%d\n",
1542// rc,
1543// iError));
1544 return (rc);
1545}
Note: See TracBrowser for help on using the repository browser.