Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8845 lines
265 KiB

  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. sockeye.c
  5. Abstract:
  6. Contains UI support for winsock browser util.
  7. Author:
  8. Dan Knudson (DanKn) 29-Jul-1996
  9. Revision History:
  10. --*/
  11. #include "sockeye.h"
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <stdarg.h>
  15. #include <time.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #include <io.h>
  19. #include <commdlg.h>
  20. #include "resource.h"
  21. #include "vars.h"
  22. #include "nspapi.h"
  23. int giCurrNumStartups = 0;
  24. HWND hwndEdit2, ghwndModal;
  25. char gszEnterAs[32];
  26. PASYNC_REQUEST_INFO gpAsyncReqInfoList = NULL;
  27. PMYSOCKET gpSelectedSocket;
  28. MYSOCKET gNullSocket;
  29. LRESULT glCurrentSelection;
  30. WSAPROTOCOL_INFOA gWSAProtocolInfoA;
  31. WSAPROTOCOL_INFOW gWSAProtocolInfoW;
  32. HFONT ghFixedFont;
  33. WSAEVENT ghSelectedEvent;
  34. INT giSelectedEventIndex;
  35. WSAPROTOCOL_INFOW gDupSockProtoInfo;
  36. char gszSocket[] = "socket";
  37. char gszSockEye[] = "SockEye";
  38. char gszUnknown[] = "unknown";
  39. char gszProtocol[] = "Protocol";
  40. char gszHostName[] = "HostName";
  41. char gszSendFlags[] = "SendFlags";
  42. char gszRecvFlags[] = "RecvFlags";
  43. char gszXxxSUCCESS[] = "%s SUCCESS";
  44. char gszSocketType[] = "SocketType";
  45. char gszPortNumber[] = "PortNumber";
  46. char gszServiceName[] = "ServiceName";
  47. char gszIoctlCommand[] = "IoctlCommand";
  48. char gszProtocolName[] = "ProtocolName";
  49. char gszUnknownError[] = "unknown error";
  50. char gszAddressFamily[] = "AddressFamily";
  51. char gszWSASocketFlags[] = "WSASocketFlags";
  52. char gszProtocolNumber[] = "ProtocolNumber";
  53. DWORD gdwDefPortNum;
  54. DWORD gdwDefProtocol;
  55. DWORD gdwDefProtoNum;
  56. DWORD gdwDefIoctlCmd;
  57. DWORD gdwDefSendFlags;
  58. DWORD gdwDefRecvFlags;
  59. DWORD gdwDefAddrFamily;
  60. DWORD gdwDefSocketType;
  61. DWORD gdwDefWSASocketFlags;
  62. char gszDefHostName[MAX_STRING_PARAM_SIZE];
  63. char gszDefProtoName[MAX_STRING_PARAM_SIZE];
  64. char gszDefServName[MAX_STRING_PARAM_SIZE];
  65. char *
  66. PASCAL
  67. GetTimeStamp(
  68. void
  69. );
  70. void
  71. ShowStructByField(
  72. PSTRUCT_FIELD_HEADER pHeader,
  73. BOOL bSubStructure
  74. );
  75. VOID
  76. PASCAL
  77. ShowGUID(
  78. char *pszProlog,
  79. GUID *pGuid
  80. );
  81. void
  82. FAR
  83. PASCAL
  84. FuncDriver(
  85. FUNC_INDEX funcIndex
  86. );
  87. int
  88. WINAPI
  89. WinMain(
  90. HINSTANCE hInstance,
  91. HINSTANCE hPrevInstance,
  92. LPSTR lpCmdLine,
  93. int nCmdShow
  94. )
  95. {
  96. MSG msg;
  97. HWND hwnd;
  98. DWORD i;
  99. HACCEL hAccel;
  100. ghInst = hInstance;
  101. ZeroMemory (&gNullSocket, sizeof (MYSOCKET));
  102. ZeroMemory (&gWSAProtocolInfoA, sizeof (WSAPROTOCOL_INFOA));
  103. ZeroMemory (&gWSAProtocolInfoW, sizeof (WSAPROTOCOL_INFOW));
  104. {
  105. DWORD d = 0x76543210;
  106. wsprintf(
  107. gszEnterAs,
  108. "Ex: enter x%x as %02x%02x%02x%02x",
  109. d,
  110. (DWORD) *((LPBYTE) &d),
  111. (DWORD) *(((LPBYTE) &d) + 1),
  112. (DWORD) *(((LPBYTE) &d) + 2),
  113. (DWORD) *(((LPBYTE) &d) + 3)
  114. );
  115. }
  116. hwnd = CreateDialog(
  117. ghInst,
  118. (LPCSTR)MAKEINTRESOURCE(IDD_DIALOG1),
  119. (HWND)NULL,
  120. (DLGPROC) MainWndProc
  121. );
  122. hwndEdit2 = CreateWindow ("edit", "", 0, 0, 0, 0, 0, NULL, NULL, ghInst, NULL);
  123. if (!hwndEdit2)
  124. {
  125. MessageBox (NULL, "err creating edit ctl", "", MB_OK);
  126. }
  127. hAccel = LoadAccelerators(
  128. ghInst,
  129. (LPCSTR)MAKEINTRESOURCE(IDR_ACCELERATOR1)
  130. );
  131. while (GetMessage (&msg, NULL, 0, 0))
  132. {
  133. if (hAccel==NULL || !TranslateAccelerator (hwnd, hAccel, &msg))
  134. {
  135. TranslateMessage (&msg);
  136. DispatchMessage (&msg);
  137. }
  138. }
  139. DestroyWindow (hwndEdit2);
  140. return 0;
  141. }
  142. LPVOID
  143. PASCAL
  144. MyAlloc(
  145. SIZE_T dwSize
  146. )
  147. {
  148. LPVOID p;
  149. if (!(p = LocalAlloc (LPTR, dwSize)))
  150. {
  151. ShowStr ("LocalAlloc (LPTR, x%x) failed, error=%d", GetLastError());
  152. }
  153. return p;
  154. }
  155. void
  156. PASCAL
  157. MyFree(
  158. LPVOID p
  159. )
  160. {
  161. if (p)
  162. {
  163. LocalFree (p);
  164. }
  165. }
  166. void
  167. GetCurrentSelections(
  168. void
  169. )
  170. {
  171. LRESULT lSel = SendMessage (ghwndList1, LB_GETCURSEL, 0, 0);
  172. LRESULT lSelCount = SendMessage (ghwndList3, LB_GETSELCOUNT, 0, 0);
  173. if ((lSel = SendMessage (ghwndList1, LB_GETCURSEL, 0, 0)) != LB_ERR)
  174. {
  175. glCurrentSelection = lSel;
  176. gpSelectedSocket = (PMYSOCKET) SendMessage(
  177. ghwndList1,
  178. LB_GETITEMDATA,
  179. (WPARAM) lSel,
  180. 0
  181. );
  182. }
  183. else
  184. {
  185. gpSelectedSocket = &gNullSocket;
  186. }
  187. if (lSelCount == 0 || lSelCount == LB_ERR)
  188. {
  189. ghSelectedEvent = NULL;
  190. }
  191. else
  192. {
  193. SendMessage(
  194. ghwndList3,
  195. LB_GETSELITEMS,
  196. 1,
  197. (LPARAM) &giSelectedEventIndex
  198. );
  199. ghSelectedEvent = (WSAEVENT) SendMessage(
  200. ghwndList3,
  201. LB_GETITEMDATA,
  202. giSelectedEventIndex,
  203. 0
  204. );
  205. }
  206. }
  207. BOOL
  208. LetUserMungeParams(
  209. PFUNC_PARAM_HEADER pParamsHeader
  210. )
  211. {
  212. if (!bShowParams)
  213. {
  214. return TRUE;
  215. }
  216. return (DialogBoxParam(
  217. ghInst,
  218. (LPCSTR)MAKEINTRESOURCE(IDD_DIALOG2),
  219. ghwndModal,
  220. (DLGPROC) ParamsDlgProc,
  221. (LPARAM) pParamsHeader
  222. ) ? TRUE : FALSE);
  223. }
  224. INT_PTR
  225. CALLBACK
  226. MainWndProc(
  227. HWND hwnd,
  228. UINT msg,
  229. WPARAM wParam,
  230. LPARAM lParam
  231. )
  232. {
  233. static HICON hIcon;
  234. static HMENU hMenu;
  235. static int icyButton, icyBorder;
  236. static HFONT hFont, hFont2;
  237. static int iMaxEditTextLength;
  238. static HANDLE hTimerEvent;
  239. #define TIMER_ID 55
  240. #define TIMER_TIMEOUT 2000
  241. int i;
  242. static LONG cxList1, cxList2, cxWnd, xCapture, cxVScroll, lCaptureFlags = 0;
  243. static int cyWnd;
  244. typedef struct _XXX
  245. {
  246. DWORD dwMenuID;
  247. DWORD dwFlags;
  248. } XXX, *PXXX;
  249. static XXX aXxx[] =
  250. {
  251. { IDM_LOGSTRUCTDWORD ,DS_BYTEDUMP },
  252. { IDM_LOGSTRUCTALLFIELD ,DS_NONZEROFIELDS|DS_ZEROFIELDS },
  253. { IDM_LOGSTRUCTNONZEROFIELD ,DS_NONZEROFIELDS },
  254. { IDM_LOGSTRUCTNONE ,0 }
  255. };
  256. switch (msg)
  257. {
  258. case WM_INITDIALOG:
  259. {
  260. RECT rect;
  261. char buf[64];
  262. DWORD dwInitialized;
  263. wsprintf(
  264. buf,
  265. "WinSock API Browser (ProcessID=x%x)",
  266. GetCurrentProcessId()
  267. );
  268. SetWindowText (hwnd, buf);
  269. ghwndMain = ghwndModal = hwnd;
  270. ghwndList1 = GetDlgItem (hwnd, IDC_LIST1);
  271. ghwndList2 = GetDlgItem (hwnd, IDC_LIST2);
  272. ghwndList3 = GetDlgItem (hwnd, IDC_LIST3);
  273. ghwndEdit = GetDlgItem (hwnd, IDC_EDIT1);
  274. hMenu = GetMenu (hwnd);
  275. hIcon = LoadIcon (ghInst, MAKEINTRESOURCE(IDI_ICON1));
  276. icyBorder = GetSystemMetrics (SM_CYFRAME);
  277. cxVScroll = 2*GetSystemMetrics (SM_CXVSCROLL);
  278. GetWindowRect (GetDlgItem (hwnd, IDC_BUTTON1), &rect);
  279. icyButton = (rect.bottom - rect.top) + icyBorder + 3;
  280. for (i = 0; aFuncNames[i]; i++)
  281. {
  282. SendMessage(
  283. ghwndList2,
  284. LB_INSERTSTRING,
  285. (WPARAM) -1,
  286. (LPARAM) aFuncNames[i]
  287. );
  288. }
  289. // SendMessage (ghwndList2, LB_SETCURSEL, (WPARAM) lInitialize, 0);
  290. //
  291. // Read in defaults from ini file
  292. //
  293. {
  294. typedef struct _DEF_VALUE
  295. {
  296. char far *lpszEntry;
  297. char far *lpszDefValue;
  298. LPVOID lp;
  299. } DEF_VALUE;
  300. DEF_VALUE aDefVals[] =
  301. {
  302. { "BufSize", "100", &dwBigBufSize },
  303. { "UserButton1", "500", aUserButtonFuncs },
  304. { "UserButton2", "500", aUserButtonFuncs + 1 },
  305. { "UserButton3", "500", aUserButtonFuncs + 2 },
  306. { "UserButton4", "500", aUserButtonFuncs + 3 },
  307. { "UserButton5", "500", aUserButtonFuncs + 4 },
  308. { "UserButton6", "500", aUserButtonFuncs + 5 },
  309. { "Initialized", "0", &dwInitialized },
  310. { gszAddressFamily, "2", &gdwDefAddrFamily },
  311. { gszSocketType, "2", &gdwDefSocketType },
  312. { gszProtocol, "0", &gdwDefProtocol },
  313. { gszProtocolNumber, "0", &gdwDefProtoNum },
  314. { gszPortNumber, "0", &gdwDefPortNum },
  315. { gszIoctlCommand, "0", &gdwDefIoctlCmd },
  316. { gszSendFlags, "0", &gdwDefSendFlags },
  317. { gszRecvFlags, "0", &gdwDefRecvFlags },
  318. { gszWSASocketFlags, "0", &gdwDefWSASocketFlags },
  319. { NULL, NULL, NULL },
  320. { gszHostName, "HostName", gszDefHostName },
  321. { gszProtocolName, "ProtoName", gszDefProtoName },
  322. { gszServiceName, "ServiceName", gszDefServName },
  323. { NULL, NULL, NULL },
  324. { "UserButton1Text", "", &aUserButtonsText[0] },
  325. { "UserButton2Text", "", &aUserButtonsText[1] },
  326. { "UserButton3Text", "", &aUserButtonsText[2] },
  327. { "UserButton4Text", "", &aUserButtonsText[3] },
  328. { "UserButton5Text", "", &aUserButtonsText[4] },
  329. { "UserButton6Text", "", &aUserButtonsText[5] },
  330. { NULL, NULL, NULL }
  331. };
  332. int i, j;
  333. for (i = 0; aDefVals[i].lpszEntry; i++)
  334. {
  335. GetProfileString(
  336. gszSockEye,
  337. aDefVals[i].lpszEntry,
  338. aDefVals[i].lpszDefValue,
  339. buf,
  340. 15
  341. );
  342. sscanf (buf, "%lx", aDefVals[i].lp);
  343. }
  344. i++;
  345. for (; aDefVals[i].lpszEntry; i++)
  346. {
  347. GetProfileString(
  348. gszSockEye,
  349. aDefVals[i].lpszEntry,
  350. aDefVals[i].lpszDefValue,
  351. (LPSTR) aDefVals[i].lp,
  352. MAX_STRING_PARAM_SIZE - 1
  353. );
  354. }
  355. i++;
  356. for (j = i; aDefVals[i].lpszEntry; i++)
  357. {
  358. GetProfileString(
  359. gszSockEye,
  360. aDefVals[i].lpszEntry,
  361. aDefVals[i].lpszDefValue,
  362. (LPSTR) aDefVals[i].lp,
  363. MAX_USER_BUTTON_TEXT_SIZE - 1
  364. );
  365. SetDlgItemText(
  366. hwnd,
  367. IDC_BUTTON7 + (i - j),
  368. (LPCSTR)aDefVals[i].lp
  369. );
  370. }
  371. if (dwInitialized == 0)
  372. {
  373. //
  374. // If here assume this is first time user had started
  375. // app, so post a msg that will automatically bring up
  376. // the hlp dlg
  377. //
  378. PostMessage (hwnd, WM_COMMAND, IDM_USAGE, 0);
  379. }
  380. }
  381. pBigBuf = MyAlloc (dwBigBufSize);
  382. {
  383. //HFONT hFontMenu = SendMessage (hMenu, WM_GETFONT, 0, 0);
  384. hFont = CreateFont(
  385. 13, 5, 0, 0, 400, 0, 0, 0, 0, 1, 2, 1, 34, "MS Sans Serif"
  386. );
  387. ghFixedFont =
  388. hFont2 = CreateFont(
  389. 13, 8, 0, 0, 400, 0, 0, 0, 0, 1, 2, 1, 49, "Courier"
  390. );
  391. for (i = 0; i < 12; i++)
  392. {
  393. SendDlgItemMessage(
  394. hwnd,
  395. IDC_BUTTON1 + i,
  396. WM_SETFONT,
  397. (WPARAM) hFont,
  398. 0
  399. );
  400. }
  401. SendDlgItemMessage (hwnd, IDM_PARAMS, WM_SETFONT,(WPARAM) hFont,0);
  402. SendMessage (ghwndList1, WM_SETFONT, (WPARAM) hFont, 0);
  403. SendMessage (ghwndList2, WM_SETFONT, (WPARAM) hFont, 0);
  404. SendMessage (ghwndList3, WM_SETFONT, (WPARAM) hFont, 0);
  405. SendMessage (ghwndEdit, WM_SETFONT, (WPARAM) hFont2, 0);
  406. }
  407. GetProfileString(
  408. gszSockEye,
  409. "ControlRatios",
  410. "20, 20, 100",
  411. buf,
  412. 63
  413. );
  414. sscanf (buf, "%ld,%ld,%ld", &cxList2, &cxList1, &cxWnd);
  415. GetProfileString(
  416. gszSockEye,
  417. "Position",
  418. "max",
  419. buf,
  420. 63
  421. );
  422. if (strcmp (buf, "max") == 0)
  423. {
  424. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  425. }
  426. else
  427. {
  428. int left = 100, top = 100, right = 600, bottom = 400;
  429. sscanf (buf, "%d,%d,%d,%d", &left, &top, &right, &bottom);
  430. //
  431. // Check to see if wnd pos is wacky, if so reset to reasonable vals
  432. //
  433. if (left < 0 ||
  434. left >= (GetSystemMetrics (SM_CXSCREEN) - 32) ||
  435. top < 0 ||
  436. top >= (GetSystemMetrics (SM_CYSCREEN) - 32))
  437. {
  438. left = top = 100;
  439. right = 600;
  440. bottom = 400;
  441. }
  442. SetWindowPos(
  443. hwnd,
  444. HWND_TOP,
  445. left,
  446. top,
  447. right - left,
  448. bottom - top,
  449. SWP_SHOWWINDOW
  450. );
  451. GetClientRect (hwnd, &rect);
  452. SendMessage(
  453. hwnd,
  454. WM_SIZE,
  455. 0,
  456. MAKELONG((rect.right-rect.left),(rect.bottom-rect.top))
  457. );
  458. ShowWindow (hwnd, SW_SHOW);
  459. }
  460. iMaxEditTextLength = ((GetVersion() & 0x80000000) ?
  461. 29998 : // we're on win95, and edit controls are 16-bit
  462. 0x20000 // were on NT, and have real 32-bit edit controls
  463. );
  464. hTimerEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  465. SetTimer (hwnd, TIMER_ID, TIMER_TIMEOUT, NULL);
  466. break;
  467. }
  468. case WM_COMMAND:
  469. {
  470. FUNC_INDEX funcIndex;
  471. BOOL bShowParamsSave = bShowParams;
  472. switch (LOWORD((DWORD)wParam))
  473. {
  474. case IDC_EDIT1:
  475. #ifdef WIN32
  476. if (HIWORD(wParam) == EN_CHANGE)
  477. #else
  478. if (HIWORD(lParam) == EN_CHANGE)
  479. #endif
  480. {
  481. //
  482. // Watch to see if the edit control is full, & if so
  483. // purge the top half of the text to make room for more
  484. //
  485. int length = GetWindowTextLength (ghwndEdit);
  486. // if (length > iMaxEditTextLength)
  487. if (length > 29998)
  488. {
  489. #ifdef WIN32
  490. SendMessage(
  491. ghwndEdit,
  492. EM_SETSEL,
  493. (WPARAM) 0,
  494. (LPARAM) 10000
  495. );
  496. #else
  497. SendMessage(
  498. ghwndEdit,
  499. EM_SETSEL,
  500. (WPARAM) 1,
  501. (LPARAM) MAKELONG (0, 10000)
  502. );
  503. #endif
  504. SendMessage(
  505. ghwndEdit,
  506. EM_REPLACESEL,
  507. 0,
  508. (LPARAM) (char far *) ""
  509. );
  510. #ifdef WIN32
  511. SendMessage(
  512. ghwndEdit,
  513. EM_SETSEL,
  514. (WPARAM)0xfffffffd,
  515. (LPARAM)0xfffffffe
  516. );
  517. #else
  518. SendMessage(
  519. ghwndEdit,
  520. EM_SETSEL,
  521. (WPARAM)1,
  522. (LPARAM) MAKELONG (0xfffd, 0xfffe)
  523. );
  524. #endif
  525. }
  526. }
  527. break;
  528. case IDC_BUTTON1:
  529. FuncDriver (ws_WSAStartup);
  530. break;
  531. case IDC_BUTTON2:
  532. FuncDriver (ws_WSACleanup);
  533. break;
  534. case IDC_BUTTON3:
  535. FuncDriver (ws_socket);
  536. break;
  537. case IDC_BUTTON4:
  538. FuncDriver (ws_WSASocketA);
  539. break;
  540. case IDC_BUTTON5:
  541. GetCurrentSelections();
  542. FuncDriver (ws_closesocket);
  543. break;
  544. case IDC_BUTTON6:
  545. case IDM_CLEAR:
  546. SetWindowText (ghwndEdit, "");
  547. break;
  548. case IDM_PARAMS:
  549. bShowParams = (bShowParams ? FALSE : TRUE);
  550. if (bShowParams)
  551. {
  552. CheckMenuItem(
  553. hMenu,
  554. IDM_PARAMS,
  555. MF_BYCOMMAND | MF_CHECKED
  556. );
  557. CheckDlgButton (hwnd, IDM_PARAMS, 1);
  558. }
  559. else
  560. {
  561. CheckMenuItem(
  562. hMenu,
  563. IDM_PARAMS,
  564. MF_BYCOMMAND | MF_UNCHECKED
  565. );
  566. CheckDlgButton (hwnd, IDM_PARAMS, 0);
  567. }
  568. break;
  569. case IDC_BUTTON7:
  570. case IDC_BUTTON8:
  571. case IDC_BUTTON9:
  572. case IDC_BUTTON10:
  573. case IDC_BUTTON11:
  574. case IDC_BUTTON12:
  575. {
  576. DWORD i = (DWORD) (LOWORD((DWORD)wParam)) - IDC_BUTTON7;
  577. if (aUserButtonFuncs[i] >= MiscBegin)
  578. {
  579. //
  580. // Hot button func id is bogus, so bring
  581. // up hot button init dlg
  582. //
  583. DialogBoxParam(
  584. ghInst,
  585. (LPCSTR)MAKEINTRESOURCE(IDD_DIALOG3),
  586. (HWND) hwnd,
  587. (DLGPROC) UserButtonsDlgProc,
  588. (LPARAM) &i
  589. );
  590. }
  591. else
  592. {
  593. //
  594. // Invoke the user button's corresponding func
  595. //
  596. GetCurrentSelections ();
  597. FuncDriver ((FUNC_INDEX) aUserButtonFuncs[i]);
  598. }
  599. break;
  600. }
  601. case IDC_PREVCTRL:
  602. {
  603. HWND hwndPrev = GetNextWindow (GetFocus (), GW_HWNDPREV);
  604. if (!hwndPrev)
  605. {
  606. hwndPrev = ghwndList2;
  607. }
  608. SetFocus (hwndPrev);
  609. break;
  610. }
  611. case IDC_NEXTCTRL:
  612. {
  613. HWND hwndNext = GetNextWindow (GetFocus (), GW_HWNDNEXT);
  614. if (!hwndNext)
  615. {
  616. hwndNext = GetDlgItem (hwnd, IDM_PARAMS);
  617. }
  618. SetFocus (hwndNext);
  619. break;
  620. }
  621. case IDC_ENTER:
  622. {
  623. if (GetFocus() != ghwndEdit)
  624. {
  625. GetCurrentSelections ();
  626. FuncDriver(
  627. (FUNC_INDEX)SendMessage(
  628. ghwndList2,
  629. LB_GETCURSEL,
  630. 0,
  631. 0
  632. ));
  633. }
  634. else
  635. {
  636. // Send the edit ctrl a cr/lf
  637. }
  638. break;
  639. }
  640. case IDC_LIST1:
  641. #ifdef WIN32
  642. switch (HIWORD(wParam))
  643. #else
  644. switch (HIWORD(lParam))
  645. #endif
  646. {
  647. case LBN_DBLCLK:
  648. {
  649. /*
  650. LONG lSel = SendMessage (ghwndList1, LB_GETCURSEL, 0, 0);
  651. PMYWIDGET pWidget;
  652. pWidget = (PMYWIDGET) SendMessage(
  653. ghwndList1,
  654. LB_GETITEMDATA,
  655. (WPARAM) lSel,
  656. 0
  657. );
  658. bShowParams = FALSE;
  659. // UpdateResults (TRUE);
  660. switch (pWidget->dwType)
  661. {
  662. }
  663. // UpdateResults (FALSE);
  664. bShowParams = bShowParamsSave;
  665. */
  666. break;
  667. }
  668. } // switch
  669. break;
  670. case IDC_LIST2:
  671. #ifdef WIN32
  672. if (HIWORD(wParam) == LBN_DBLCLK)
  673. #else
  674. if (HIWORD(lParam) == LBN_DBLCLK)
  675. #endif
  676. {
  677. GetCurrentSelections ();
  678. FuncDriver(
  679. (FUNC_INDEX)SendMessage(
  680. ghwndList2,
  681. LB_GETCURSEL,
  682. 0,
  683. 0
  684. ));
  685. }
  686. break;
  687. case IDM_EXIT:
  688. {
  689. PostMessage (hwnd, WM_CLOSE, 0, 0);
  690. break;
  691. }
  692. case IDM_DEFAULTVALUES:
  693. {
  694. char szHostName[MAX_STRING_PARAM_SIZE],
  695. szProtoName[MAX_STRING_PARAM_SIZE],
  696. szServName[MAX_STRING_PARAM_SIZE];
  697. FUNC_PARAM params[] =
  698. {
  699. { "Buffer size", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  700. { gszAddressFamily, PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  701. { gszSocketType, PT_ORDINAL, (ULONG_PTR) gdwDefSocketType, aSocketTypes },
  702. { gszProtocol, PT_ORDINAL, (ULONG_PTR) gdwDefProtocol, aProtocols },
  703. { gszProtocolNumber, PT_DWORD, (ULONG_PTR) gdwDefProtoNum, NULL },
  704. { gszPortNumber, PT_DWORD, (ULONG_PTR) gdwDefPortNum, NULL },
  705. { gszIoctlCommand, PT_ORDINAL, (ULONG_PTR) gdwDefIoctlCmd, aWSAIoctlCmds },
  706. { gszHostName, PT_STRING, (ULONG_PTR) szHostName, szHostName },
  707. { gszProtocolName, PT_STRING, (ULONG_PTR) szProtoName, szProtoName },
  708. { gszServiceName, PT_STRING, (ULONG_PTR) szServName, szServName },
  709. { gszSendFlags, PT_FLAGS, (ULONG_PTR) aWSASendFlags, aWSASendFlags },
  710. { gszRecvFlags, PT_FLAGS, (ULONG_PTR) aWSARecvFlags, aWSARecvFlags },
  711. { gszWSASocketFlags, PT_FLAGS, (ULONG_PTR) aWSAFlags, aWSAFlags }
  712. };
  713. FUNC_PARAM_HEADER paramsHeader =
  714. { 13, DefValues, params, NULL };
  715. BOOL bShowParamsSave = bShowParams;
  716. bShowParams = TRUE;
  717. lstrcpyA (szHostName, gszDefHostName);
  718. lstrcpyA (szProtoName, gszDefProtoName);
  719. lstrcpyA (szServName, gszDefServName);
  720. if (LetUserMungeParams (&paramsHeader))
  721. {
  722. if (params[0].dwValue != dwBigBufSize)
  723. {
  724. LPVOID pTmpBigBuf = MyAlloc (params[0].dwValue);
  725. if (pTmpBigBuf)
  726. {
  727. MyFree (pBigBuf);
  728. pBigBuf = pTmpBigBuf;
  729. dwBigBufSize = (DWORD) params[0].dwValue;
  730. }
  731. }
  732. gdwDefAddrFamily = (DWORD) params[1].dwValue;
  733. gdwDefSocketType = (DWORD) params[2].dwValue;
  734. gdwDefProtocol = (DWORD) params[3].dwValue;
  735. gdwDefProtoNum = (DWORD) params[4].dwValue;
  736. gdwDefPortNum = (DWORD) params[5].dwValue;
  737. gdwDefIoctlCmd = (DWORD) params[6].dwValue;
  738. if (params[7].dwValue == (ULONG_PTR) szHostName)
  739. {
  740. lstrcpyA (gszDefHostName, szHostName);
  741. }
  742. if (params[8].dwValue == (ULONG_PTR) szProtoName)
  743. {
  744. lstrcpyA (gszDefProtoName, szProtoName);
  745. }
  746. if (params[9].dwValue == (ULONG_PTR) szServName)
  747. {
  748. lstrcpyA (gszDefServName, szServName);
  749. }
  750. gdwDefSendFlags = (DWORD) params[10].dwValue;
  751. gdwDefRecvFlags = (DWORD) params[11].dwValue;
  752. gdwDefWSASocketFlags = (DWORD) params[12].dwValue;
  753. }
  754. bShowParams = bShowParamsSave;
  755. break;
  756. }
  757. case IDM_USERBUTTONS:
  758. DialogBoxParam(
  759. ghInst,
  760. (LPCSTR)MAKEINTRESOURCE(IDD_DIALOG3),
  761. (HWND) hwnd,
  762. (DLGPROC) UserButtonsDlgProc,
  763. (LPARAM) NULL
  764. );
  765. break;
  766. case IDM_DUMPPARAMS:
  767. bDumpParams = (bDumpParams ? FALSE : TRUE);
  768. CheckMenuItem(
  769. hMenu,
  770. IDM_DUMPPARAMS,
  771. MF_BYCOMMAND | (bDumpParams ? MF_CHECKED : MF_UNCHECKED)
  772. );
  773. break;
  774. case IDM_LOGSTRUCTDWORD:
  775. case IDM_LOGSTRUCTALLFIELD:
  776. case IDM_LOGSTRUCTNONZEROFIELD:
  777. case IDM_LOGSTRUCTNONE:
  778. for (i = 0; aXxx[i].dwFlags != dwDumpStructsFlags; i++);
  779. CheckMenuItem(
  780. hMenu,
  781. aXxx[i].dwMenuID,
  782. MF_BYCOMMAND | MF_UNCHECKED
  783. );
  784. for (i = 0; aXxx[i].dwMenuID != LOWORD((DWORD)wParam); i++);
  785. CheckMenuItem(
  786. hMenu,
  787. aXxx[i].dwMenuID,
  788. MF_BYCOMMAND | MF_CHECKED
  789. );
  790. dwDumpStructsFlags = aXxx[i].dwFlags;
  791. break;
  792. case IDM_TIMESTAMP:
  793. bTimeStamp = (bTimeStamp ? FALSE : TRUE);
  794. CheckMenuItem(
  795. hMenu,
  796. IDM_TIMESTAMP,
  797. MF_BYCOMMAND | (bTimeStamp ? MF_CHECKED : MF_UNCHECKED)
  798. );
  799. break;
  800. case IDM_LOGFILE:
  801. {
  802. if (hLogFile)
  803. {
  804. fclose (hLogFile);
  805. hLogFile = (FILE *) NULL;
  806. CheckMenuItem(
  807. hMenu,
  808. IDM_LOGFILE,
  809. MF_BYCOMMAND | MF_UNCHECKED
  810. );
  811. }
  812. else
  813. {
  814. OPENFILENAME ofn;
  815. char szDirName[256] = ".\\";
  816. char szFile[256] = "sockeye.log\0";
  817. char szFileTitle[256] = "";
  818. static char *szFilter =
  819. "Log files (*.log)\0*.log\0All files (*.*)\0*.*\0\0";
  820. ofn.lStructSize = sizeof(OPENFILENAME);
  821. ofn.hwndOwner = hwnd;
  822. ofn.lpstrFilter = szFilter;
  823. ofn.lpstrCustomFilter = (LPSTR) NULL;
  824. ofn.nMaxCustFilter = 0L;
  825. ofn.nFilterIndex = 1;
  826. ofn.lpstrFile = szFile;
  827. ofn.nMaxFile = sizeof(szFile);
  828. ofn.lpstrFileTitle = szFileTitle;
  829. ofn.nMaxFileTitle = sizeof(szFileTitle);
  830. ofn.lpstrInitialDir = szDirName;
  831. ofn.lpstrTitle = (LPSTR) NULL;
  832. ofn.Flags = 0L;
  833. ofn.nFileOffset = 0;
  834. ofn.nFileExtension = 0;
  835. ofn.lpstrDefExt = "LOG";
  836. if (!GetOpenFileName(&ofn))
  837. {
  838. return 0L;
  839. }
  840. if ((hLogFile = fopen (szFile, "at")) == (FILE *) NULL)
  841. {
  842. MessageBox(
  843. hwnd,
  844. "Error creating log file",
  845. gszSockEye,
  846. MB_OK
  847. );
  848. }
  849. else
  850. {
  851. struct tm *newtime;
  852. time_t aclock;
  853. time (&aclock);
  854. newtime = localtime (&aclock);
  855. fprintf(
  856. hLogFile,
  857. "\n---Log opened: %s\n",
  858. asctime (newtime)
  859. );
  860. CheckMenuItem(
  861. hMenu,
  862. IDM_LOGFILE,
  863. MF_BYCOMMAND | MF_CHECKED
  864. );
  865. }
  866. }
  867. break;
  868. }
  869. case IDM_USAGE:
  870. {
  871. static char szUsage[] =
  872. "ABSTRACT:\r\n" \
  873. " SockEye (the WinSock API Browser) allows a user " \
  874. "to interactively call into the Windows Sockets " \
  875. "API, modify parameters, and inspect all returned " \
  876. "information.\r\n" \
  877. "\r\n" \
  878. "GETTING STARTED:\r\n" \
  879. "1. Press the 'Startup' button to initialize WinSock\r\n" \
  880. "2. Double-click on items in the left-most window " \
  881. "to invoke the corresponding API. (Check the Params " \
  882. "checkbox in the upper left corner to change " \
  883. "parameters.)\r\n" \
  884. "* Press the 'Cleanup' button to shutdown WinSock\r\n" \
  885. "\r\n" \
  886. "MORE INFO:\r\n" \
  887. "* Choose 'Options/Default values...' to modify " \
  888. "default parameter values\r\n" \
  889. "* Choose 'Options/Record log file' to save all " \
  890. "output to a file.\r\n" \
  891. "* All parameter values in hexadecimal unless " \
  892. "specified (strings displayed by contents, not " \
  893. "pointer value).\r\n" \
  894. "* Choose 'Options/User buttons...' or press " \
  895. "one of the buttons on right side of toolbar to " \
  896. "create a personal hot-link between a button and a " \
  897. "particular function.";
  898. DialogBoxParam(
  899. ghInst,
  900. (LPCSTR)MAKEINTRESOURCE(IDD_DIALOG6),
  901. (HWND)hwnd,
  902. (DLGPROC) AboutDlgProc,
  903. (LPARAM) szUsage
  904. );
  905. break;
  906. }
  907. case IDM_NOHANDLECHK:
  908. gbDisableHandleChecking = (gbDisableHandleChecking ? 0 : 1);
  909. CheckMenuItem(
  910. hMenu,
  911. IDM_NOHANDLECHK,
  912. MF_BYCOMMAND |
  913. (gbDisableHandleChecking ? MF_CHECKED : MF_UNCHECKED)
  914. );
  915. break;
  916. case IDM_ABOUT:
  917. {
  918. DialogBoxParam(
  919. ghInst,
  920. (LPCSTR)MAKEINTRESOURCE(IDD_DIALOG4),
  921. (HWND)hwnd,
  922. (DLGPROC) AboutDlgProc,
  923. 0
  924. );
  925. break;
  926. }
  927. } // switch
  928. break;
  929. }
  930. case WM_ASYNCREQUESTCOMPLETED:
  931. {
  932. PASYNC_REQUEST_INFO pAsyncReqInfo;
  933. if ((pAsyncReqInfo = DequeueAsyncRequestInfo ((HANDLE) wParam)))
  934. {
  935. if (WSAGETASYNCERROR(lParam) == 0)
  936. {
  937. ShowStr(
  938. "Request x%x (%s) completed successfully",
  939. pAsyncReqInfo->hRequest,
  940. aFuncNames[pAsyncReqInfo->FuncIndex]
  941. );
  942. switch (pAsyncReqInfo->FuncIndex)
  943. {
  944. case ws_WSAAsyncGetHostByAddr:
  945. case ws_WSAAsyncGetHostByName:
  946. ShowHostEnt ((struct hostent *) (pAsyncReqInfo + 1));
  947. break;
  948. case ws_WSAAsyncGetProtoByName:
  949. case ws_WSAAsyncGetProtoByNumber:
  950. ShowProtoEnt ((struct protoent *) (pAsyncReqInfo + 1));
  951. break;
  952. case ws_WSAAsyncGetServByName:
  953. case ws_WSAAsyncGetServByPort:
  954. ShowServEnt ((struct servent *) (pAsyncReqInfo + 1));
  955. break;
  956. }
  957. }
  958. else
  959. {
  960. char FAR *pszError;
  961. for(
  962. i = 0;
  963. WSAGETASYNCERROR(lParam) != aWSAErrors[i].dwVal &&
  964. aWSAErrors[i].lpszVal;
  965. i++
  966. );
  967. pszError = (aWSAErrors[i].lpszVal ? aWSAErrors[i].lpszVal :
  968. gszUnknownError);
  969. ShowStr(
  970. "Request x%x (%s) completed unsuccessfully: %s (%d)",
  971. pAsyncReqInfo->hRequest,
  972. aFuncNames[pAsyncReqInfo->FuncIndex],
  973. pszError,
  974. (DWORD) WSAGETASYNCERROR(lParam)
  975. );
  976. }
  977. MyFree (pAsyncReqInfo);
  978. }
  979. else
  980. {
  981. }
  982. break;
  983. }
  984. case WM_NETWORKEVENT:
  985. // case WM_NETWORKEVENT: format info
  986. ShowStr ("WM_NETWORKEVENT: wParam=x%x, lParam=x%x", wParam ,lParam);
  987. break;
  988. #ifdef WIN32
  989. case WM_CTLCOLORBTN:
  990. SetBkColor ((HDC) wParam, RGB (192,192,192));
  991. return (INT_PTR) GetStockObject (LTGRAY_BRUSH);
  992. #else
  993. case WM_CTLCOLOR:
  994. {
  995. if (HIWORD(lParam) == CTLCOLOR_BTN)
  996. {
  997. SetBkColor ((HDC) wParam, RGB (192,192,192));
  998. return (INT_PTR) GetStockObject (LTGRAY_BRUSH);
  999. }
  1000. break;
  1001. }
  1002. #endif
  1003. case WM_MOUSEMOVE:
  1004. {
  1005. LONG x = (LONG)((short)LOWORD(lParam));
  1006. int y = (int)((short)HIWORD(lParam));
  1007. if ((y > icyButton && (x < (cxList2 + icyBorder) ||
  1008. x > (cxList2 + icyBorder + cxList1))) ||
  1009. lCaptureFlags)
  1010. {
  1011. SetCursor (LoadCursor (NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
  1012. }
  1013. if (lCaptureFlags == 1)
  1014. {
  1015. int cxList2New;
  1016. x = (x > (cxList1 + cxList2 - cxVScroll) ?
  1017. (cxList1 + cxList2 - cxVScroll) : x);
  1018. x = (x < cxVScroll ? cxVScroll : x);
  1019. cxList2New = (int) (cxList2 + x - xCapture);
  1020. SetWindowPos(
  1021. ghwndList2,
  1022. GetNextWindow (ghwndList2, GW_HWNDPREV),
  1023. 0,
  1024. icyButton,
  1025. cxList2New,
  1026. cyWnd,
  1027. SWP_SHOWWINDOW
  1028. );
  1029. SetWindowPos(
  1030. ghwndList3,
  1031. GetNextWindow (ghwndList3, GW_HWNDPREV),
  1032. cxList2New + icyBorder,
  1033. icyButton + (cyWnd - icyBorder) / 2 + icyBorder,
  1034. (int) (cxList1 - (x - xCapture)),
  1035. (cyWnd - icyBorder) / 2,
  1036. SWP_SHOWWINDOW
  1037. );
  1038. SetWindowPos(
  1039. ghwndList1,
  1040. GetNextWindow (ghwndList1, GW_HWNDPREV),
  1041. cxList2New + icyBorder,
  1042. icyButton,
  1043. (int) (cxList1 - (x - xCapture)),
  1044. (cyWnd - icyBorder) / 2,
  1045. SWP_SHOWWINDOW
  1046. );
  1047. }
  1048. else if (lCaptureFlags == 2)
  1049. {
  1050. int cxList1New;
  1051. x = (x < (cxList2 + cxVScroll) ? (cxList2 + cxVScroll) : x);
  1052. x = (x > (cxWnd - cxVScroll) ? (cxWnd - cxVScroll) : x);
  1053. cxList1New = (int) (cxList1 + x - xCapture);
  1054. SetWindowPos(
  1055. ghwndList1,
  1056. GetNextWindow (ghwndList1, GW_HWNDPREV),
  1057. (int) cxList2 + icyBorder,
  1058. icyButton,
  1059. cxList1New,
  1060. (cyWnd - icyBorder) / 2,
  1061. SWP_SHOWWINDOW
  1062. );
  1063. SetWindowPos(
  1064. ghwndList3,
  1065. GetNextWindow (ghwndList3, GW_HWNDPREV),
  1066. (int) cxList2 + icyBorder,
  1067. icyButton + (cyWnd - icyBorder) / 2 + icyBorder,
  1068. cxList1New,
  1069. (cyWnd - icyBorder) / 2,
  1070. SWP_SHOWWINDOW
  1071. );
  1072. SetWindowPos(
  1073. ghwndEdit,
  1074. GetNextWindow (ghwndEdit, GW_HWNDPREV),
  1075. (int) (cxList1New + cxList2) + 2*icyBorder,
  1076. icyButton,
  1077. (int)cxWnd - (cxList1New + (int)cxList2 + 2*icyBorder),
  1078. cyWnd,
  1079. SWP_SHOWWINDOW
  1080. );
  1081. }
  1082. break;
  1083. }
  1084. case WM_LBUTTONDOWN:
  1085. {
  1086. if ((int)((short)HIWORD(lParam)) > icyButton)
  1087. {
  1088. xCapture = (LONG)LOWORD(lParam);
  1089. if (xCapture > (cxList2 + icyBorder) &&
  1090. xCapture < (cxList2 + icyBorder + cxList1))
  1091. {
  1092. break;
  1093. }
  1094. SetCapture (hwnd);
  1095. lCaptureFlags = ((xCapture < cxList1 + cxList2) ? 1 : 2);
  1096. }
  1097. break;
  1098. }
  1099. case WM_LBUTTONUP:
  1100. {
  1101. if (lCaptureFlags)
  1102. {
  1103. POINT p;
  1104. LONG x;
  1105. RECT rect = { 0, icyButton, 2000, 2000 };
  1106. GetCursorPos (&p);
  1107. MapWindowPoints (HWND_DESKTOP, hwnd, &p, 1);
  1108. x = (LONG) p.x;
  1109. ReleaseCapture();
  1110. if (lCaptureFlags == 1)
  1111. {
  1112. x = (x < cxVScroll ? cxVScroll : x);
  1113. x = (x > (cxList1 + cxList2 - cxVScroll) ?
  1114. (cxList1 + cxList2 - cxVScroll) : x);
  1115. cxList2 = cxList2 + (x - xCapture);
  1116. cxList1 = cxList1 - (x - xCapture);
  1117. rect.right = (int) (cxList1 + cxList2) + icyBorder;
  1118. }
  1119. else
  1120. {
  1121. x = (x < (cxList2 + cxVScroll) ?
  1122. (cxList2 + cxVScroll) : x);
  1123. x = (x > (cxWnd - cxVScroll) ?
  1124. (cxWnd - cxVScroll) : x);
  1125. cxList1 = cxList1 + (x - xCapture);
  1126. rect.left = (int)cxList2 + icyBorder;
  1127. }
  1128. lCaptureFlags = 0;
  1129. InvalidateRect (hwnd, &rect, TRUE);
  1130. }
  1131. break;
  1132. }
  1133. case WM_SIZE:
  1134. {
  1135. if (wParam != SIZE_MINIMIZED)
  1136. {
  1137. LONG width = (LONG)LOWORD(lParam);
  1138. //
  1139. // Adjust globals based on new size
  1140. //
  1141. cxWnd = (cxWnd ? cxWnd : 1); // avoid div by 0
  1142. cxList1 = (cxList1 * width) / cxWnd;
  1143. cxList2 = (cxList2 * width) / cxWnd;
  1144. cxWnd = width;
  1145. cyWnd = ((int)HIWORD(lParam)) - icyButton;
  1146. //
  1147. // Now reposition the child windows
  1148. //
  1149. SetWindowPos(
  1150. ghwndList2,
  1151. GetNextWindow (ghwndList2, GW_HWNDPREV),
  1152. 0,
  1153. icyButton,
  1154. (int) cxList2,
  1155. cyWnd,
  1156. SWP_SHOWWINDOW
  1157. );
  1158. SetWindowPos(
  1159. ghwndList1,
  1160. GetNextWindow (ghwndList1, GW_HWNDPREV),
  1161. (int) cxList2 + icyBorder,
  1162. icyButton,
  1163. (int) cxList1,
  1164. (cyWnd - icyBorder) / 2,
  1165. SWP_SHOWWINDOW
  1166. );
  1167. SetWindowPos(
  1168. ghwndList3,
  1169. GetNextWindow (ghwndList3, GW_HWNDPREV),
  1170. (int) cxList2 + icyBorder,
  1171. icyButton + (cyWnd - icyBorder) / 2 + icyBorder,
  1172. (int) cxList1,
  1173. (cyWnd - icyBorder) / 2,
  1174. SWP_SHOWWINDOW
  1175. );
  1176. SetWindowPos(
  1177. ghwndEdit,
  1178. GetNextWindow (ghwndEdit, GW_HWNDPREV),
  1179. (int) (cxList1 + cxList2) + 2*icyBorder,
  1180. icyButton,
  1181. (int)width - ((int)(cxList1 + cxList2) + 2*icyBorder),
  1182. cyWnd,
  1183. SWP_SHOWWINDOW
  1184. );
  1185. InvalidateRect (hwnd, NULL, TRUE);
  1186. }
  1187. break;
  1188. }
  1189. case WM_PAINT:
  1190. {
  1191. PAINTSTRUCT ps;
  1192. BeginPaint (hwnd, &ps);
  1193. if (IsIconic (hwnd))
  1194. {
  1195. DrawIcon (ps.hdc, 0, 0, hIcon);
  1196. }
  1197. else
  1198. {
  1199. FillRect (ps.hdc, &ps.rcPaint, GetStockObject (LTGRAY_BRUSH));
  1200. #ifdef WIN32
  1201. MoveToEx (ps.hdc, 0, 0, NULL);
  1202. #else
  1203. MoveTo (ps.hdc, 0, 0);
  1204. #endif
  1205. LineTo (ps.hdc, 5000, 0);
  1206. #ifdef WIN32
  1207. MoveToEx (ps.hdc, 0, icyButton - 4, NULL);
  1208. #else
  1209. MoveTo (ps.hdc, 0, icyButton - 4);
  1210. #endif
  1211. LineTo (ps.hdc, 5000, icyButton - 4);
  1212. }
  1213. EndPaint (hwnd, &ps);
  1214. break;
  1215. }
  1216. case WM_TIMER:
  1217. //
  1218. // Enter alterable wait state to cause any queued APCs to fire
  1219. // (might be able to use SleepEx() instead)
  1220. //
  1221. WaitForSingleObjectEx (hTimerEvent, 0, TRUE);
  1222. break;
  1223. case WM_CLOSE:
  1224. {
  1225. BOOL bAutoShutdown = FALSE;
  1226. RECT rect;
  1227. //
  1228. //
  1229. //
  1230. KillTimer (hwnd, TIMER_ID);
  1231. CloseHandle (hTimerEvent);
  1232. //
  1233. // Give user chance to cancel and auto-shutdown any init instances
  1234. //
  1235. if (giCurrNumStartups > 0)
  1236. {
  1237. int iResult;
  1238. if ((iResult = MessageBox(
  1239. hwnd,
  1240. "Cleanup existing Startup instances? (recommended)",
  1241. "SockEye closing",
  1242. MB_YESNOCANCEL
  1243. )) == IDYES)
  1244. {
  1245. bShowParams = FALSE;
  1246. while (giCurrNumStartups > 0)
  1247. {
  1248. FuncDriver (ws_WSACleanup);
  1249. }
  1250. }
  1251. else if (iResult == IDCANCEL)
  1252. {
  1253. break;
  1254. }
  1255. }
  1256. //
  1257. // Save defaults in ini file
  1258. //
  1259. {
  1260. char buf[32];
  1261. typedef struct _DEF_VALUE2
  1262. {
  1263. char far *lpszEntry;
  1264. ULONG_PTR dwValue;
  1265. } DEF_VALUE2;
  1266. DEF_VALUE2 aDefVals[] =
  1267. {
  1268. { "BufSize", dwBigBufSize },
  1269. { "UserButton1", aUserButtonFuncs[0] },
  1270. { "UserButton2", aUserButtonFuncs[1] },
  1271. { "UserButton3", aUserButtonFuncs[2] },
  1272. { "UserButton4", aUserButtonFuncs[3] },
  1273. { "UserButton5", aUserButtonFuncs[4] },
  1274. { "UserButton6", aUserButtonFuncs[5] },
  1275. { "Initialized", 1 },
  1276. { gszAddressFamily, gdwDefAddrFamily },
  1277. { gszSocketType, gdwDefSocketType },
  1278. { gszProtocol, gdwDefProtocol },
  1279. { gszProtocolNumber, gdwDefProtoNum },
  1280. { gszPortNumber, gdwDefPortNum },
  1281. { gszIoctlCommand, gdwDefIoctlCmd },
  1282. { gszSendFlags, gdwDefSendFlags },
  1283. { gszRecvFlags, gdwDefRecvFlags },
  1284. { gszWSASocketFlags, gdwDefWSASocketFlags },
  1285. { NULL, 0 },
  1286. { gszHostName, (ULONG_PTR) gszDefHostName },
  1287. { gszProtocolName, (ULONG_PTR) gszDefProtoName },
  1288. { gszServiceName, (ULONG_PTR) gszDefServName },
  1289. { "UserButton1Text", (ULONG_PTR) &aUserButtonsText[0] },
  1290. { "UserButton2Text", (ULONG_PTR) &aUserButtonsText[1] },
  1291. { "UserButton3Text", (ULONG_PTR) &aUserButtonsText[2] },
  1292. { "UserButton4Text", (ULONG_PTR) &aUserButtonsText[3] },
  1293. { "UserButton5Text", (ULONG_PTR) &aUserButtonsText[4] },
  1294. { "UserButton6Text", (ULONG_PTR) &aUserButtonsText[5] },
  1295. { NULL, 0 }
  1296. };
  1297. int i;
  1298. for (i = 0; aDefVals[i].lpszEntry; i++)
  1299. {
  1300. sprintf (buf, "%lx", aDefVals[i].dwValue);
  1301. WriteProfileString(
  1302. gszSockEye,
  1303. aDefVals[i].lpszEntry,
  1304. buf
  1305. );
  1306. }
  1307. i++;
  1308. for (; aDefVals[i].lpszEntry; i++)
  1309. {
  1310. WriteProfileString(
  1311. gszSockEye,
  1312. aDefVals[i].lpszEntry,
  1313. (LPCSTR) aDefVals[i].dwValue
  1314. );
  1315. }
  1316. //
  1317. // Save the window dimensions (if iconic then don't bother)
  1318. //
  1319. if (!IsIconic (hwnd))
  1320. {
  1321. if (IsZoomed (hwnd))
  1322. {
  1323. strcpy (buf, "max");
  1324. }
  1325. else
  1326. {
  1327. GetWindowRect (hwnd, &rect);
  1328. sprintf(
  1329. buf,
  1330. "%d,%d,%d,%d",
  1331. rect.left,
  1332. rect.top,
  1333. rect.right,
  1334. rect.bottom
  1335. );
  1336. }
  1337. WriteProfileString(
  1338. gszSockEye,
  1339. "Position",
  1340. (LPCSTR) buf
  1341. );
  1342. sprintf (buf, "%ld,%ld,%ld", cxList2, cxList1, cxWnd);
  1343. WriteProfileString(
  1344. gszSockEye,
  1345. "ControlRatios",
  1346. (LPCSTR) buf
  1347. );
  1348. }
  1349. }
  1350. if (hLogFile)
  1351. {
  1352. fclose (hLogFile);
  1353. }
  1354. DestroyIcon (hIcon);
  1355. MyFree (pBigBuf);
  1356. DeleteObject (hFont);
  1357. DeleteObject (hFont2);
  1358. PostQuitMessage (0);
  1359. break;
  1360. }
  1361. } //switch
  1362. return FALSE;
  1363. }
  1364. INT_PTR
  1365. CALLBACK
  1366. AboutDlgProc(
  1367. HWND hwnd,
  1368. UINT msg,
  1369. WPARAM wParam,
  1370. LPARAM lParam
  1371. )
  1372. {
  1373. switch (msg)
  1374. {
  1375. case WM_INITDIALOG:
  1376. if (lParam)
  1377. {
  1378. SetDlgItemText (hwnd, IDC_EDIT1, (LPCSTR) lParam);
  1379. }
  1380. break;
  1381. case WM_COMMAND:
  1382. switch (LOWORD(wParam))
  1383. {
  1384. case IDOK:
  1385. EndDialog (hwnd, 0);
  1386. break;
  1387. }
  1388. break;
  1389. #ifdef WIN32
  1390. case WM_CTLCOLORSTATIC:
  1391. SetBkColor ((HDC) wParam, RGB (192,192,192));
  1392. return (INT_PTR) GetStockObject (LTGRAY_BRUSH);
  1393. #else
  1394. case WM_CTLCOLOR:
  1395. {
  1396. if (HIWORD(lParam) == CTLCOLOR_STATIC)
  1397. {
  1398. SetBkColor ((HDC) wParam, RGB (192,192,192));
  1399. return (INT_PTR) GetStockObject (LTGRAY_BRUSH);
  1400. }
  1401. break;
  1402. }
  1403. #endif
  1404. case WM_PAINT:
  1405. {
  1406. PAINTSTRUCT ps;
  1407. BeginPaint (hwnd, &ps);
  1408. FillRect (ps.hdc, &ps.rcPaint, GetStockObject (LTGRAY_BRUSH));
  1409. EndPaint (hwnd, &ps);
  1410. break;
  1411. }
  1412. }
  1413. return FALSE;
  1414. }
  1415. void
  1416. FAR
  1417. ShowStr(
  1418. LPCSTR format,
  1419. ...
  1420. )
  1421. {
  1422. char buf[256];
  1423. va_list ap;
  1424. va_start(ap, format);
  1425. vsprintf (buf, format, ap);
  1426. if (hLogFile)
  1427. {
  1428. fprintf (hLogFile, "%s\n", buf);
  1429. }
  1430. strcat (buf, "\r\n");
  1431. //
  1432. // Insert text at end
  1433. //
  1434. #ifdef WIN32
  1435. SendMessage (ghwndEdit, EM_SETSEL, (WPARAM)0xfffffffd, (LPARAM)0xfffffffe);
  1436. #else
  1437. SendMessage(
  1438. ghwndEdit,
  1439. EM_SETSEL,
  1440. (WPARAM)0,
  1441. (LPARAM) MAKELONG(0xfffd,0xfffe)
  1442. );
  1443. #endif
  1444. SendMessage (ghwndEdit, EM_REPLACESEL, 0, (LPARAM) buf);
  1445. #ifdef WIN32
  1446. //
  1447. // Scroll to end of text
  1448. //
  1449. SendMessage (ghwndEdit, EM_SCROLLCARET, 0, 0);
  1450. #endif
  1451. va_end(ap);
  1452. }
  1453. INT_PTR
  1454. CALLBACK
  1455. ParamsDlgProc(
  1456. HWND hwnd,
  1457. UINT msg,
  1458. WPARAM wParam,
  1459. LPARAM lParam
  1460. )
  1461. {
  1462. DWORD i;
  1463. typedef struct _DLG_INST_DATA
  1464. {
  1465. PFUNC_PARAM_HEADER pParamsHeader;
  1466. LRESULT lLastSel;
  1467. char szComboText[MAX_STRING_PARAM_SIZE];
  1468. } DLG_INST_DATA, *PDLG_INST_DATA;
  1469. PDLG_INST_DATA pDlgInstData = (PDLG_INST_DATA)
  1470. GetWindowLongPtr (hwnd, DWLP_USER);
  1471. static int icxList2, icyList2, icyEdit1;
  1472. switch (msg)
  1473. {
  1474. case WM_INITDIALOG:
  1475. {
  1476. //
  1477. // Alloc a dlg instance data struct, init it, & save a ptr to it
  1478. //
  1479. pDlgInstData = (PDLG_INST_DATA) MyAlloc (sizeof(DLG_INST_DATA));
  1480. if (pDlgInstData == NULL) {
  1481. EndDialog(hwnd, 0);
  1482. return (FALSE);
  1483. }
  1484. pDlgInstData->pParamsHeader = (PFUNC_PARAM_HEADER) lParam;
  1485. pDlgInstData->lLastSel = -1;
  1486. SetWindowLongPtr (hwnd, DWLP_USER, (LPARAM) pDlgInstData);
  1487. //
  1488. // Stick all the param names in the listbox, & for each PT_DWORD
  1489. // param save it's default value
  1490. //
  1491. for (i = 0; i < pDlgInstData->pParamsHeader->dwNumParams; i++)
  1492. {
  1493. SendDlgItemMessage(
  1494. hwnd,
  1495. IDC_LIST1,
  1496. LB_INSERTSTRING,
  1497. (WPARAM) -1,
  1498. (LPARAM) pDlgInstData->pParamsHeader->aParams[i].szName
  1499. );
  1500. if (pDlgInstData->pParamsHeader->aParams[i].dwType == PT_DWORD)
  1501. {
  1502. pDlgInstData->pParamsHeader->aParams[i].u.dwDefValue = (ULONG_PTR)
  1503. pDlgInstData->pParamsHeader->aParams[i].dwValue;
  1504. }
  1505. }
  1506. //
  1507. // Set the dlg title as appropriate
  1508. //
  1509. // help if (pDlgInstData->pParamsHeader->FuncIndex == DefValues)
  1510. // help {
  1511. // help EnableWindow (GetDlgItem (hwnd, IDC_TB_HELP), FALSE);
  1512. // help }
  1513. SetWindowText(
  1514. hwnd,
  1515. aFuncNames[pDlgInstData->pParamsHeader->FuncIndex]
  1516. );
  1517. //
  1518. // Limit the max text length for the combobox's edit field
  1519. // (NOTE: A combobox ctrl actually has two child windows: a
  1520. // edit ctrl & a listbox. We need to get the hwnd of the
  1521. // child edit ctrl & send it the LIMITTEXT msg.)
  1522. //
  1523. {
  1524. HWND hwndChild =
  1525. GetWindow (GetDlgItem (hwnd, IDC_COMBO1), GW_CHILD);
  1526. while (hwndChild)
  1527. {
  1528. char buf[8];
  1529. GetClassName (hwndChild, buf, 7);
  1530. if (_stricmp (buf, "edit") == 0)
  1531. {
  1532. break;
  1533. }
  1534. hwndChild = GetWindow (hwndChild, GW_HWNDNEXT);
  1535. }
  1536. SendMessage(
  1537. hwndChild,
  1538. EM_LIMITTEXT,
  1539. (WPARAM) (gbWideStringParams ?
  1540. (MAX_STRING_PARAM_SIZE/2 - 1) : MAX_STRING_PARAM_SIZE - 1),
  1541. 0
  1542. );
  1543. }
  1544. {
  1545. RECT rect;
  1546. GetWindowRect (GetDlgItem (hwnd, IDC_LIST2), &rect);
  1547. SetWindowPos(
  1548. GetDlgItem (hwnd, IDC_LIST2),
  1549. NULL,
  1550. 0,
  1551. 0,
  1552. 0,
  1553. 0,
  1554. SWP_NOMOVE | SWP_NOZORDER
  1555. );
  1556. icxList2 = rect.right - rect.left;
  1557. icyList2 = rect.bottom - rect.top;
  1558. GetWindowRect (GetDlgItem (hwnd, 58), &rect);
  1559. icyEdit1 = icyList2 - (rect.bottom - rect.top);
  1560. }
  1561. SendDlgItemMessage(
  1562. hwnd,
  1563. IDC_EDIT1,
  1564. WM_SETFONT,
  1565. (WPARAM) ghFixedFont,
  1566. 0
  1567. );
  1568. break;
  1569. }
  1570. case WM_COMMAND:
  1571. {
  1572. LRESULT lLastSel = pDlgInstData->lLastSel;
  1573. char far *lpszComboText = pDlgInstData->szComboText;
  1574. PFUNC_PARAM_HEADER pParamsHeader = pDlgInstData->pParamsHeader;
  1575. switch (LOWORD(wParam))
  1576. {
  1577. case IDC_EDIT1:
  1578. {
  1579. if (HIWORD(wParam) == EN_CHANGE)
  1580. {
  1581. //
  1582. // Don't allow the user to enter characters other than
  1583. // 0-9, a-f, or A-F in the edit control (do this by
  1584. // hiliting other letters and cutting them).
  1585. //
  1586. HWND hwndEdit = GetDlgItem (hwnd, IDC_EDIT1);
  1587. DWORD dwLength, j;
  1588. BYTE *p;
  1589. dwLength = (DWORD) GetWindowTextLength (hwndEdit);
  1590. if (dwLength && (p = MyAlloc (dwLength + 1)))
  1591. {
  1592. GetWindowText (hwndEdit, p, dwLength + 1);
  1593. for (i = j = 0; i < dwLength ; i++, j++)
  1594. {
  1595. if (aHex[p[i]] == 255)
  1596. {
  1597. SendMessage(
  1598. hwndEdit,
  1599. EM_SETSEL,
  1600. (WPARAM) j,
  1601. (LPARAM) j + 1 // 0xfffffffe
  1602. );
  1603. SendMessage (hwndEdit, EM_REPLACESEL, 0, (LPARAM) "");
  1604. SendMessage (hwndEdit, EM_SCROLLCARET, 0, 0);
  1605. j--;
  1606. }
  1607. }
  1608. MyFree (p);
  1609. }
  1610. }
  1611. break;
  1612. }
  1613. case IDOK:
  1614. // if gbWideStringParams convert ascii -> unicode
  1615. if (lLastSel != -1)
  1616. {
  1617. //
  1618. // Save val of currently selected param
  1619. //
  1620. char buf[MAX_STRING_PARAM_SIZE];
  1621. i = GetDlgItemText (hwnd, IDC_COMBO1, buf, MAX_STRING_PARAM_SIZE-1);
  1622. switch (pParamsHeader->aParams[lLastSel].dwType)
  1623. {
  1624. case PT_STRING:
  1625. {
  1626. LRESULT lComboSel;
  1627. lComboSel = SendDlgItemMessage(
  1628. hwnd,
  1629. IDC_COMBO1,
  1630. CB_GETCURSEL,
  1631. 0,
  1632. 0
  1633. );
  1634. if (lComboSel == 0) // "NULL pointer"
  1635. {
  1636. pParamsHeader->aParams[lLastSel].dwValue = 0;
  1637. }
  1638. else if (lComboSel == 2) // "Invalid string pointer"
  1639. {
  1640. pParamsHeader->aParams[lLastSel].dwValue = (ULONG_PTR)
  1641. -1;
  1642. }
  1643. else // "Valid string pointer"
  1644. {
  1645. strncpy(
  1646. pParamsHeader->aParams[lLastSel].u.buf,
  1647. buf,
  1648. MAX_STRING_PARAM_SIZE - 1
  1649. );
  1650. pParamsHeader->aParams[lLastSel].u.buf[MAX_STRING_PARAM_SIZE-1] = 0;
  1651. pParamsHeader->aParams[lLastSel].dwValue = (ULONG_PTR)
  1652. pParamsHeader->aParams[lLastSel].u.buf;
  1653. }
  1654. break;
  1655. }
  1656. case PT_POINTER:
  1657. {
  1658. //
  1659. // If there is any text in the "Buffer byte editor"
  1660. // window then retrieve it, convert it to hexadecimal,
  1661. // and copy it to the buffer
  1662. //
  1663. DWORD dwLength;
  1664. BYTE *p, *p2,
  1665. *pBuf = pParamsHeader->aParams[lLastSel].u.ptr;
  1666. HWND hwndEdit = GetDlgItem (hwnd,IDC_EDIT1);
  1667. dwLength = (DWORD) GetWindowTextLength (hwndEdit);
  1668. if (dwLength && (p = MyAlloc (dwLength + 1)))
  1669. {
  1670. GetWindowText (hwndEdit, p, dwLength + 1);
  1671. SetWindowText (hwndEdit, "");
  1672. p2 = p;
  1673. p[dwLength] = (BYTE) '0';
  1674. dwLength = (dwLength + 1) & 0xfffffffe;
  1675. for (i = 0; i < dwLength; i++, i++)
  1676. {
  1677. BYTE b;
  1678. b = aHex[*p] << 4;
  1679. p++;
  1680. b |= aHex[*p];
  1681. p++;
  1682. *pBuf = b;
  1683. pBuf++;
  1684. }
  1685. MyFree (p2);
  1686. }
  1687. // fall thru to code below
  1688. }
  1689. case PT_DWORD:
  1690. case PT_FLAGS:
  1691. case PT_ORDINAL:
  1692. case PT_WSAPROTOCOLINFO:
  1693. case PT_QOS:
  1694. case PT_PTRNOEDIT:
  1695. {
  1696. if (!sscanf(
  1697. buf,
  1698. "%08lx",
  1699. &pParamsHeader->aParams[lLastSel].dwValue
  1700. ))
  1701. {
  1702. //
  1703. // Default to 0
  1704. //
  1705. pParamsHeader->aParams[lLastSel].dwValue = 0;
  1706. }
  1707. break;
  1708. }
  1709. } // switch
  1710. }
  1711. //
  1712. // Convert any unicode string params as appropriate
  1713. //
  1714. if (gbWideStringParams)
  1715. {
  1716. DWORD dwNumParams = pParamsHeader->dwNumParams, i;
  1717. PFUNC_PARAM pParam = pParamsHeader->aParams;
  1718. for (i = 0; i < dwNumParams; i++)
  1719. {
  1720. if (pParam->dwType == PT_STRING &&
  1721. pParam->dwValue != 0 &&
  1722. pParam->dwValue != 0xffffffff)
  1723. {
  1724. int len = lstrlenA ((char *) pParam->dwValue) + 1;
  1725. WCHAR buf[MAX_STRING_PARAM_SIZE/2];
  1726. MultiByteToWideChar(
  1727. GetACP(),
  1728. MB_PRECOMPOSED,
  1729. (LPCSTR) pParam->dwValue,
  1730. (len > MAX_STRING_PARAM_SIZE/2 ?
  1731. MAX_STRING_PARAM_SIZE/2 - 1 : -1),
  1732. buf,
  1733. MAX_STRING_PARAM_SIZE/2
  1734. );
  1735. buf[MAX_STRING_PARAM_SIZE/2 - 1] = 0;
  1736. lstrcpyW ((WCHAR *) pParam->dwValue, buf);
  1737. }
  1738. pParam++;
  1739. }
  1740. }
  1741. MyFree (pDlgInstData);
  1742. EndDialog (hwnd, TRUE);
  1743. break;
  1744. case IDCANCEL:
  1745. MyFree (pDlgInstData);
  1746. EndDialog (hwnd, FALSE);
  1747. break;
  1748. case IDC_LIST1:
  1749. #ifdef WIN32
  1750. if (HIWORD(wParam) == LBN_SELCHANGE)
  1751. #else
  1752. if (HIWORD(lParam) == LBN_SELCHANGE)
  1753. #endif
  1754. {
  1755. char buf[MAX_STRING_PARAM_SIZE] = "";
  1756. LPCSTR lpstr = buf;
  1757. LRESULT lSel =
  1758. SendDlgItemMessage (hwnd, IDC_LIST1, LB_GETCURSEL, 0, 0);
  1759. if (lLastSel != -1)
  1760. {
  1761. //
  1762. // Save the old param value
  1763. //
  1764. i = GetDlgItemText(
  1765. hwnd,
  1766. IDC_COMBO1,
  1767. buf,
  1768. MAX_STRING_PARAM_SIZE - 1
  1769. );
  1770. switch (pParamsHeader->aParams[lLastSel].dwType)
  1771. {
  1772. case PT_STRING:
  1773. {
  1774. LRESULT lComboSel;
  1775. lComboSel = SendDlgItemMessage(
  1776. hwnd,
  1777. IDC_COMBO1,
  1778. CB_GETCURSEL,
  1779. 0,
  1780. 0
  1781. );
  1782. if (lComboSel == 0) // "NULL pointer"
  1783. {
  1784. pParamsHeader->aParams[lLastSel].dwValue = (DWORD)0;
  1785. }
  1786. else if (lComboSel == 2) // "Invalid string pointer"
  1787. {
  1788. pParamsHeader->aParams[lLastSel].dwValue = (DWORD)
  1789. 0xffffffff;
  1790. }
  1791. else // "Valid string pointer" or no sel
  1792. {
  1793. strncpy(
  1794. pParamsHeader->aParams[lLastSel].u.buf,
  1795. buf,
  1796. MAX_STRING_PARAM_SIZE - 1
  1797. );
  1798. pParamsHeader->aParams[lLastSel].u.buf[MAX_STRING_PARAM_SIZE - 1] = 0;
  1799. pParamsHeader->aParams[lLastSel].dwValue = (ULONG_PTR)
  1800. pParamsHeader->aParams[lLastSel].u.buf;
  1801. }
  1802. break;
  1803. }
  1804. case PT_POINTER:
  1805. {
  1806. //
  1807. // If there is any text in the "Buffer byte editor"
  1808. // window then retrieve it, convert it to hexadecimal,
  1809. // and copy it to the buffer
  1810. //
  1811. DWORD dwLength;
  1812. BYTE *p, *p2,
  1813. *pBuf = pParamsHeader->aParams[lLastSel].u.ptr;
  1814. HWND hwndEdit = GetDlgItem (hwnd,IDC_EDIT1);
  1815. dwLength = (DWORD) GetWindowTextLength (hwndEdit);
  1816. if (dwLength && (p = MyAlloc (dwLength + 1)))
  1817. {
  1818. GetWindowText (hwndEdit, p, dwLength + 1);
  1819. SetWindowText (hwndEdit, "");
  1820. p2 = p;
  1821. p[dwLength] = (BYTE) '0';
  1822. dwLength = (dwLength + 1) & 0xfffffffe;
  1823. for (i = 0; i < dwLength; i+= 2)
  1824. {
  1825. BYTE b;
  1826. b = aHex[*p] << 4;
  1827. p++;
  1828. b |= aHex[*p];
  1829. p++;
  1830. *pBuf = b;
  1831. pBuf++;
  1832. }
  1833. MyFree (p2);
  1834. }
  1835. // fall thru to code below
  1836. }
  1837. case PT_DWORD:
  1838. case PT_FLAGS:
  1839. case PT_ORDINAL:
  1840. case PT_WSAPROTOCOLINFO:
  1841. case PT_QOS:
  1842. case PT_PTRNOEDIT:
  1843. {
  1844. if (!sscanf(
  1845. buf,
  1846. "%08lx",
  1847. &pParamsHeader->aParams[lLastSel].dwValue
  1848. ))
  1849. {
  1850. //
  1851. // Default to 0
  1852. //
  1853. pParamsHeader->aParams[lLastSel].dwValue = 0;
  1854. }
  1855. break;
  1856. }
  1857. } // switch
  1858. }
  1859. SendDlgItemMessage (hwnd, IDC_LIST2, LB_RESETCONTENT, 0, 0);
  1860. SendDlgItemMessage (hwnd, IDC_COMBO1, CB_RESETCONTENT, 0, 0);
  1861. {
  1862. int icxL2, icyL2, icxE1, icyE1;
  1863. char FAR *pszS1, *pszS2;
  1864. static char szBitFlags[] = "Bit flags:";
  1865. static char szOrdinalValues[] = "Ordinal values:";
  1866. static char szBufByteEdit[] =
  1867. "Buffer byte editor (use 0-9, a-f, A-F)";
  1868. switch (pParamsHeader->aParams[lSel].dwType)
  1869. {
  1870. case PT_DWORD:
  1871. case PT_STRING:
  1872. case PT_WSAPROTOCOLINFO:
  1873. case PT_QOS:
  1874. case PT_PTRNOEDIT:
  1875. icxL2 = icyL2 = icxE1 = icxE1 = 0;
  1876. pszS1 = pszS2 = NULL;
  1877. break;
  1878. case PT_FLAGS:
  1879. icxL2 = icxList2;
  1880. icyL2 = icyList2;
  1881. icxE1 = icyE1 = 0;
  1882. pszS1 = szBitFlags;
  1883. pszS2 = NULL;
  1884. break;
  1885. case PT_POINTER:
  1886. icxL2 = icyL2 = 0;
  1887. icxE1 = icxList2;
  1888. icyE1 = icyEdit1;;
  1889. pszS1 = szBufByteEdit;
  1890. pszS2 = gszEnterAs;
  1891. break;
  1892. case PT_ORDINAL:
  1893. icxL2 = icxList2;
  1894. icyL2 = icyList2;
  1895. icxE1 = icyE1 = 0;
  1896. pszS1 = szOrdinalValues;
  1897. pszS2 = NULL;
  1898. break;
  1899. }
  1900. SetWindowPos(
  1901. GetDlgItem (hwnd, IDC_LIST2),
  1902. NULL,
  1903. 0,
  1904. 0,
  1905. icxL2,
  1906. icyL2,
  1907. SWP_NOMOVE | SWP_NOZORDER
  1908. );
  1909. SetWindowPos(
  1910. GetDlgItem (hwnd, IDC_EDIT1),
  1911. NULL,
  1912. 0,
  1913. 0,
  1914. icxE1,
  1915. icyE1,
  1916. SWP_NOMOVE | SWP_NOZORDER
  1917. );
  1918. SetDlgItemText (hwnd, 57, pszS1);
  1919. SetDlgItemText (hwnd, 58, pszS2);
  1920. }
  1921. switch (pParamsHeader->aParams[lSel].dwType)
  1922. {
  1923. case PT_STRING:
  1924. {
  1925. char * aszOptions[] =
  1926. {
  1927. "NULL pointer",
  1928. "Valid string pointer",
  1929. "Invalid string pointer"
  1930. };
  1931. for (i = 0; i < 3; i++)
  1932. {
  1933. SendDlgItemMessage(
  1934. hwnd,
  1935. IDC_COMBO1,
  1936. CB_INSERTSTRING,
  1937. (WPARAM) -1,
  1938. (LPARAM) aszOptions[i]
  1939. );
  1940. }
  1941. if (pParamsHeader->aParams[lSel].dwValue == 0)
  1942. {
  1943. i = 0;
  1944. buf[0] = 0;
  1945. }
  1946. else if (pParamsHeader->aParams[lSel].dwValue != 0xffffffff)
  1947. {
  1948. i = 1;
  1949. lpstr = (LPCSTR) pParamsHeader->aParams[lSel].dwValue;
  1950. }
  1951. else
  1952. {
  1953. i = 2;
  1954. buf[0] = 0;
  1955. }
  1956. SendDlgItemMessage(
  1957. hwnd,
  1958. IDC_COMBO1,
  1959. CB_SETCURSEL,
  1960. (WPARAM) i,
  1961. 0
  1962. );
  1963. break;
  1964. }
  1965. case PT_POINTER:
  1966. case PT_WSAPROTOCOLINFO:
  1967. case PT_QOS:
  1968. case PT_PTRNOEDIT:
  1969. {
  1970. SendDlgItemMessage(
  1971. hwnd,
  1972. IDC_COMBO1,
  1973. CB_INSERTSTRING,
  1974. (WPARAM) -1,
  1975. (LPARAM) "00000000"
  1976. );
  1977. sprintf(
  1978. buf,
  1979. "%08lx (valid pointer)",
  1980. pParamsHeader->aParams[lSel].u.dwDefValue
  1981. );
  1982. SendDlgItemMessage(
  1983. hwnd,
  1984. IDC_COMBO1,
  1985. CB_INSERTSTRING,
  1986. (WPARAM) -1,
  1987. (LPARAM) buf
  1988. );
  1989. SendDlgItemMessage(
  1990. hwnd,
  1991. IDC_COMBO1,
  1992. CB_INSERTSTRING,
  1993. (WPARAM) -1,
  1994. (LPARAM) "ffffffff"
  1995. );
  1996. sprintf(
  1997. buf,
  1998. "%08lx",
  1999. pParamsHeader->aParams[lSel].dwValue
  2000. );
  2001. break;
  2002. }
  2003. case PT_DWORD:
  2004. {
  2005. SendDlgItemMessage(
  2006. hwnd,
  2007. IDC_COMBO1,
  2008. CB_INSERTSTRING,
  2009. (WPARAM) -1,
  2010. (LPARAM) "0000000"
  2011. );
  2012. if (pParamsHeader->aParams[lSel].u.dwDefValue)
  2013. {
  2014. //
  2015. // Add the default val string to the combo
  2016. //
  2017. sprintf(
  2018. buf,
  2019. "%08lx",
  2020. pParamsHeader->aParams[lSel].u.dwDefValue
  2021. );
  2022. SendDlgItemMessage(
  2023. hwnd,
  2024. IDC_COMBO1,
  2025. CB_INSERTSTRING,
  2026. (WPARAM) -1,
  2027. (LPARAM) buf
  2028. );
  2029. }
  2030. SendDlgItemMessage(
  2031. hwnd,
  2032. IDC_COMBO1,
  2033. CB_INSERTSTRING,
  2034. (WPARAM) -1,
  2035. (LPARAM) "ffffffff"
  2036. );
  2037. sprintf(
  2038. buf,
  2039. "%08lx",
  2040. pParamsHeader->aParams[lSel].dwValue
  2041. );
  2042. break;
  2043. }
  2044. case PT_FLAGS:
  2045. {
  2046. //
  2047. // Stick the bit flag strings in the list box
  2048. //
  2049. PLOOKUP pLookup = (PLOOKUP)
  2050. pParamsHeader->aParams[lSel].u.pLookup;
  2051. for (i = 0; pLookup[i].dwVal != 0xffffffff; i++)
  2052. {
  2053. SendDlgItemMessage(
  2054. hwnd,
  2055. IDC_LIST2,
  2056. LB_INSERTSTRING,
  2057. (WPARAM) -1,
  2058. (LPARAM) pLookup[i].lpszVal
  2059. );
  2060. if (pParamsHeader->aParams[lSel].dwValue &
  2061. pLookup[i].dwVal)
  2062. {
  2063. SendDlgItemMessage(
  2064. hwnd,
  2065. IDC_LIST2,
  2066. LB_SETSEL,
  2067. (WPARAM) TRUE,
  2068. (LPARAM) MAKELPARAM((WORD)i,0)
  2069. );
  2070. }
  2071. }
  2072. SendDlgItemMessage(
  2073. hwnd,
  2074. IDC_COMBO1,
  2075. CB_INSERTSTRING,
  2076. (WPARAM) -1,
  2077. (LPARAM) "select none"
  2078. );
  2079. SendDlgItemMessage(
  2080. hwnd,
  2081. IDC_COMBO1,
  2082. CB_INSERTSTRING,
  2083. (WPARAM) -1,
  2084. (LPARAM) "select all"
  2085. );
  2086. sprintf(
  2087. buf,
  2088. "%08lx",
  2089. pParamsHeader->aParams[lSel].dwValue
  2090. );
  2091. break;
  2092. }
  2093. case PT_ORDINAL:
  2094. {
  2095. //
  2096. // Stick the bit flag strings in the list box
  2097. //
  2098. HWND hwndList2 = GetDlgItem (hwnd, IDC_LIST2);
  2099. PLOOKUP pLookup = (PLOOKUP)
  2100. pParamsHeader->aParams[lSel].u.pLookup;
  2101. for (i = 0; pLookup[i].dwVal != 0xffffffff; i++)
  2102. {
  2103. SendMessage(
  2104. hwndList2,
  2105. LB_INSERTSTRING,
  2106. (WPARAM) -1,
  2107. (LPARAM) pLookup[i].lpszVal
  2108. );
  2109. if (pParamsHeader->aParams[lSel].dwValue ==
  2110. pLookup[i].dwVal)
  2111. {
  2112. SendMessage(
  2113. hwndList2,
  2114. LB_SETSEL,
  2115. (WPARAM) TRUE,
  2116. (LPARAM) MAKELPARAM((WORD)i,0)
  2117. );
  2118. }
  2119. }
  2120. SendDlgItemMessage(
  2121. hwnd,
  2122. IDC_COMBO1,
  2123. CB_INSERTSTRING,
  2124. (WPARAM) -1,
  2125. (LPARAM) (char far *) "select none"
  2126. );
  2127. wsprintf(
  2128. buf,
  2129. "%08lx",
  2130. pParamsHeader->aParams[lSel].dwValue
  2131. );
  2132. break;
  2133. }
  2134. } //switch
  2135. SetDlgItemText (hwnd, IDC_COMBO1, lpstr);
  2136. pDlgInstData->lLastSel = lSel;
  2137. }
  2138. break;
  2139. case IDC_LIST2:
  2140. #ifdef WIN32
  2141. if (HIWORD(wParam) == LBN_SELCHANGE)
  2142. #else
  2143. if (HIWORD(lParam) == LBN_SELCHANGE)
  2144. #endif
  2145. {
  2146. PLOOKUP pLookup = (PLOOKUP)
  2147. pParamsHeader->aParams[lLastSel].u.pLookup;
  2148. char buf[16];
  2149. DWORD dwValue = 0;
  2150. int far *ai;
  2151. LONG i;
  2152. LRESULT lSelCount =
  2153. SendDlgItemMessage (hwnd, IDC_LIST2, LB_GETSELCOUNT, 0, 0);
  2154. if (lSelCount)
  2155. {
  2156. ai = (int far *) MyAlloc ((size_t)lSelCount * sizeof(int));
  2157. SendDlgItemMessage(
  2158. hwnd,
  2159. IDC_LIST2,
  2160. LB_GETSELITEMS,
  2161. (WPARAM) lSelCount,
  2162. (LPARAM) ai
  2163. );
  2164. if (pParamsHeader->aParams[lLastSel].dwType == PT_FLAGS)
  2165. {
  2166. for (i = 0; i < lSelCount; i++)
  2167. {
  2168. dwValue |= pLookup[ai[i]].dwVal;
  2169. }
  2170. }
  2171. else // if (.dwType == PT_ORDINAL)
  2172. {
  2173. if (lSelCount == 1)
  2174. {
  2175. dwValue = pLookup[ai[0]].dwVal;
  2176. }
  2177. else if (lSelCount == 2)
  2178. {
  2179. //
  2180. // Figure out which item we need to de-select,
  2181. // since we're doing ords & only want 1 item
  2182. // selected at a time
  2183. //
  2184. GetDlgItemText (hwnd, IDC_COMBO1, buf, 16);
  2185. if (sscanf (buf, "%lx", &dwValue))
  2186. {
  2187. if (pLookup[ai[0]].dwVal == dwValue)
  2188. {
  2189. SendDlgItemMessage(
  2190. hwnd,
  2191. IDC_LIST2,
  2192. LB_SETSEL,
  2193. 0,
  2194. (LPARAM) ai[0]
  2195. );
  2196. dwValue = pLookup[ai[1]].dwVal;
  2197. }
  2198. else
  2199. {
  2200. SendDlgItemMessage(
  2201. hwnd,
  2202. IDC_LIST2,
  2203. LB_SETSEL,
  2204. 0,
  2205. (LPARAM) ai[1]
  2206. );
  2207. dwValue = pLookup[ai[0]].dwVal;
  2208. }
  2209. }
  2210. else
  2211. {
  2212. // de-select items???
  2213. dwValue = 0;
  2214. }
  2215. }
  2216. }
  2217. MyFree (ai);
  2218. }
  2219. sprintf (buf, "%08lx", dwValue);
  2220. SetDlgItemText (hwnd, IDC_COMBO1, buf);
  2221. }
  2222. break;
  2223. case IDC_COMBO1:
  2224. #ifdef WIN32
  2225. switch (HIWORD(wParam))
  2226. #else
  2227. switch (HIWORD(lParam))
  2228. #endif
  2229. {
  2230. case CBN_SELCHANGE:
  2231. {
  2232. LRESULT lSel =
  2233. SendDlgItemMessage (hwnd, IDC_COMBO1, CB_GETCURSEL, 0, 0);
  2234. switch (pParamsHeader->aParams[lLastSel].dwType)
  2235. {
  2236. case PT_POINTER:
  2237. case PT_PTRNOEDIT:
  2238. {
  2239. if (lSel == 1)
  2240. {
  2241. //
  2242. // Strip off the "(valid pointer)" in the edit ctrl
  2243. //
  2244. wsprintf(
  2245. lpszComboText,
  2246. "%08lx",
  2247. pParamsHeader->aParams[lLastSel].u.ptr
  2248. );
  2249. PostMessage (hwnd, WM_USER+55, 0, 0);
  2250. }
  2251. break;
  2252. }
  2253. case PT_FLAGS:
  2254. {
  2255. BOOL bSelect = (lSel ? TRUE : FALSE);
  2256. SendDlgItemMessage(
  2257. hwnd,
  2258. IDC_LIST2,
  2259. LB_SETSEL,
  2260. (WPARAM) bSelect,
  2261. (LPARAM) -1
  2262. );
  2263. if (bSelect)
  2264. {
  2265. PLOOKUP pLookup = (PLOOKUP)
  2266. pParamsHeader->aParams[lLastSel].u.pLookup;
  2267. DWORD dwValue = 0;
  2268. int far *ai;
  2269. LONG i;
  2270. LRESULT lSelCount =
  2271. SendDlgItemMessage (hwnd, IDC_LIST2, LB_GETSELCOUNT, 0, 0);
  2272. if (lSelCount)
  2273. {
  2274. ai = (int far *) MyAlloc ((size_t)lSelCount * sizeof(int));
  2275. SendDlgItemMessage(
  2276. hwnd,
  2277. IDC_LIST2,
  2278. LB_GETSELITEMS,
  2279. (WPARAM) lSelCount,
  2280. (LPARAM) ai
  2281. );
  2282. for (i = 0; i < lSelCount; i++)
  2283. {
  2284. dwValue |= pLookup[ai[i]].dwVal;
  2285. }
  2286. MyFree (ai);
  2287. }
  2288. sprintf (lpszComboText, "%08lx", dwValue);
  2289. }
  2290. else
  2291. {
  2292. strcpy (lpszComboText, "00000000");
  2293. }
  2294. PostMessage (hwnd, WM_USER+55, 0, 0);
  2295. break;
  2296. }
  2297. case PT_STRING:
  2298. if (lSel == 1)
  2299. {
  2300. strncpy(
  2301. lpszComboText,
  2302. pParamsHeader->aParams[lLastSel].u.buf,
  2303. MAX_STRING_PARAM_SIZE
  2304. );
  2305. lpszComboText[MAX_STRING_PARAM_SIZE-1] = 0;
  2306. }
  2307. else
  2308. {
  2309. lpszComboText[0] = 0;
  2310. }
  2311. PostMessage (hwnd, WM_USER+55, 0, 0);
  2312. break;
  2313. case PT_DWORD:
  2314. break;
  2315. case PT_ORDINAL:
  2316. //
  2317. // The only option here is "select none"
  2318. //
  2319. strcpy (lpszComboText, "00000000");
  2320. PostMessage (hwnd, WM_USER+55, 0, 0);
  2321. break;
  2322. case PT_WSAPROTOCOLINFO:
  2323. {
  2324. if (lSel == 1)
  2325. {
  2326. LPWSAPROTOCOL_INFOA pInfo = (gbWideStringParams ?
  2327. (LPWSAPROTOCOL_INFOA)
  2328. &gWSAProtocolInfoW :
  2329. &gWSAProtocolInfoA);
  2330. char szProtocol[MAX_STRING_PARAM_SIZE];
  2331. FUNC_PARAM params[] =
  2332. {
  2333. { "dwServiceFlags1", PT_FLAGS, (ULONG_PTR) pInfo->dwServiceFlags1, aServiceFlags },
  2334. { "dwServiceFlags2", PT_DWORD, (ULONG_PTR) pInfo->dwServiceFlags2, NULL },
  2335. { "dwServiceFlags3", PT_DWORD, (ULONG_PTR) pInfo->dwServiceFlags3, NULL },
  2336. { "dwServiceFlags4", PT_DWORD, (ULONG_PTR) pInfo->dwServiceFlags4, NULL },
  2337. { "dwProviderFlags1", PT_FLAGS, (ULONG_PTR) pInfo->dwProviderFlags, aProviderFlags },
  2338. { "ProviderID.Data1", PT_DWORD, (ULONG_PTR) pInfo->ProviderId.Data1, NULL },
  2339. { "ProviderID.Data2", PT_DWORD, (ULONG_PTR) pInfo->ProviderId.Data2, NULL },
  2340. { "ProviderID.Data3", PT_DWORD, (ULONG_PTR) pInfo->ProviderId.Data3, NULL },
  2341. { "ProviderID.Data4[0-3]",PT_DWORD, *((LPDWORD) pInfo->ProviderId.Data4), NULL },
  2342. { "ProviderID.Data4[4-7]",PT_DWORD, *((LPDWORD) &pInfo->ProviderId.Data4[4]), NULL },
  2343. { "dwCatalogEntryId", PT_DWORD, (ULONG_PTR) pInfo->dwCatalogEntryId, NULL },
  2344. { "ProtoChain.Len", PT_DWORD, (ULONG_PTR) pInfo->ProtocolChain.ChainLen, NULL },
  2345. { "ProtoChain.Entry0", PT_DWORD, (ULONG_PTR) pInfo->ProtocolChain.ChainEntries[0], NULL },
  2346. { "ProtoChain.Entry1", PT_DWORD, (ULONG_PTR) pInfo->ProtocolChain.ChainEntries[1], NULL },
  2347. { "ProtoChain.Entry2", PT_DWORD, (ULONG_PTR) pInfo->ProtocolChain.ChainEntries[2], NULL },
  2348. { "ProtoChain.Entry3", PT_DWORD, (ULONG_PTR) pInfo->ProtocolChain.ChainEntries[3], NULL },
  2349. { "ProtoChain.Entry4", PT_DWORD, (ULONG_PTR) pInfo->ProtocolChain.ChainEntries[4], NULL },
  2350. { "ProtoChain.Entry5", PT_DWORD, (ULONG_PTR) pInfo->ProtocolChain.ChainEntries[5], NULL },
  2351. { "ProtoChain.Entry6", PT_DWORD, (ULONG_PTR) pInfo->ProtocolChain.ChainEntries[6], NULL },
  2352. { "iVersion", PT_DWORD, (ULONG_PTR) pInfo->iVersion, NULL },
  2353. { "iAddressFamily", PT_ORDINAL, (ULONG_PTR) pInfo->iAddressFamily, aAddressFamilies },
  2354. { "iMaxSockAddr", PT_DWORD, (ULONG_PTR) pInfo->iMaxSockAddr, NULL },
  2355. { "iMinSockAddr", PT_DWORD, (ULONG_PTR) pInfo->iMinSockAddr, NULL },
  2356. { "iSocketType", PT_FLAGS, (ULONG_PTR) pInfo->iSocketType, aSocketTypes },
  2357. { "iProtocol", PT_DWORD, (ULONG_PTR) pInfo->iProtocol, NULL }, // ought be flags?
  2358. { "iProtocolMaxOffset", PT_DWORD, (ULONG_PTR) pInfo->iProtocolMaxOffset, NULL },
  2359. { "iNetworkByteOrder", PT_ORDINAL, (ULONG_PTR) pInfo->iNetworkByteOrder, aNetworkByteOrders },
  2360. { "iSecurityScheme", PT_DWORD, (ULONG_PTR) pInfo->iSecurityScheme, NULL },
  2361. { "dwMessageSize", PT_DWORD, (ULONG_PTR) pInfo->dwMessageSize, NULL },
  2362. { "dwProviderReserved", PT_DWORD, (ULONG_PTR) pInfo->dwProviderReserved, NULL },
  2363. { "szProtocol", PT_STRING, (ULONG_PTR) szProtocol, szProtocol }
  2364. };
  2365. FUNC_PARAM_HEADER paramsHeader =
  2366. { 31, WSAProtoInfo, params, NULL };
  2367. //
  2368. // Set "ghwndModal" so this Params dlg will
  2369. // be modal to the existing Params dlg
  2370. //
  2371. ghwndModal = hwnd;
  2372. if (gbWideStringParams)
  2373. {
  2374. //
  2375. // Convert from unicode to ascii show text not
  2376. // clipped after 1st char (it's an ascii window)
  2377. //
  2378. WideCharToMultiByte(
  2379. GetACP(),
  2380. 0,
  2381. (LPWSTR) pInfo->szProtocol,
  2382. lstrlenW ((LPWSTR) pInfo->szProtocol) + 1,
  2383. szProtocol,
  2384. MAX_STRING_PARAM_SIZE,
  2385. NULL,
  2386. NULL
  2387. );
  2388. }
  2389. else
  2390. {
  2391. lstrcpyA (szProtocol, pInfo->szProtocol);
  2392. }
  2393. if (LetUserMungeParams (&paramsHeader))
  2394. {
  2395. //
  2396. // Save the new params
  2397. //
  2398. pInfo->dwServiceFlags1 = (DWORD)
  2399. params[0].dwValue;
  2400. pInfo->dwServiceFlags2 = (DWORD)
  2401. params[1].dwValue;
  2402. pInfo->dwServiceFlags3 = (DWORD)
  2403. params[2].dwValue;
  2404. pInfo->dwServiceFlags4 = (DWORD)
  2405. params[3].dwValue;
  2406. pInfo->dwProviderFlags = (DWORD)
  2407. params[4].dwValue;
  2408. pInfo->ProviderId.Data1 = (DWORD)
  2409. params[5].dwValue;
  2410. pInfo->ProviderId.Data2 = (unsigned short)
  2411. LOWORD(params[6].dwValue);
  2412. pInfo->ProviderId.Data3 = (unsigned short)
  2413. LOWORD(params[7].dwValue);
  2414. *((LPDWORD) pInfo->ProviderId.Data4) = (DWORD)
  2415. params[8].dwValue;
  2416. *((LPDWORD) &pInfo->ProviderId.Data4[4]) = (DWORD)
  2417. params[9].dwValue;
  2418. pInfo->dwCatalogEntryId = (DWORD)
  2419. params[10].dwValue;
  2420. pInfo->ProtocolChain.ChainLen = (DWORD)
  2421. params[11].dwValue;
  2422. pInfo->ProtocolChain.ChainEntries[0] = (DWORD)
  2423. params[12].dwValue;
  2424. pInfo->ProtocolChain.ChainEntries[1] = (DWORD)
  2425. params[13].dwValue;
  2426. pInfo->ProtocolChain.ChainEntries[2] = (DWORD)
  2427. params[14].dwValue;
  2428. pInfo->ProtocolChain.ChainEntries[3] = (DWORD)
  2429. params[15].dwValue;
  2430. pInfo->ProtocolChain.ChainEntries[4] = (DWORD)
  2431. params[16].dwValue;
  2432. pInfo->ProtocolChain.ChainEntries[5] = (DWORD)
  2433. params[17].dwValue;
  2434. pInfo->ProtocolChain.ChainEntries[6] = (DWORD)
  2435. params[18].dwValue;
  2436. pInfo->iVersion = (int)
  2437. params[19].dwValue;
  2438. pInfo->iAddressFamily = (int)
  2439. params[20].dwValue;
  2440. pInfo->iMaxSockAddr = (int)
  2441. params[21].dwValue;
  2442. pInfo->iMinSockAddr = (int)
  2443. params[22].dwValue;
  2444. pInfo->iSocketType = (int)
  2445. params[23].dwValue;
  2446. pInfo->iProtocol = (int)
  2447. params[24].dwValue;
  2448. pInfo->iProtocolMaxOffset = (int)
  2449. params[25].dwValue;
  2450. pInfo->iNetworkByteOrder = (int)
  2451. params[26].dwValue;
  2452. pInfo->iSecurityScheme = (int)
  2453. params[27].dwValue;
  2454. pInfo->dwMessageSize = (DWORD)
  2455. params[28].dwValue;
  2456. pInfo->dwProviderReserved = (DWORD)
  2457. params[29].dwValue;
  2458. if (params[30].dwValue == (ULONG_PTR) szProtocol)
  2459. {
  2460. if (gbWideStringParams)
  2461. {
  2462. lstrcpyW(
  2463. (WCHAR *) pInfo->szProtocol,
  2464. (WCHAR *) szProtocol
  2465. );
  2466. }
  2467. else
  2468. {
  2469. lstrcpyA (pInfo->szProtocol, szProtocol);
  2470. }
  2471. }
  2472. }
  2473. //
  2474. // Now reset ghwndModal to what it was initially
  2475. //
  2476. ghwndModal = ghwndMain;
  2477. //
  2478. // Strip off the "(valid pointer)" in the edit ctrl
  2479. //
  2480. wsprintf (lpszComboText, "%08lx", pInfo);
  2481. PostMessage (hwnd, WM_USER+55, 0, 0);
  2482. pParamsHeader->aParams[lLastSel].dwValue = (ULONG_PTR) pInfo;
  2483. }
  2484. break;
  2485. }
  2486. case PT_QOS:
  2487. {
  2488. if (lSel == 1)
  2489. {
  2490. LPQOS pQOS = (LPQOS)
  2491. pParamsHeader->aParams[lLastSel].u.ptr;
  2492. FUNC_PARAM params[] =
  2493. {
  2494. { "Send.TokenRate", PT_DWORD, (ULONG_PTR) pQOS->SendingFlowspec.TokenRate, NULL },
  2495. { "Send.TokenBucketSize", PT_DWORD, (ULONG_PTR) pQOS->SendingFlowspec.TokenBucketSize, NULL },
  2496. { "Send.PeakBandwidth", PT_DWORD, (ULONG_PTR) pQOS->SendingFlowspec.PeakBandwidth, NULL },
  2497. { "Send.Latency", PT_DWORD, (ULONG_PTR) pQOS->SendingFlowspec.Latency, NULL },
  2498. { "Send.DelayVariation", PT_DWORD, (ULONG_PTR) pQOS->SendingFlowspec.DelayVariation, NULL },
  2499. { "Send.ServiceType", PT_ORDINAL, (ULONG_PTR) pQOS->SendingFlowspec.ServiceType, aQOSServiceTypes },
  2500. { "Send.MaxSduSize", PT_DWORD, (ULONG_PTR) pQOS->SendingFlowspec.MaxSduSize, NULL },
  2501. { "Send.MinimumPolicedSize", PT_DWORD, (ULONG_PTR) pQOS->SendingFlowspec.MinimumPolicedSize, NULL },
  2502. { "Recv.TokenRate", PT_DWORD, (ULONG_PTR) pQOS->ReceivingFlowspec.TokenRate, NULL },
  2503. { "Recv.TokenBucketSize", PT_DWORD, (ULONG_PTR) pQOS->ReceivingFlowspec.TokenBucketSize, NULL },
  2504. { "Recv.PeakBandwidth", PT_DWORD, (ULONG_PTR) pQOS->ReceivingFlowspec.PeakBandwidth, NULL },
  2505. { "Recv.Latency", PT_DWORD, (ULONG_PTR) pQOS->ReceivingFlowspec.Latency, NULL },
  2506. { "Recv.DelayVariation", PT_DWORD, (ULONG_PTR) pQOS->ReceivingFlowspec.DelayVariation, NULL },
  2507. { "Recv.ServiceType", PT_ORDINAL, (ULONG_PTR) pQOS->ReceivingFlowspec.ServiceType, aQOSServiceTypes },
  2508. { "Recv.MaxSduSize", PT_DWORD, (ULONG_PTR) pQOS->ReceivingFlowspec.MaxSduSize, NULL },
  2509. { "Recv.MinimumPolicedSize", PT_DWORD, (ULONG_PTR) pQOS->ReceivingFlowspec.MinimumPolicedSize, NULL },
  2510. { "ProviderSpecific.len", PT_DWORD, (ULONG_PTR) pQOS->ProviderSpecific.len, NULL },
  2511. { "ProviderSpecific.buf", PT_POINTER, (ULONG_PTR) pQOS->ProviderSpecific.buf, pQOS+1 }
  2512. };
  2513. FUNC_PARAM_HEADER paramsHeader =
  2514. { 18, ws_QOS, params, NULL };
  2515. //
  2516. // Set "ghwndModal" so this Params dlg will
  2517. // be modal to the existing Params dlg
  2518. //
  2519. ghwndModal = hwnd;
  2520. if (LetUserMungeParams (&paramsHeader))
  2521. {
  2522. //
  2523. // Save the params
  2524. //
  2525. for (i = 0; i < 17; i++)
  2526. {
  2527. *(((LPDWORD) pQOS) + i) = (DWORD)
  2528. params[i].dwValue;
  2529. }
  2530. }
  2531. //
  2532. // Now reset ghwndModal to what it was initially
  2533. //
  2534. ghwndModal = ghwndMain;
  2535. //
  2536. // Strip off the "(valid pointer)" in the edit ctrl
  2537. //
  2538. wsprintf (lpszComboText, "%08lx", pQOS);
  2539. PostMessage (hwnd, WM_USER+55, 0, 0);
  2540. pParamsHeader->aParams[lLastSel].dwValue =
  2541. (ULONG_PTR) pQOS;
  2542. }
  2543. break;
  2544. }
  2545. } // switch
  2546. break;
  2547. }
  2548. case CBN_EDITCHANGE:
  2549. {
  2550. //
  2551. // If user entered text in the edit field then copy the
  2552. // text to our buffer
  2553. //
  2554. if (pParamsHeader->aParams[lLastSel].dwType == PT_STRING)
  2555. {
  2556. char buf[MAX_STRING_PARAM_SIZE];
  2557. GetDlgItemText(
  2558. hwnd,
  2559. IDC_COMBO1,
  2560. buf,
  2561. MAX_STRING_PARAM_SIZE
  2562. );
  2563. strncpy(
  2564. pParamsHeader->aParams[lLastSel].u.buf,
  2565. buf,
  2566. MAX_STRING_PARAM_SIZE
  2567. );
  2568. pParamsHeader->aParams[lLastSel].u.buf
  2569. [MAX_STRING_PARAM_SIZE-1] = 0;
  2570. }
  2571. break;
  2572. }
  2573. } // switch
  2574. } // switch
  2575. break;
  2576. }
  2577. case WM_USER+55:
  2578. SetDlgItemText (hwnd, IDC_COMBO1, pDlgInstData->szComboText);
  2579. break;
  2580. #ifdef WIN32
  2581. case WM_CTLCOLORSTATIC:
  2582. SetBkColor ((HDC) wParam, RGB (192,192,192));
  2583. return (INT_PTR) GetStockObject (LTGRAY_BRUSH);
  2584. #else
  2585. case WM_CTLCOLOR:
  2586. {
  2587. if (HIWORD(lParam) == CTLCOLOR_STATIC)
  2588. {
  2589. SetBkColor ((HDC) wParam, RGB (192,192,192));
  2590. return (INT_PTR) GetStockObject (LTGRAY_BRUSH);
  2591. }
  2592. break;
  2593. }
  2594. #endif
  2595. case WM_PAINT:
  2596. {
  2597. PAINTSTRUCT ps;
  2598. BeginPaint (hwnd, &ps);
  2599. FillRect (ps.hdc, &ps.rcPaint, GetStockObject (LTGRAY_BRUSH));
  2600. EndPaint (hwnd, &ps);
  2601. break;
  2602. }
  2603. } // switch
  2604. return FALSE;
  2605. }
  2606. INT_PTR
  2607. CALLBACK
  2608. UserButtonsDlgProc(
  2609. HWND hwnd,
  2610. UINT msg,
  2611. WPARAM wParam,
  2612. LPARAM lParam
  2613. )
  2614. {
  2615. static int iButtonIndex;
  2616. switch (msg)
  2617. {
  2618. case WM_INITDIALOG:
  2619. {
  2620. int i;
  2621. char buf[32];
  2622. if (lParam)
  2623. {
  2624. //
  2625. // The dlg was invoked because someone pressed a user button
  2626. // that was uninitialized, so only allow chgs on this button
  2627. //
  2628. iButtonIndex = *((int *) lParam);
  2629. _itoa (iButtonIndex + 1, buf, 10);
  2630. SendDlgItemMessage(
  2631. hwnd,
  2632. IDC_LIST1,
  2633. LB_INSERTSTRING,
  2634. (WPARAM) -1,
  2635. (LPARAM) buf
  2636. );
  2637. }
  2638. else
  2639. {
  2640. //
  2641. // The dlg was invoked because the user chose a menuitem,
  2642. // so allow chgs on all buttons
  2643. //
  2644. iButtonIndex = MAX_USER_BUTTONS;
  2645. for (i = 1; i <= MAX_USER_BUTTONS; i++)
  2646. {
  2647. _itoa (i, buf, 10);
  2648. SendDlgItemMessage(
  2649. hwnd,
  2650. IDC_LIST1,
  2651. LB_INSERTSTRING,
  2652. (WPARAM) -1,
  2653. (LPARAM) buf
  2654. );
  2655. }
  2656. }
  2657. SendDlgItemMessage(
  2658. hwnd,
  2659. IDC_LIST1,
  2660. LB_SETCURSEL,
  2661. (WPARAM) 0,
  2662. 0
  2663. );
  2664. for (i = 0; aFuncNames[i]; i++)
  2665. {
  2666. SendDlgItemMessage(
  2667. hwnd,
  2668. IDC_LIST2,
  2669. LB_INSERTSTRING,
  2670. (WPARAM) -1,
  2671. (LPARAM) aFuncNames[i]
  2672. );
  2673. }
  2674. SendDlgItemMessage(
  2675. hwnd,
  2676. IDC_LIST2,
  2677. LB_INSERTSTRING,
  2678. (WPARAM) -1,
  2679. (LPARAM) "<none>"
  2680. );
  2681. if (!lParam)
  2682. {
  2683. #ifdef WIN32
  2684. wParam = (WPARAM) MAKELONG (0, LBN_SELCHANGE);
  2685. #else
  2686. lParam = (LPARAM) MAKELONG (0, LBN_SELCHANGE);
  2687. #endif
  2688. goto IDC_LIST1_selchange;
  2689. }
  2690. break;
  2691. }
  2692. case WM_COMMAND:
  2693. switch (LOWORD(wParam))
  2694. {
  2695. case IDOK:
  2696. {
  2697. LRESULT lFuncSel;
  2698. lFuncSel = SendDlgItemMessage(hwnd, IDC_LIST2, LB_GETCURSEL, 0, 0);
  2699. if (lFuncSel == LB_ERR)
  2700. {
  2701. MessageBox (hwnd, "Select a function", "", MB_OK);
  2702. break;
  2703. }
  2704. if (iButtonIndex == MAX_USER_BUTTONS)
  2705. {
  2706. iButtonIndex = (int) SendDlgItemMessage(
  2707. hwnd,
  2708. IDC_LIST1,
  2709. LB_GETCURSEL,
  2710. 0,
  2711. 0
  2712. );
  2713. }
  2714. aUserButtonFuncs[iButtonIndex] = (DWORD) lFuncSel;
  2715. if (lFuncSel == MiscBegin)
  2716. {
  2717. //
  2718. // User selected "<none>" option so nullify string
  2719. //
  2720. aUserButtonsText[iButtonIndex][0] = 0;
  2721. }
  2722. else
  2723. {
  2724. GetDlgItemText(
  2725. hwnd,
  2726. IDC_EDIT1,
  2727. (LPSTR) &aUserButtonsText[iButtonIndex],
  2728. MAX_USER_BUTTON_TEXT_SIZE - 1
  2729. );
  2730. aUserButtonsText[iButtonIndex][MAX_USER_BUTTON_TEXT_SIZE - 1] =
  2731. 0;
  2732. }
  2733. SetDlgItemText(
  2734. ghwndMain,
  2735. IDC_BUTTON7 + iButtonIndex,
  2736. (LPSTR) &aUserButtonsText[iButtonIndex]
  2737. );
  2738. // Fall thru to IDCANCEL code
  2739. }
  2740. case IDCANCEL:
  2741. EndDialog (hwnd, FALSE);
  2742. break;
  2743. case IDC_LIST1:
  2744. IDC_LIST1_selchange:
  2745. #ifdef WIN32
  2746. if (HIWORD(wParam) == LBN_SELCHANGE)
  2747. #else
  2748. if (HIWORD(lParam) == LBN_SELCHANGE)
  2749. #endif
  2750. {
  2751. LRESULT lButtonSel =
  2752. SendDlgItemMessage(hwnd, IDC_LIST1, LB_GETCURSEL, 0, 0);
  2753. SendDlgItemMessage(
  2754. hwnd,
  2755. IDC_LIST2,
  2756. LB_SETCURSEL,
  2757. (WPARAM) aUserButtonFuncs[lButtonSel],
  2758. 0
  2759. );
  2760. SetDlgItemText(
  2761. hwnd,
  2762. IDC_EDIT1,
  2763. aUserButtonsText[lButtonSel]
  2764. );
  2765. }
  2766. break;
  2767. } // switch
  2768. break;
  2769. #ifdef WIN32
  2770. case WM_CTLCOLORSTATIC:
  2771. SetBkColor ((HDC) wParam, RGB (192,192,192));
  2772. return (INT_PTR) GetStockObject (LTGRAY_BRUSH);
  2773. #else
  2774. case WM_CTLCOLOR:
  2775. {
  2776. if (HIWORD(lParam) == CTLCOLOR_STATIC)
  2777. {
  2778. SetBkColor ((HDC) wParam, RGB (192,192,192));
  2779. return (INT_PTR) GetStockObject (LTGRAY_BRUSH);
  2780. }
  2781. break;
  2782. }
  2783. #endif
  2784. case WM_PAINT:
  2785. {
  2786. PAINTSTRUCT ps;
  2787. BeginPaint (hwnd, &ps);
  2788. FillRect (ps.hdc, &ps.rcPaint, GetStockObject (LTGRAY_BRUSH));
  2789. EndPaint (hwnd, &ps);
  2790. break;
  2791. }
  2792. } // switch
  2793. return FALSE;
  2794. }
  2795. int
  2796. CALLBACK
  2797. ConditionProc(
  2798. LPWSABUF lpCallerId,
  2799. LPWSABUF lpCallerData,
  2800. LPQOS lpSQOS,
  2801. LPQOS lpGQOS,
  2802. LPWSABUF lpCalleeId,
  2803. LPWSABUF lpCalleeData,
  2804. GROUP FAR *g,
  2805. DWORD dwCallbackData
  2806. )
  2807. {
  2808. ShowStr ("ConditionProc: enter");
  2809. return 0;
  2810. }
  2811. void
  2812. CALLBACK
  2813. CompletionProc(
  2814. DWORD dwError,
  2815. DWORD cbTransferred,
  2816. LPWSAOVERLAPPED pOverlapped,
  2817. DWORD dwFlags
  2818. )
  2819. {
  2820. ShowStr ("CompletionProc: enter");
  2821. ShowStr (" dwError=%ld", dwError);
  2822. ShowStr (" cbTransferred=%ld", cbTransferred);
  2823. ShowStr (" pOverlapped=x%x", pOverlapped);
  2824. ShowStr (" dwFlags=%d (x%x)", dwFlags, dwFlags);
  2825. MyFree (pOverlapped);
  2826. }
  2827. DWORD
  2828. PASCAL
  2829. ShowError(
  2830. FUNC_INDEX funcIndex,
  2831. int iResult
  2832. )
  2833. {
  2834. DWORD i, dwError = (iResult == 0 ? (DWORD) WSAGetLastError() : iResult);
  2835. for(
  2836. i = 0;
  2837. (dwError != aWSAErrors[i].dwVal && aWSAErrors[i].lpszVal);
  2838. i++
  2839. );
  2840. ShowStr(
  2841. "%s error: %s (%d)",
  2842. aFuncNames[funcIndex],
  2843. (aWSAErrors[i].lpszVal ? aWSAErrors[i].lpszVal : gszUnknownError),
  2844. dwError
  2845. );
  2846. return dwError;
  2847. }
  2848. void
  2849. PASCAL
  2850. ShowUnknownError(
  2851. FUNC_INDEX funcIndex,
  2852. int iResult
  2853. )
  2854. {
  2855. ShowStr(
  2856. "%s returned unrecognized error (%d)",
  2857. aFuncNames[funcIndex],
  2858. iResult
  2859. );
  2860. }
  2861. void
  2862. FAR
  2863. PASCAL
  2864. FuncDriver(
  2865. FUNC_INDEX funcIndex
  2866. )
  2867. {
  2868. int i, j, k;
  2869. //
  2870. // Determine if we're doing a ascii or a unicode op
  2871. //
  2872. gbWideStringParams =
  2873. ((aFuncNames[funcIndex])[strlen (aFuncNames[funcIndex]) - 1] == 'W' ?
  2874. TRUE : FALSE);
  2875. //
  2876. // Zero the global buf so the user doesn't see extraneous stuff
  2877. //
  2878. ZeroMemory (pBigBuf, dwBigBufSize);
  2879. //
  2880. // The big switch statement...
  2881. //
  2882. switch (funcIndex)
  2883. {
  2884. case ws_accept:
  2885. {
  2886. int iLength;
  2887. struct sockaddr sa;
  2888. FUNC_PARAM params[] =
  2889. {
  2890. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  2891. { "lpAddress", PT_PTRNOEDIT, (ULONG_PTR) &sa, &sa },
  2892. { "lpiAddrLength", PT_PTRNOEDIT, (ULONG_PTR) &iLength, &iLength },
  2893. };
  2894. FUNC_PARAM_HEADER paramsHeader =
  2895. { 3, funcIndex, params, NULL };
  2896. if (LetUserMungeParams (&paramsHeader))
  2897. {
  2898. SOCKET s;
  2899. if ((s = accept(
  2900. (SOCKET) params[0].dwValue,
  2901. (struct sockaddr FAR *) params[1].dwValue,
  2902. (int FAR *) params[2].dwValue
  2903. )) != INVALID_SOCKET)
  2904. {
  2905. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  2906. ShowStr (" returned socket=x%x", s);
  2907. if (params[1].dwValue)
  2908. {
  2909. ShowStr (" lpAddress=x%x", params[1].dwValue);
  2910. ShowStr(
  2911. " ->sa_family=%d, %s",
  2912. sa.sa_family,
  2913. GetStringFromOrdinalValue(
  2914. (DWORD) sa.sa_family,
  2915. aAddressFamilies
  2916. )
  2917. );
  2918. ShowStr (" ->sa_data=");
  2919. ShowBytes (14, sa.sa_data, 1);
  2920. }
  2921. }
  2922. else
  2923. {
  2924. ShowError (funcIndex, 0);
  2925. }
  2926. }
  2927. break;
  2928. }
  2929. case ws_bind:
  2930. {
  2931. FUNC_PARAM params[] =
  2932. {
  2933. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  2934. { "lpName", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  2935. { " ->sa_family", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  2936. { " ->sa_data", PT_POINTER, (ULONG_PTR) (pBigBuf + 2), pBigBuf + 2 },
  2937. { "namelen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  2938. };
  2939. FUNC_PARAM_HEADER paramsHeader =
  2940. { 5, funcIndex, params, NULL };
  2941. if (LetUserMungeParams (&paramsHeader))
  2942. {
  2943. *((u_short *) pBigBuf) = LOWORD(params[2].dwValue);
  2944. if ((i = bind(
  2945. (SOCKET) params[0].dwValue,
  2946. (struct sockaddr FAR *) params[1].dwValue,
  2947. (int) params[4].dwValue
  2948. )) == 0)
  2949. {
  2950. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  2951. }
  2952. else if (i == SOCKET_ERROR)
  2953. {
  2954. ShowError (funcIndex, 0);
  2955. }
  2956. else
  2957. {
  2958. ShowUnknownError (funcIndex, i);
  2959. }
  2960. }
  2961. break;
  2962. }
  2963. case ws_closesocket:
  2964. {
  2965. FUNC_PARAM params[] =
  2966. {
  2967. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  2968. };
  2969. FUNC_PARAM_HEADER paramsHeader =
  2970. { 1, funcIndex, params, NULL };
  2971. if (LetUserMungeParams (&paramsHeader))
  2972. {
  2973. if ((i = closesocket ((SOCKET) params[0].dwValue)) == 0)
  2974. {
  2975. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  2976. if ((SOCKET) params[0].dwValue != gpSelectedSocket->Sock)
  2977. {
  2978. //
  2979. // The user overrode the selected widget, so make sure
  2980. // we don't delete the wrong string from the list box
  2981. //
  2982. int iNumItems;
  2983. PMYSOCKET ps;
  2984. iNumItems = (int) SendMessage(
  2985. ghwndList1,
  2986. LB_GETCOUNT,
  2987. 0,
  2988. 0
  2989. );
  2990. for (i = 0; i < iNumItems; i++)
  2991. {
  2992. ps = (PMYSOCKET) SendMessage(
  2993. ghwndList1,
  2994. LB_GETITEMDATA,
  2995. i,
  2996. 0
  2997. );
  2998. if ((SOCKET) params[0].dwValue == ps->Sock)
  2999. {
  3000. glCurrentSelection = (LONG) i;
  3001. gpSelectedSocket = ps;
  3002. break;
  3003. }
  3004. }
  3005. if (i == iNumItems)
  3006. {
  3007. ShowStr(
  3008. "Strange, couldn't find socket=x%x in list",
  3009. params[0].dwValue
  3010. );
  3011. break;
  3012. }
  3013. }
  3014. SendMessage(
  3015. ghwndList1,
  3016. LB_DELETESTRING,
  3017. glCurrentSelection,
  3018. 0
  3019. );
  3020. MyFree (gpSelectedSocket);
  3021. }
  3022. else if (i == SOCKET_ERROR)
  3023. {
  3024. ShowError (funcIndex, 0);
  3025. }
  3026. else
  3027. {
  3028. ShowUnknownError (funcIndex, i);
  3029. }
  3030. }
  3031. break;
  3032. }
  3033. case ws_connect:
  3034. {
  3035. FUNC_PARAM params[] =
  3036. {
  3037. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3038. { "lpName", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  3039. { " ->sa_family", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  3040. { " ->sa_data", PT_POINTER, (ULONG_PTR) (pBigBuf + 2), pBigBuf + 2 },
  3041. { "namelen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  3042. };
  3043. FUNC_PARAM_HEADER paramsHeader =
  3044. { 5, funcIndex, params, NULL };
  3045. if (LetUserMungeParams (&paramsHeader))
  3046. {
  3047. *((u_short *) pBigBuf) = LOWORD(params[2].dwValue);
  3048. if ((i = connect(
  3049. (SOCKET) params[0].dwValue,
  3050. (struct sockaddr FAR *) params[1].dwValue,
  3051. (int) params[4].dwValue
  3052. )) == 0)
  3053. {
  3054. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3055. }
  3056. else if (i == SOCKET_ERROR)
  3057. {
  3058. ShowError (funcIndex, 0);
  3059. }
  3060. else
  3061. {
  3062. ShowUnknownError (funcIndex, i);
  3063. }
  3064. }
  3065. break;
  3066. }
  3067. case ws_gethostbyaddr:
  3068. {
  3069. char szAddress[MAX_STRING_PARAM_SIZE];
  3070. FUNC_PARAM params[] =
  3071. {
  3072. { "addr", PT_POINTER, (ULONG_PTR) pBigBuf, pBigBuf },
  3073. { "len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  3074. { "type", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  3075. };
  3076. FUNC_PARAM_HEADER paramsHeader =
  3077. { 3, funcIndex, params, NULL };
  3078. lstrcpy (szAddress, "xxx");
  3079. if (LetUserMungeParams (&paramsHeader))
  3080. {
  3081. struct hostent *phe;
  3082. // note: WinSock owns the returned ptr, don't free/munge it
  3083. if ((phe = gethostbyaddr(
  3084. (char FAR *) params[0].dwValue,
  3085. (int) params[1].dwValue,
  3086. (int) params[2].dwValue
  3087. )))
  3088. {
  3089. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3090. ShowHostEnt (phe);
  3091. }
  3092. else
  3093. {
  3094. ShowError (funcIndex, 0);
  3095. }
  3096. }
  3097. break;
  3098. }
  3099. case ws_gethostbyname:
  3100. {
  3101. char szHostName[MAX_STRING_PARAM_SIZE];
  3102. FUNC_PARAM params[] =
  3103. {
  3104. { "name", PT_STRING, (ULONG_PTR) szHostName, szHostName }
  3105. };
  3106. FUNC_PARAM_HEADER paramsHeader =
  3107. { 1, funcIndex, params, NULL };
  3108. lstrcpyA (szHostName, gszDefHostName);
  3109. if (LetUserMungeParams (&paramsHeader))
  3110. {
  3111. struct hostent *phe;
  3112. // note: WinSock owns the returned ptr, don't free/munge it
  3113. if ((phe = gethostbyname ((char FAR *) params[0].dwValue)))
  3114. {
  3115. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3116. ShowHostEnt (phe);
  3117. }
  3118. else
  3119. {
  3120. ShowError (funcIndex, 0);
  3121. }
  3122. }
  3123. break;
  3124. }
  3125. case ws_gethostname:
  3126. {
  3127. char szName[MAX_STRING_PARAM_SIZE];
  3128. FUNC_PARAM params[] =
  3129. {
  3130. { "name", PT_POINTER, (ULONG_PTR) szName, szName },
  3131. { "namelen",PT_DWORD, (ULONG_PTR) MAX_STRING_PARAM_SIZE, NULL }
  3132. };
  3133. FUNC_PARAM_HEADER paramsHeader =
  3134. { 2, funcIndex, params, NULL };
  3135. if (LetUserMungeParams (&paramsHeader))
  3136. {
  3137. if ((i = gethostname(
  3138. (char FAR *) params[0].dwValue,
  3139. (int) params[1].dwValue
  3140. )) == 0)
  3141. {
  3142. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3143. ShowStr (" name=%s", (char FAR *) params[0].dwValue);
  3144. }
  3145. else if (i == SOCKET_ERROR)
  3146. {
  3147. ShowError (funcIndex, 0);
  3148. }
  3149. else
  3150. {
  3151. ShowUnknownError (funcIndex, i);
  3152. }
  3153. }
  3154. break;
  3155. }
  3156. case ws_getpeername:
  3157. case ws_getsockname:
  3158. {
  3159. int iNameLen = dwBigBufSize;
  3160. FUNC_PARAM params[] =
  3161. {
  3162. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3163. { "lpName", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  3164. { "lpiNameLength", PT_PTRNOEDIT, (ULONG_PTR) &iNameLen, &iNameLen },
  3165. };
  3166. FUNC_PARAM_HEADER paramsHeader =
  3167. { 3, funcIndex, params, NULL };
  3168. if (LetUserMungeParams (&paramsHeader))
  3169. {
  3170. if (funcIndex == ws_getpeername)
  3171. {
  3172. i = getpeername(
  3173. (SOCKET) params[0].dwValue,
  3174. (struct sockaddr FAR *) params[1].dwValue,
  3175. (int *) params[2].dwValue
  3176. );
  3177. }
  3178. else
  3179. {
  3180. i = getsockname(
  3181. (SOCKET) params[0].dwValue,
  3182. (struct sockaddr FAR *) params[1].dwValue,
  3183. (int *) params[2].dwValue
  3184. );
  3185. }
  3186. if (i == 0)
  3187. {
  3188. DWORD dwAddressFamily = (DWORD)
  3189. *((u_short *) params[1].dwValue);
  3190. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3191. ShowStr (" *lpNameLength=x%x", *((int *) params[2].dwValue));
  3192. ShowStr (" lpName=x%x", params[1].dwValue);
  3193. ShowStr(
  3194. " ->AddressFamiliy=%d, %s",
  3195. dwAddressFamily,
  3196. GetStringFromOrdinalValue(
  3197. dwAddressFamily,
  3198. aAddressFamilies
  3199. )
  3200. );
  3201. ShowStr (" ->Data=");
  3202. ShowBytes(
  3203. *((int *) params[2].dwValue) - sizeof (u_short),
  3204. (LPBYTE) params[1].dwValue + 2,
  3205. 1
  3206. );
  3207. }
  3208. else if (i == SOCKET_ERROR)
  3209. {
  3210. ShowError (funcIndex, 0);
  3211. }
  3212. else
  3213. {
  3214. ShowUnknownError (funcIndex, i);
  3215. }
  3216. }
  3217. break;
  3218. }
  3219. case ws_getprotobyname:
  3220. {
  3221. char szProtoName[MAX_STRING_PARAM_SIZE];
  3222. FUNC_PARAM params[] =
  3223. {
  3224. { "name", PT_STRING, (ULONG_PTR) szProtoName, szProtoName },
  3225. };
  3226. FUNC_PARAM_HEADER paramsHeader =
  3227. { 1, funcIndex, params, NULL };
  3228. lstrcpyA (szProtoName, gszDefProtoName);
  3229. if (LetUserMungeParams (&paramsHeader))
  3230. {
  3231. struct protoent *ppe;
  3232. // note: WinSock owns the returned ptr, don't free/munge it
  3233. if ((ppe = getprotobyname ((char FAR *) params[0].dwValue)))
  3234. {
  3235. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3236. ShowProtoEnt (ppe);
  3237. }
  3238. else
  3239. {
  3240. ShowError (funcIndex, 0);
  3241. }
  3242. }
  3243. break;
  3244. }
  3245. case ws_getprotobynumber:
  3246. {
  3247. FUNC_PARAM params[] =
  3248. {
  3249. { "number", PT_DWORD, (ULONG_PTR) gdwDefPortNum, NULL },
  3250. };
  3251. FUNC_PARAM_HEADER paramsHeader =
  3252. { 1, funcIndex, params, NULL };
  3253. if (LetUserMungeParams (&paramsHeader))
  3254. {
  3255. struct protoent *ppe;
  3256. // note: WinSock owns the returned ptr, don't free/munge it
  3257. if ((ppe = getprotobynumber ((int) params[0].dwValue)))
  3258. {
  3259. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3260. ShowProtoEnt (ppe);
  3261. }
  3262. else
  3263. {
  3264. ShowError (funcIndex, 0);
  3265. }
  3266. }
  3267. break;
  3268. }
  3269. case ws_getservbyname:
  3270. {
  3271. char szServName[MAX_STRING_PARAM_SIZE];
  3272. char szProtoName[MAX_STRING_PARAM_SIZE];
  3273. FUNC_PARAM params[] =
  3274. {
  3275. { "serviceName", PT_STRING, (ULONG_PTR) szServName, szServName },
  3276. { "protoName", PT_STRING, (ULONG_PTR) 0, szProtoName },
  3277. };
  3278. FUNC_PARAM_HEADER paramsHeader =
  3279. { 2, funcIndex, params, NULL };
  3280. lstrcpyA (szServName, gszDefServName);
  3281. lstrcpyA (szProtoName, gszDefProtoName);
  3282. if (LetUserMungeParams (&paramsHeader))
  3283. {
  3284. struct servent *pse;
  3285. // note: WinSock owns the returned ptr, don't free/munge it
  3286. if ((pse = getservbyname(
  3287. (char FAR *) params[0].dwValue,
  3288. (char FAR *) params[1].dwValue
  3289. )))
  3290. {
  3291. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3292. ShowServEnt (pse);
  3293. }
  3294. else
  3295. {
  3296. ShowError (funcIndex, 0);
  3297. }
  3298. }
  3299. break;
  3300. }
  3301. case ws_getservbyport:
  3302. {
  3303. char szProtoName[MAX_STRING_PARAM_SIZE];
  3304. FUNC_PARAM params[] =
  3305. {
  3306. { "port", PT_DWORD, (ULONG_PTR) gdwDefPortNum, NULL },
  3307. { "protoName", PT_STRING, (ULONG_PTR) 0, szProtoName },
  3308. };
  3309. FUNC_PARAM_HEADER paramsHeader =
  3310. { 2, funcIndex, params, NULL };
  3311. lstrcpyA (szProtoName, gszDefProtoName);
  3312. if (LetUserMungeParams (&paramsHeader))
  3313. {
  3314. struct servent *pse;
  3315. // note: WinSock owns the returned ptr, don't free/munge it
  3316. if ((pse = getservbyport(
  3317. (int) params[0].dwValue,
  3318. (char FAR *) params[1].dwValue
  3319. )))
  3320. {
  3321. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3322. ShowServEnt (pse);
  3323. }
  3324. else
  3325. {
  3326. ShowError (funcIndex, 0);
  3327. }
  3328. }
  3329. break;
  3330. }
  3331. case ws_getsockopt:
  3332. {
  3333. int iOptionBufLength = dwBigBufSize;
  3334. FUNC_PARAM params[] =
  3335. {
  3336. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3337. { "iLevel", PT_ORDINAL, (ULONG_PTR) 0, aSockOptLevels },
  3338. { "iOptionName", PT_ORDINAL, (ULONG_PTR) 0, aSockOpts },
  3339. { "lpOptionBuf", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  3340. { "lpiOptionBufLength", PT_POINTER, (ULONG_PTR) &iOptionBufLength, &iOptionBufLength },
  3341. };
  3342. FUNC_PARAM_HEADER paramsHeader =
  3343. { 5, funcIndex, params, NULL };
  3344. if (LetUserMungeParams (&paramsHeader))
  3345. {
  3346. if ((i = getsockopt(
  3347. (SOCKET) params[0].dwValue,
  3348. (int) params[1].dwValue,
  3349. (int) params[2].dwValue,
  3350. (char FAR *) params[3].dwValue,
  3351. (int FAR *) params[4].dwValue
  3352. )) == 0)
  3353. {
  3354. // getockopt: format returned OptionBuf data
  3355. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3356. ShowStr(
  3357. " Level/OptionName=%d/%d, %s/%s",
  3358. params[1].dwValue,
  3359. params[2].dwValue,
  3360. GetStringFromOrdinalValue(
  3361. (DWORD) params[1].dwValue,
  3362. aSockOptLevels
  3363. ),
  3364. GetStringFromOrdinalValue(
  3365. (DWORD) params[2].dwValue,
  3366. aSockOpts
  3367. )
  3368. );
  3369. ShowStr(
  3370. " *lpiOptionBufLength=x%x",
  3371. *((int *) params[4].dwValue)
  3372. );
  3373. ShowStr (" *lpOptionBuf=");
  3374. ShowBytes(
  3375. (DWORD) *((int *) params[4].dwValue),
  3376. (LPVOID) params[3].dwValue,
  3377. 1
  3378. );
  3379. }
  3380. else if (i == SOCKET_ERROR)
  3381. {
  3382. ShowError (funcIndex, 0);
  3383. }
  3384. else
  3385. {
  3386. ShowUnknownError (funcIndex, i);
  3387. }
  3388. }
  3389. break;
  3390. }
  3391. case ws_htonl:
  3392. {
  3393. FUNC_PARAM params[] =
  3394. {
  3395. { "hostLong", PT_DWORD, (ULONG_PTR) 0x12345678, NULL },
  3396. };
  3397. FUNC_PARAM_HEADER paramsHeader =
  3398. { 1, funcIndex, params, NULL };
  3399. if (LetUserMungeParams (&paramsHeader))
  3400. {
  3401. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3402. ShowStr (" hostLong=x%x", params[0].dwValue);
  3403. ShowStr (" networkLong=x%x", htonl ((u_long) params[0].dwValue));
  3404. }
  3405. break;
  3406. }
  3407. case ws_htons:
  3408. {
  3409. FUNC_PARAM params[] =
  3410. {
  3411. { "hostShort", PT_DWORD, (ULONG_PTR) 0x1234, NULL },
  3412. };
  3413. FUNC_PARAM_HEADER paramsHeader =
  3414. { 1, funcIndex, params, NULL };
  3415. if (LetUserMungeParams (&paramsHeader))
  3416. {
  3417. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3418. ShowStr (" hostShort=x%x", (DWORD) LOWORD(params[0].dwValue));
  3419. ShowStr(
  3420. " networkShort=x%x",
  3421. (DWORD) htons ((u_short) LOWORD(params[0].dwValue))
  3422. );
  3423. }
  3424. break;
  3425. }
  3426. case ws_inet_addr:
  3427. {
  3428. char szInetAddr[MAX_STRING_PARAM_SIZE] = "1.2.3.4";
  3429. FUNC_PARAM params[] =
  3430. {
  3431. { "szInternetAddress", PT_STRING, (ULONG_PTR) szInetAddr, szInetAddr },
  3432. };
  3433. FUNC_PARAM_HEADER paramsHeader =
  3434. { 1, funcIndex, params, NULL };
  3435. if (LetUserMungeParams (&paramsHeader))
  3436. {
  3437. unsigned long l = inet_addr ((char FAR *) params[0].dwValue);
  3438. if (l != INADDR_NONE)
  3439. {
  3440. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3441. ShowStr (" ulInternetAddress=x%x", l);
  3442. }
  3443. else
  3444. {
  3445. ShowStr ("inet_addr error: INADDR_NONE");
  3446. }
  3447. }
  3448. break;
  3449. }
  3450. case ws_inet_ntoa:
  3451. {
  3452. FUNC_PARAM params[] =
  3453. {
  3454. { "ulInternetAddress", PT_DWORD, (ULONG_PTR) 0x04030201, NULL },
  3455. };
  3456. FUNC_PARAM_HEADER paramsHeader =
  3457. { 1, funcIndex, params, NULL };
  3458. if (LetUserMungeParams (&paramsHeader))
  3459. {
  3460. char FAR *pszInetAddr;
  3461. struct in_addr ia;
  3462. CopyMemory (&ia, &params[0].dwValue, sizeof (DWORD));
  3463. if ((pszInetAddr = inet_ntoa (ia)))
  3464. {
  3465. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3466. ShowStr (" pszInternetAddress=x%x", pszInetAddr);
  3467. ShowStr (" szInternetAddress=%s", pszInetAddr);
  3468. }
  3469. else
  3470. {
  3471. ShowStr ("inet_ntoa error: returned NULL");
  3472. }
  3473. }
  3474. break;
  3475. }
  3476. case ws_ioctlsocket:
  3477. {
  3478. FUNC_PARAM params[] =
  3479. {
  3480. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3481. { "lCommand", PT_ORDINAL, (ULONG_PTR) 0, aIoctlCmds },
  3482. { "lpData", PT_POINTER, (ULONG_PTR) pBigBuf, pBigBuf }
  3483. };
  3484. FUNC_PARAM_HEADER paramsHeader =
  3485. { 3, funcIndex, params, NULL };
  3486. if (LetUserMungeParams (&paramsHeader))
  3487. {
  3488. if ((i = ioctlsocket(
  3489. (SOCKET) params[0].dwValue,
  3490. (long) params[1].dwValue,
  3491. (u_long FAR *) params[2].dwValue
  3492. )) == 0)
  3493. {
  3494. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3495. ShowStr(
  3496. " lCommand=%d, %s",
  3497. params[1].dwValue,
  3498. GetStringFromOrdinalValue(
  3499. (DWORD) params[1].dwValue,
  3500. aIoctlCmds
  3501. )
  3502. );
  3503. ShowStr (" *lpData=");
  3504. ShowBytes (16, (LPVOID) params[2].dwValue, 1);
  3505. }
  3506. else if (i == SOCKET_ERROR)
  3507. {
  3508. ShowError (funcIndex, 0);
  3509. }
  3510. else
  3511. {
  3512. ShowUnknownError (funcIndex, i);
  3513. }
  3514. }
  3515. break;
  3516. }
  3517. case ws_listen:
  3518. {
  3519. FUNC_PARAM params[] =
  3520. {
  3521. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3522. { "iBacklog", PT_DWORD, (ULONG_PTR) 0, NULL }
  3523. };
  3524. FUNC_PARAM_HEADER paramsHeader =
  3525. { 2, funcIndex, params, NULL };
  3526. if (LetUserMungeParams (&paramsHeader))
  3527. {
  3528. if ((i = listen(
  3529. (SOCKET) params[0].dwValue,
  3530. (int) params[1].dwValue
  3531. )) == 0)
  3532. {
  3533. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3534. }
  3535. else if (i == SOCKET_ERROR)
  3536. {
  3537. ShowError (funcIndex, 0);
  3538. }
  3539. else
  3540. {
  3541. ShowUnknownError (funcIndex, i);
  3542. }
  3543. }
  3544. break;
  3545. }
  3546. case ws_ntohl:
  3547. {
  3548. FUNC_PARAM params[] =
  3549. {
  3550. { "networkLong", PT_DWORD, (ULONG_PTR) 0x12345678, NULL },
  3551. };
  3552. FUNC_PARAM_HEADER paramsHeader =
  3553. { 1, funcIndex, params, NULL };
  3554. if (LetUserMungeParams (&paramsHeader))
  3555. {
  3556. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3557. ShowStr (" networkLong=x%x", params[0].dwValue);
  3558. ShowStr (" hostLong=x%x", ntohl ((u_long) params[0].dwValue));
  3559. }
  3560. break;
  3561. }
  3562. case ws_ntohs:
  3563. {
  3564. FUNC_PARAM params[] =
  3565. {
  3566. { "networkShort", PT_DWORD, (ULONG_PTR) 0x1234, NULL },
  3567. };
  3568. FUNC_PARAM_HEADER paramsHeader =
  3569. { 1, funcIndex, params, NULL };
  3570. if (LetUserMungeParams (&paramsHeader))
  3571. {
  3572. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3573. ShowStr (" networkShort=x%x",(DWORD) LOWORD(params[0].dwValue));
  3574. ShowStr(
  3575. " hostShort=x%x",
  3576. (DWORD) ntohs ((u_short) LOWORD(params[0].dwValue))
  3577. );
  3578. }
  3579. break;
  3580. }
  3581. case ws_recv:
  3582. {
  3583. FUNC_PARAM params[] =
  3584. {
  3585. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3586. { "lpBuf", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  3587. { "iBufLength", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  3588. { "iRecvFlags", PT_FLAGS, (ULONG_PTR) gdwDefRecvFlags, aRecvFlags },
  3589. };
  3590. FUNC_PARAM_HEADER paramsHeader =
  3591. { 4, funcIndex, params, NULL };
  3592. if (LetUserMungeParams (&paramsHeader))
  3593. {
  3594. if ((i = recv(
  3595. (SOCKET) params[0].dwValue,
  3596. (char FAR *) params[1].dwValue,
  3597. (int) params[2].dwValue,
  3598. (int) params[3].dwValue
  3599. )) != SOCKET_ERROR)
  3600. {
  3601. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3602. ShowStr (" NumByteReceived=x%x", i);
  3603. ShowStr (" *pBuf=");
  3604. ShowBytes (i, (LPVOID) params[1].dwValue, 1);
  3605. }
  3606. else
  3607. {
  3608. ShowError (funcIndex, 0);
  3609. }
  3610. }
  3611. break;
  3612. }
  3613. case ws_recvfrom:
  3614. {
  3615. int iSrcAddrLen;
  3616. struct sockaddr FAR *pSrcAddr = MyAlloc (dwBigBufSize);
  3617. FUNC_PARAM params[] =
  3618. {
  3619. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3620. { "lpBuf", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  3621. { "iBufLength", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  3622. { "iRecvFlags", PT_FLAGS, (ULONG_PTR) gdwDefRecvFlags, aRecvFlags },
  3623. { "lpSourceAddr", PT_PTRNOEDIT, (ULONG_PTR) pSrcAddr, pSrcAddr },
  3624. { "lpiSourceAddrLength",PT_POINTER, (ULONG_PTR) &iSrcAddrLen, &iSrcAddrLen },
  3625. };
  3626. FUNC_PARAM_HEADER paramsHeader =
  3627. { 6, funcIndex, params, NULL };
  3628. if (!pSrcAddr)
  3629. {
  3630. break;
  3631. }
  3632. if (LetUserMungeParams (&paramsHeader))
  3633. {
  3634. if ((i = recvfrom(
  3635. (SOCKET) params[0].dwValue,
  3636. (char FAR *) params[1].dwValue,
  3637. (int) params[2].dwValue,
  3638. (int) params[3].dwValue,
  3639. (struct sockaddr FAR *) params[4].dwValue,
  3640. (int FAR *) params[5].dwValue
  3641. )) != SOCKET_ERROR)
  3642. {
  3643. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3644. ShowStr (" NumByteReceived=x%x", i);
  3645. ShowStr (" *pBuf=");
  3646. ShowBytes (i, (LPVOID) params[1].dwValue, 1);
  3647. ShowStr(
  3648. " *lpiSourceAddrLength=%d",
  3649. (DWORD) *((int *) params[5].dwValue)
  3650. );
  3651. ShowStr (" *lpSourceAddr=");
  3652. ShowBytes(
  3653. *((int *) params[5].dwValue),
  3654. (LPVOID) params[4].dwValue,
  3655. 1
  3656. );
  3657. }
  3658. else
  3659. {
  3660. ShowError (funcIndex, 0);
  3661. }
  3662. }
  3663. MyFree (pSrcAddr);
  3664. break;
  3665. }
  3666. case ws_select:
  3667. // case ws_select:
  3668. break;
  3669. case ws_send:
  3670. {
  3671. FUNC_PARAM params[] =
  3672. {
  3673. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3674. { "lpBuf", PT_POINTER, (ULONG_PTR) pBigBuf, pBigBuf },
  3675. { "iBufLength", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  3676. { "iSendFlags", PT_FLAGS, (ULONG_PTR) gdwDefSendFlags, aSendFlags },
  3677. };
  3678. FUNC_PARAM_HEADER paramsHeader =
  3679. { 4, funcIndex, params, NULL };
  3680. if (LetUserMungeParams (&paramsHeader))
  3681. {
  3682. if ((i = send(
  3683. (SOCKET) params[0].dwValue,
  3684. (char FAR *) params[1].dwValue,
  3685. (int) params[2].dwValue,
  3686. (int) params[3].dwValue
  3687. )) != SOCKET_ERROR)
  3688. {
  3689. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3690. ShowStr (" NumBytesSent=x%x", i);
  3691. }
  3692. else
  3693. {
  3694. ShowError (funcIndex, 0);
  3695. }
  3696. }
  3697. break;
  3698. }
  3699. case ws_sendto:
  3700. {
  3701. int iTargetAddrLen;
  3702. struct sockaddr FAR *pTargetAddr = MyAlloc (dwBigBufSize);
  3703. FUNC_PARAM params[] =
  3704. {
  3705. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3706. { "lpBuf", PT_POINTER, (ULONG_PTR) pBigBuf, pBigBuf },
  3707. { "iBufLength", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  3708. { "iSendFlags", PT_FLAGS, (ULONG_PTR) gdwDefSendFlags, aSendFlags },
  3709. { "lpTargetAddr", PT_POINTER, (ULONG_PTR) pTargetAddr, pTargetAddr },
  3710. { "iTargetAddrLength", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  3711. };
  3712. FUNC_PARAM_HEADER paramsHeader =
  3713. { 6, funcIndex, params, NULL };
  3714. if (LetUserMungeParams (&paramsHeader))
  3715. {
  3716. if ((i = sendto(
  3717. (SOCKET) params[0].dwValue,
  3718. (char FAR *) params[1].dwValue,
  3719. (int) params[2].dwValue,
  3720. (int) params[3].dwValue,
  3721. (struct sockaddr FAR *) params[4].dwValue,
  3722. (int) params[5].dwValue
  3723. )) != SOCKET_ERROR)
  3724. {
  3725. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3726. ShowStr (" NumBytesSent=x%x", i);
  3727. }
  3728. else
  3729. {
  3730. ShowError (funcIndex, 0);
  3731. }
  3732. }
  3733. break;
  3734. }
  3735. case ws_setsockopt:
  3736. {
  3737. int iOptionBufLength = dwBigBufSize;
  3738. FUNC_PARAM params[] =
  3739. {
  3740. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3741. { "iLevel", PT_ORDINAL, (ULONG_PTR) 0, aSockOptLevels },
  3742. { "iOptionName", PT_ORDINAL, (ULONG_PTR) 0, aSockOpts },
  3743. { "lpOptionBuf", PT_POINTER, (ULONG_PTR) pBigBuf, pBigBuf },
  3744. { "iOptionBufLength", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  3745. };
  3746. FUNC_PARAM_HEADER paramsHeader =
  3747. { 5, funcIndex, params, NULL };
  3748. if (LetUserMungeParams (&paramsHeader))
  3749. {
  3750. if ((i = setsockopt(
  3751. (SOCKET) params[0].dwValue,
  3752. (int) params[1].dwValue,
  3753. (int) params[2].dwValue,
  3754. (char FAR *) params[3].dwValue,
  3755. (int) params[4].dwValue
  3756. )) == 0)
  3757. {
  3758. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3759. }
  3760. else if (i == SOCKET_ERROR)
  3761. {
  3762. ShowError (funcIndex, 0);
  3763. }
  3764. else
  3765. {
  3766. ShowUnknownError (funcIndex, i);
  3767. }
  3768. }
  3769. break;
  3770. }
  3771. case ws_shutdown:
  3772. {
  3773. FUNC_PARAM params[] =
  3774. {
  3775. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3776. { "iHow", PT_ORDINAL, (ULONG_PTR) 0, aShutdownOps },
  3777. };
  3778. FUNC_PARAM_HEADER paramsHeader =
  3779. { 2, funcIndex, params, NULL };
  3780. if (LetUserMungeParams (&paramsHeader))
  3781. {
  3782. if ((i = shutdown(
  3783. (SOCKET) params[0].dwValue,
  3784. (int) params[1].dwValue
  3785. )) == 0)
  3786. {
  3787. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3788. }
  3789. else if (i == SOCKET_ERROR)
  3790. {
  3791. ShowError (funcIndex, 0);
  3792. }
  3793. else
  3794. {
  3795. ShowUnknownError (funcIndex, i);
  3796. }
  3797. }
  3798. break;
  3799. }
  3800. case ws_socket:
  3801. {
  3802. FUNC_PARAM params[] =
  3803. {
  3804. { "address family", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  3805. { "socket type", PT_ORDINAL, (ULONG_PTR) gdwDefSocketType, aSocketTypes },
  3806. { "protocol", PT_DWORD, (ULONG_PTR) gdwDefProtocol, aProtocols },
  3807. };
  3808. FUNC_PARAM_HEADER paramsHeader =
  3809. { 3, funcIndex, params, NULL };
  3810. if (LetUserMungeParams (&paramsHeader))
  3811. {
  3812. PMYSOCKET pSocket;
  3813. if (!(pSocket = MyAlloc (sizeof (MYSOCKET))))
  3814. {
  3815. break;
  3816. }
  3817. if ((pSocket->Sock = socket(
  3818. (int) params[0].dwValue,
  3819. (int) params[1].dwValue,
  3820. (int) params[2].dwValue
  3821. )) != INVALID_SOCKET)
  3822. {
  3823. char buf[128];
  3824. LRESULT index;
  3825. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3826. pSocket->dwAddressFamily = (DWORD) params[0].dwValue;
  3827. pSocket->dwSocketType = (DWORD) params[1].dwValue;
  3828. wsprintf(
  3829. buf,
  3830. "Socket=x%x (%s %s)",
  3831. pSocket->Sock,
  3832. GetStringFromOrdinalValue(
  3833. pSocket->dwAddressFamily,
  3834. aAddressFamilies
  3835. ),
  3836. GetStringFromOrdinalValue(
  3837. pSocket->dwSocketType,
  3838. aSocketTypes
  3839. )
  3840. );
  3841. index = SendMessage(
  3842. ghwndList1,
  3843. LB_ADDSTRING,
  3844. 0,
  3845. (LPARAM) buf
  3846. );
  3847. SendMessage(
  3848. ghwndList1,
  3849. LB_SETITEMDATA,
  3850. index,
  3851. (LPARAM) pSocket
  3852. );
  3853. }
  3854. else
  3855. {
  3856. ShowError (funcIndex, 0);
  3857. MyFree (pSocket);
  3858. }
  3859. }
  3860. break;
  3861. }
  3862. case ws_WSAAccept:
  3863. {
  3864. int iAddrLen = dwBigBufSize;
  3865. FUNC_PARAM params[] =
  3866. {
  3867. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  3868. { "lpAddr", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  3869. { "lpiAddrLen", PT_DWORD, (ULONG_PTR) &iAddrLen, &iAddrLen },
  3870. { "lpfnCondition", PT_DWORD, (ULONG_PTR) ConditionProc, ConditionProc },
  3871. { "dwCallbackData", PT_DWORD, (ULONG_PTR) 0, NULL }
  3872. };
  3873. FUNC_PARAM_HEADER paramsHeader =
  3874. { 5, funcIndex, params, NULL };
  3875. if (LetUserMungeParams (&paramsHeader))
  3876. {
  3877. SOCKET s;
  3878. if ((s = WSAAccept(
  3879. (SOCKET) params[0].dwValue,
  3880. (struct sockaddr FAR *) params[1].dwValue,
  3881. (LPINT) params[2].dwValue,
  3882. (LPCONDITIONPROC) params[3].dwValue,
  3883. params[4].dwValue
  3884. )) != INVALID_SOCKET)
  3885. {
  3886. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3887. ShowStr (" returned socket=x%x", s);
  3888. if (params[1].dwValue &&
  3889. params[2].dwValue &&
  3890. *((LPINT) params[2].dwValue))
  3891. {
  3892. struct sockaddr FAR *pSockAddr = (struct sockaddr FAR *)
  3893. params[1].dwValue;
  3894. ShowStr(
  3895. " lpAddr->AddressFamily=%d, %s",
  3896. (DWORD) pSockAddr->sa_family,
  3897. GetStringFromOrdinalValue(
  3898. (DWORD) pSockAddr->sa_family,
  3899. aAddressFamilies
  3900. )
  3901. );
  3902. ShowStr ( "lpAddr->sa_data=");
  3903. ShowBytes(
  3904. *((LPINT) params[2].dwValue) - sizeof (u_short),
  3905. pSockAddr->sa_data,
  3906. 1
  3907. );
  3908. }
  3909. }
  3910. else
  3911. {
  3912. ShowError (funcIndex, 0);
  3913. }
  3914. }
  3915. break;
  3916. }
  3917. case ws_WSAAddressToStringA:
  3918. case ws_WSAAddressToStringW:
  3919. {
  3920. DWORD dwAddrStrLen = dwBigBufSize;
  3921. LPSTR pszAddrStr = MyAlloc (dwBigBufSize);
  3922. LPWSAPROTOCOL_INFOA pProtoInfo = (funcIndex == ws_WSAAddressToStringA ?
  3923. &gWSAProtocolInfoA :
  3924. (LPWSAPROTOCOL_INFOA) &gWSAProtocolInfoW);
  3925. FUNC_PARAM params[] =
  3926. {
  3927. { "lpsaAddress", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  3928. { " ->sa_family", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  3929. { " ->sa_data", PT_POINTER, (ULONG_PTR) (pBigBuf + 2), pBigBuf + 2},
  3930. { "dwAddressLength", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  3931. { "lpProtocolInfo", PT_WSAPROTOCOLINFO, (ULONG_PTR) pProtoInfo, pProtoInfo },
  3932. { "lpszAddressString", PT_POINTER, (ULONG_PTR) pszAddrStr, pszAddrStr },
  3933. { "lpdwAddressStringLength",PT_POINTER, (ULONG_PTR) &dwAddrStrLen, &dwAddrStrLen }
  3934. };
  3935. FUNC_PARAM_HEADER paramsHeader =
  3936. { 7, funcIndex, params, NULL };
  3937. if (LetUserMungeParams (&paramsHeader))
  3938. {
  3939. LPSOCKADDR pSockAddr = (LPSOCKADDR) params[0].dwValue;
  3940. if (!IsBadWritePtr (pSockAddr, sizeof (WORD)))
  3941. {
  3942. pSockAddr->sa_family = (short) params[1].dwValue;
  3943. }
  3944. if (funcIndex == ws_WSAAddressToStringA)
  3945. {
  3946. i = WSAAddressToStringA(
  3947. (LPSOCKADDR) params[0].dwValue,
  3948. (DWORD) params[3].dwValue,
  3949. (LPWSAPROTOCOL_INFOA) params[4].dwValue,
  3950. (LPSTR) params[5].dwValue,
  3951. (LPDWORD) params[6].dwValue
  3952. );
  3953. }
  3954. else
  3955. {
  3956. i = WSAAddressToStringW(
  3957. (LPSOCKADDR) params[0].dwValue,
  3958. (DWORD) params[3].dwValue,
  3959. (LPWSAPROTOCOL_INFOW) params[4].dwValue,
  3960. (LPWSTR) params[5].dwValue,
  3961. (LPDWORD) params[6].dwValue
  3962. );
  3963. }
  3964. if (i == 0)
  3965. {
  3966. DWORD dwLength = *((LPDWORD) params[6].dwValue);
  3967. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  3968. ShowStr (" *lpdwAddressStringLength=x%x", dwLength);
  3969. ShowStr (" *lpszAddressString=");
  3970. ShowBytes(
  3971. (funcIndex == ws_WSAAddressToStringA ?
  3972. dwLength : dwLength * sizeof(WCHAR)),
  3973. (LPVOID) params[5].dwValue,
  3974. 1
  3975. );
  3976. }
  3977. else if (i == SOCKET_ERROR)
  3978. {
  3979. ShowError (funcIndex, 0);
  3980. }
  3981. else
  3982. {
  3983. ShowUnknownError (funcIndex, i);
  3984. }
  3985. }
  3986. break;
  3987. }
  3988. case ws_WSAAsyncGetHostByAddr:
  3989. {
  3990. PASYNC_REQUEST_INFO pAsyncReqInfo;
  3991. if ((pAsyncReqInfo = MyAlloc(
  3992. sizeof (ASYNC_REQUEST_INFO) + dwBigBufSize
  3993. )))
  3994. {
  3995. char szHostAddr[MAX_STRING_PARAM_SIZE] = "1.2.3.4";
  3996. FUNC_PARAM params[] =
  3997. {
  3998. { "hwnd", PT_DWORD, (ULONG_PTR) ghwndMain, NULL },
  3999. { "wMsg", PT_DWORD, (ULONG_PTR) WM_ASYNCREQUESTCOMPLETED, NULL },
  4000. { "addr", PT_POINTER, (ULONG_PTR) pBigBuf, pBigBuf },
  4001. { "len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4002. { "type", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  4003. { "buf", PT_PTRNOEDIT, (ULONG_PTR) (pAsyncReqInfo+1), pAsyncReqInfo + 1 },
  4004. { "buflen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4005. };
  4006. FUNC_PARAM_HEADER paramsHeader =
  4007. { 7, funcIndex, params, NULL };
  4008. if (LetUserMungeParams (&paramsHeader))
  4009. {
  4010. if ((pAsyncReqInfo->hRequest = WSAAsyncGetHostByAddr(
  4011. (HWND) params[0].dwValue,
  4012. (unsigned int) params[1].dwValue,
  4013. (char FAR *) params[2].dwValue,
  4014. (int) params[3].dwValue,
  4015. (int) params[4].dwValue,
  4016. (char FAR *) params[5].dwValue,
  4017. (int) params[6].dwValue
  4018. )))
  4019. {
  4020. ShowStr(
  4021. "%s returned hRequest=x%x",
  4022. aFuncNames[funcIndex],
  4023. pAsyncReqInfo->hRequest
  4024. );
  4025. pAsyncReqInfo->pszFuncName = aFuncNames[funcIndex];
  4026. pAsyncReqInfo->FuncIndex = funcIndex;
  4027. QueueAsyncRequestInfo (pAsyncReqInfo);
  4028. break;
  4029. }
  4030. else
  4031. {
  4032. ShowError (funcIndex, 0);
  4033. }
  4034. }
  4035. MyFree (pAsyncReqInfo);
  4036. }
  4037. break;
  4038. }
  4039. case ws_WSAAsyncGetHostByName:
  4040. {
  4041. PASYNC_REQUEST_INFO pAsyncReqInfo;
  4042. if ((pAsyncReqInfo = MyAlloc(
  4043. sizeof (ASYNC_REQUEST_INFO) + dwBigBufSize
  4044. )))
  4045. {
  4046. char szHostName[MAX_STRING_PARAM_SIZE];
  4047. FUNC_PARAM params[] =
  4048. {
  4049. { "hwnd", PT_DWORD, (ULONG_PTR) ghwndMain, NULL },
  4050. { "wMsg", PT_DWORD, (ULONG_PTR) WM_ASYNCREQUESTCOMPLETED, NULL },
  4051. { "name", PT_STRING, (ULONG_PTR) szHostName, szHostName },
  4052. { "buf", PT_PTRNOEDIT, (ULONG_PTR) (pAsyncReqInfo+1), pAsyncReqInfo + 1 },
  4053. { "buflen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4054. };
  4055. FUNC_PARAM_HEADER paramsHeader =
  4056. { 5, funcIndex, params, NULL };
  4057. lstrcpyA (szHostName, gszDefHostName);
  4058. if (LetUserMungeParams (&paramsHeader))
  4059. {
  4060. if ((pAsyncReqInfo->hRequest = WSAAsyncGetHostByName(
  4061. (HWND) params[0].dwValue,
  4062. (unsigned int) params[1].dwValue,
  4063. (char FAR *) params[2].dwValue,
  4064. (char FAR *) params[3].dwValue,
  4065. (int) params[4].dwValue
  4066. )))
  4067. {
  4068. ShowStr(
  4069. "%s returned hRequest=x%x",
  4070. aFuncNames[funcIndex],
  4071. pAsyncReqInfo->hRequest
  4072. );
  4073. pAsyncReqInfo->pszFuncName = aFuncNames[funcIndex];
  4074. pAsyncReqInfo->FuncIndex = funcIndex;
  4075. QueueAsyncRequestInfo (pAsyncReqInfo);
  4076. break;
  4077. }
  4078. else
  4079. {
  4080. ShowError (funcIndex, 0);
  4081. }
  4082. }
  4083. MyFree (pAsyncReqInfo);
  4084. }
  4085. break;
  4086. }
  4087. case ws_WSAAsyncGetProtoByName:
  4088. {
  4089. PASYNC_REQUEST_INFO pAsyncReqInfo;
  4090. if ((pAsyncReqInfo = MyAlloc(
  4091. sizeof (ASYNC_REQUEST_INFO) + dwBigBufSize
  4092. )))
  4093. {
  4094. char szProtoName[MAX_STRING_PARAM_SIZE];
  4095. FUNC_PARAM params[] =
  4096. {
  4097. { "hwnd", PT_DWORD, (ULONG_PTR) ghwndMain, NULL },
  4098. { "wMsg", PT_DWORD, (ULONG_PTR) WM_ASYNCREQUESTCOMPLETED, NULL },
  4099. { "name", PT_STRING, (ULONG_PTR) szProtoName, szProtoName },
  4100. { "buf", PT_PTRNOEDIT, (ULONG_PTR) (pAsyncReqInfo+1), pAsyncReqInfo + 1 },
  4101. { "buflen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4102. };
  4103. FUNC_PARAM_HEADER paramsHeader =
  4104. { 5, funcIndex, params, NULL };
  4105. lstrcpyA (szProtoName, gszDefProtoName);
  4106. if (LetUserMungeParams (&paramsHeader))
  4107. {
  4108. if ((pAsyncReqInfo->hRequest = WSAAsyncGetProtoByName(
  4109. (HWND) params[0].dwValue,
  4110. (unsigned int) params[1].dwValue,
  4111. (char FAR *) params[2].dwValue,
  4112. (char FAR *) params[3].dwValue,
  4113. (int) params[4].dwValue
  4114. )))
  4115. {
  4116. ShowStr(
  4117. "%s returned hRequest=x%x",
  4118. aFuncNames[funcIndex],
  4119. pAsyncReqInfo->hRequest
  4120. );
  4121. pAsyncReqInfo->pszFuncName = aFuncNames[funcIndex];
  4122. pAsyncReqInfo->FuncIndex = funcIndex;
  4123. QueueAsyncRequestInfo (pAsyncReqInfo);
  4124. break;
  4125. }
  4126. else
  4127. {
  4128. ShowError (funcIndex, 0);
  4129. }
  4130. }
  4131. MyFree (pAsyncReqInfo);
  4132. }
  4133. break;
  4134. }
  4135. case ws_WSAAsyncGetProtoByNumber:
  4136. {
  4137. PASYNC_REQUEST_INFO pAsyncReqInfo;
  4138. if ((pAsyncReqInfo = MyAlloc(
  4139. sizeof (ASYNC_REQUEST_INFO) + dwBigBufSize
  4140. )))
  4141. {
  4142. FUNC_PARAM params[] =
  4143. {
  4144. { "hwnd", PT_DWORD, (ULONG_PTR) ghwndMain, NULL },
  4145. { "wMsg", PT_DWORD, (ULONG_PTR) WM_ASYNCREQUESTCOMPLETED, NULL },
  4146. { "number", PT_DWORD, (ULONG_PTR) gdwDefProtoNum, NULL },
  4147. { "buf", PT_PTRNOEDIT, (ULONG_PTR) (pAsyncReqInfo+1), pAsyncReqInfo + 1 },
  4148. { "buflen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4149. };
  4150. FUNC_PARAM_HEADER paramsHeader =
  4151. { 5, funcIndex, params, NULL };
  4152. if (LetUserMungeParams (&paramsHeader))
  4153. {
  4154. if ((pAsyncReqInfo->hRequest = WSAAsyncGetProtoByNumber(
  4155. (HWND) params[0].dwValue,
  4156. (unsigned int) params[1].dwValue,
  4157. (int) params[2].dwValue,
  4158. (char FAR *) params[3].dwValue,
  4159. (int) params[4].dwValue
  4160. )))
  4161. {
  4162. ShowStr(
  4163. "%s returned hRequest=x%x",
  4164. aFuncNames[funcIndex],
  4165. pAsyncReqInfo->hRequest
  4166. );
  4167. pAsyncReqInfo->pszFuncName = aFuncNames[funcIndex];
  4168. pAsyncReqInfo->FuncIndex = funcIndex;
  4169. QueueAsyncRequestInfo (pAsyncReqInfo);
  4170. break;
  4171. }
  4172. else
  4173. {
  4174. ShowError (funcIndex, 0);
  4175. }
  4176. }
  4177. MyFree (pAsyncReqInfo);
  4178. }
  4179. break;
  4180. }
  4181. case ws_WSAAsyncGetServByName:
  4182. {
  4183. PASYNC_REQUEST_INFO pAsyncReqInfo;
  4184. if ((pAsyncReqInfo = MyAlloc(
  4185. sizeof (ASYNC_REQUEST_INFO) + dwBigBufSize
  4186. )))
  4187. {
  4188. char szServName[MAX_STRING_PARAM_SIZE];
  4189. char szProtoName[MAX_STRING_PARAM_SIZE];
  4190. FUNC_PARAM params[] =
  4191. {
  4192. { "hwnd", PT_DWORD, (ULONG_PTR) ghwndMain, NULL },
  4193. { "wMsg", PT_DWORD, (ULONG_PTR) WM_ASYNCREQUESTCOMPLETED, NULL },
  4194. { "name", PT_STRING, (ULONG_PTR) szServName, szServName },
  4195. { "proto", PT_STRING, (ULONG_PTR) 0, szProtoName },
  4196. { "buf", PT_PTRNOEDIT, (ULONG_PTR) (pAsyncReqInfo+1), pAsyncReqInfo + 1 },
  4197. { "buflen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4198. };
  4199. FUNC_PARAM_HEADER paramsHeader =
  4200. { 6, funcIndex, params, NULL };
  4201. lstrcpyA (szServName, gszDefServName);
  4202. lstrcpyA (szProtoName, gszDefProtoName);
  4203. if (LetUserMungeParams (&paramsHeader))
  4204. {
  4205. if ((pAsyncReqInfo->hRequest = WSAAsyncGetServByName(
  4206. (HWND) params[0].dwValue,
  4207. (unsigned int) params[1].dwValue,
  4208. (char FAR *) params[2].dwValue,
  4209. (char FAR *) params[3].dwValue,
  4210. (char FAR *) params[4].dwValue,
  4211. (int) params[5].dwValue
  4212. )))
  4213. {
  4214. ShowStr(
  4215. "%s returned hRequest=x%x",
  4216. aFuncNames[funcIndex],
  4217. pAsyncReqInfo->hRequest
  4218. );
  4219. pAsyncReqInfo->pszFuncName = aFuncNames[funcIndex];
  4220. pAsyncReqInfo->FuncIndex = funcIndex;
  4221. QueueAsyncRequestInfo (pAsyncReqInfo);
  4222. break;
  4223. }
  4224. else
  4225. {
  4226. ShowError (funcIndex, 0);
  4227. }
  4228. }
  4229. MyFree (pAsyncReqInfo);
  4230. }
  4231. break;
  4232. }
  4233. case ws_WSAAsyncGetServByPort:
  4234. {
  4235. PASYNC_REQUEST_INFO pAsyncReqInfo;
  4236. if ((pAsyncReqInfo = MyAlloc(
  4237. sizeof (ASYNC_REQUEST_INFO) + dwBigBufSize
  4238. )))
  4239. {
  4240. char szProtoName[MAX_STRING_PARAM_SIZE];
  4241. FUNC_PARAM params[] =
  4242. {
  4243. { "hwnd", PT_DWORD, (ULONG_PTR) ghwndMain, NULL },
  4244. { "wMsg", PT_DWORD, (ULONG_PTR) WM_ASYNCREQUESTCOMPLETED, NULL },
  4245. { "port", PT_DWORD, (ULONG_PTR) gdwDefPortNum, NULL },
  4246. { "proto", PT_STRING, (ULONG_PTR) 0, szProtoName },
  4247. { "buf", PT_PTRNOEDIT, (ULONG_PTR) (pAsyncReqInfo+1), pAsyncReqInfo + 1 },
  4248. { "buflen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4249. };
  4250. FUNC_PARAM_HEADER paramsHeader =
  4251. { 6, funcIndex, params, NULL };
  4252. lstrcpyA (szProtoName, gszDefProtoName);
  4253. if (LetUserMungeParams (&paramsHeader))
  4254. {
  4255. if ((pAsyncReqInfo->hRequest = WSAAsyncGetServByPort(
  4256. (HWND) params[0].dwValue,
  4257. (unsigned int) params[1].dwValue,
  4258. (int) params[2].dwValue,
  4259. (char FAR *) params[3].dwValue,
  4260. (char FAR *) params[4].dwValue,
  4261. (int) params[5].dwValue
  4262. )))
  4263. {
  4264. ShowStr(
  4265. "%s returned hRequest=x%x",
  4266. aFuncNames[funcIndex],
  4267. pAsyncReqInfo->hRequest
  4268. );
  4269. pAsyncReqInfo->pszFuncName = aFuncNames[funcIndex];
  4270. pAsyncReqInfo->FuncIndex = funcIndex;
  4271. QueueAsyncRequestInfo (pAsyncReqInfo);
  4272. break;
  4273. }
  4274. else
  4275. {
  4276. ShowError (funcIndex, 0);
  4277. }
  4278. }
  4279. MyFree (pAsyncReqInfo);
  4280. }
  4281. break;
  4282. }
  4283. case ws_WSAAsyncSelect:
  4284. {
  4285. FUNC_PARAM params[] =
  4286. {
  4287. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  4288. { "hwnd", PT_DWORD, (ULONG_PTR) ghwndMain, ghwndMain },
  4289. { "msg", PT_DWORD, (ULONG_PTR) WM_NETWORKEVENT, NULL },
  4290. { "lEvent", PT_FLAGS, (ULONG_PTR) 0, aNetworkEvents }
  4291. };
  4292. FUNC_PARAM_HEADER paramsHeader =
  4293. { 4, funcIndex, params, NULL };
  4294. if (LetUserMungeParams (&paramsHeader))
  4295. {
  4296. if ((i = WSAAsyncSelect(
  4297. (SOCKET) params[0].dwValue,
  4298. (HWND) params[1].dwValue,
  4299. (unsigned int) params[2].dwValue,
  4300. (long) params[3].dwValue
  4301. )) == 0)
  4302. {
  4303. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4304. }
  4305. else if (i == SOCKET_ERROR)
  4306. {
  4307. ShowError (funcIndex, 0);
  4308. }
  4309. else
  4310. {
  4311. ShowUnknownError (funcIndex, i);
  4312. }
  4313. }
  4314. break;
  4315. }
  4316. case ws_WSACancelAsyncRequest:
  4317. {
  4318. FUNC_PARAM params[] =
  4319. {
  4320. { "hRequest", PT_DWORD, (ULONG_PTR) (gpAsyncReqInfoList ? gpAsyncReqInfoList->hRequest : NULL), NULL }
  4321. };
  4322. FUNC_PARAM_HEADER paramsHeader =
  4323. { 1, funcIndex, params, NULL };
  4324. if (LetUserMungeParams (&paramsHeader))
  4325. {
  4326. if ((i = WSACancelAsyncRequest ((HANDLE) params[0].dwValue)) == 0)
  4327. {
  4328. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4329. }
  4330. else if (i == SOCKET_ERROR)
  4331. {
  4332. ShowError (funcIndex, 0);
  4333. }
  4334. else
  4335. {
  4336. ShowUnknownError (funcIndex, i);
  4337. }
  4338. }
  4339. break;
  4340. }
  4341. // case ws_WSACancelBlockingCall: not implemented in ws 2
  4342. //
  4343. // break;
  4344. case ws_WSACleanup:
  4345. {
  4346. FUNC_PARAM_HEADER paramsHeader =
  4347. { 0, funcIndex, NULL, NULL };
  4348. if (LetUserMungeParams (&paramsHeader))
  4349. {
  4350. if (WSACleanup() == 0)
  4351. {
  4352. char szButtonText[32];
  4353. wsprintf (szButtonText, "Startup (%d)", --giCurrNumStartups);
  4354. SetDlgItemText (ghwndMain, IDC_BUTTON1, szButtonText);
  4355. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4356. if (giCurrNumStartups == 0)
  4357. {
  4358. int iNumItems;
  4359. iNumItems = (int) SendMessage(
  4360. ghwndList1,
  4361. LB_GETCOUNT,
  4362. 0,
  4363. 0
  4364. );
  4365. for (i = 0; i < iNumItems; i++)
  4366. {
  4367. PMYSOCKET pSocket;
  4368. pSocket = (PMYSOCKET) SendMessage(
  4369. ghwndList1,
  4370. LB_GETITEMDATA,
  4371. 0,
  4372. 0
  4373. );
  4374. SendMessage (ghwndList1, LB_DELETESTRING, 0, 0);
  4375. closesocket (pSocket->Sock);
  4376. MyFree (pSocket);
  4377. }
  4378. }
  4379. }
  4380. else
  4381. {
  4382. ShowError (funcIndex, 0);
  4383. }
  4384. }
  4385. break;
  4386. }
  4387. case ws_WSACloseEvent:
  4388. {
  4389. FUNC_PARAM params[] =
  4390. {
  4391. { "hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL }
  4392. };
  4393. FUNC_PARAM_HEADER paramsHeader =
  4394. { 1, funcIndex, params, NULL };
  4395. if (LetUserMungeParams (&paramsHeader))
  4396. {
  4397. if (WSACloseEvent ((WSAEVENT) params[0].dwValue) == TRUE)
  4398. {
  4399. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4400. if ((WSAEVENT) params[0].dwValue != ghSelectedEvent)
  4401. {
  4402. //
  4403. // The user overrode the selected widget, so make sure
  4404. // we don't delete the wrong string from the list box
  4405. //
  4406. int iNumItems;
  4407. WSAEVENT hEvent;
  4408. iNumItems = (int) SendMessage(
  4409. ghwndList3,
  4410. LB_GETCOUNT,
  4411. 0,
  4412. 0
  4413. );
  4414. for (i = 0; i < iNumItems; i++)
  4415. {
  4416. hEvent = (WSAEVENT) SendMessage(
  4417. ghwndList3,
  4418. LB_GETITEMDATA,
  4419. i,
  4420. 0
  4421. );
  4422. if ((WSAEVENT) params[0].dwValue == hEvent)
  4423. {
  4424. giSelectedEventIndex = (int) i;
  4425. break;
  4426. }
  4427. }
  4428. if (i == iNumItems)
  4429. {
  4430. ShowStr(
  4431. "Strange, couldn't find that hEvent=x%x in list",
  4432. params[0].dwValue
  4433. );
  4434. break;
  4435. }
  4436. }
  4437. SendMessage(
  4438. ghwndList3,
  4439. LB_DELETESTRING,
  4440. (WPARAM) giSelectedEventIndex,
  4441. 0
  4442. );
  4443. }
  4444. else
  4445. {
  4446. ShowError (funcIndex, 0);
  4447. }
  4448. }
  4449. break;
  4450. }
  4451. case ws_WSAConnect:
  4452. {
  4453. LPBYTE pBuf = MyAlloc (5 * dwBigBufSize + 2 * sizeof (QOS));
  4454. LPSOCKADDR pSA = (LPSOCKADDR) pBuf;
  4455. LPBYTE pCallerBuf = pBuf + dwBigBufSize,
  4456. pCalleeBuf = pBuf + 2 * dwBigBufSize;
  4457. LPQOS pSQOS = (LPQOS) (pBuf + 3 * dwBigBufSize),
  4458. pGQOS = (LPQOS) (pBuf + 4 * dwBigBufSize + sizeof (QOS));
  4459. WSABUF callerData, calleeData;
  4460. FUNC_PARAM params[] =
  4461. {
  4462. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  4463. { "name", PT_PTRNOEDIT, (ULONG_PTR) pSA, pSA },
  4464. { " ->sa_family", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  4465. { " ->sa_data", PT_POINTER, (ULONG_PTR) &pSA->sa_data, &pSA->sa_data },
  4466. { "namelen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4467. { "lpCallerData", PT_PTRNOEDIT, (ULONG_PTR) &callerData, &callerData },
  4468. { " ->len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4469. { " ->buf", PT_POINTER, (ULONG_PTR) pCallerBuf, pCallerBuf },
  4470. { "lpCalleeData", PT_PTRNOEDIT, (ULONG_PTR) &calleeData, &calleeData },
  4471. { " ->len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4472. { " ->buf", PT_POINTER, (ULONG_PTR) pCalleeBuf, pCalleeBuf },
  4473. { "lpSQOS", PT_QOS, (ULONG_PTR) pSQOS, pSQOS },
  4474. { "lpGQOS", PT_QOS, (ULONG_PTR) pGQOS, pGQOS },
  4475. };
  4476. FUNC_PARAM_HEADER paramsHeader =
  4477. { 13, funcIndex, params, NULL };
  4478. if (!pBuf)
  4479. {
  4480. break;
  4481. }
  4482. ZeroMemory (pSQOS, sizeof (QOS));
  4483. pSQOS->ProviderSpecific.len = dwBigBufSize;
  4484. ZeroMemory (pGQOS, sizeof (QOS));
  4485. pGQOS->ProviderSpecific.len = dwBigBufSize;
  4486. if (LetUserMungeParams (&paramsHeader))
  4487. {
  4488. pSA->sa_family = (u_short) LOWORD(params[2].dwValue);
  4489. callerData.len = (DWORD) params[6].dwValue;
  4490. calleeData.len = (DWORD) params[9].dwValue;
  4491. if ((i = WSAConnect(
  4492. (SOCKET) params[0].dwValue,
  4493. (LPSOCKADDR) params[1].dwValue,
  4494. (int) params[4].dwValue,
  4495. (LPWSABUF) params[5].dwValue,
  4496. (LPWSABUF) params[8].dwValue,
  4497. (LPQOS) params[11].dwValue,
  4498. (LPQOS) params[12].dwValue
  4499. )) == 0)
  4500. {
  4501. LPWSABUF pCalleeData = (LPWSABUF) params[8].dwValue;
  4502. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4503. ShowStr (" lpCalleeData->len=x%x", pCalleeData->len);
  4504. if (pCalleeData->len)
  4505. {
  4506. ShowStr (" lpCalleeData->buf=x%x", pCalleeData->buf);
  4507. ShowBytes (pCalleeData->len, pCalleeData->buf, 2);
  4508. }
  4509. }
  4510. else if (i == SOCKET_ERROR)
  4511. {
  4512. ShowError (funcIndex, 0);
  4513. }
  4514. else
  4515. {
  4516. ShowUnknownError (funcIndex, i);
  4517. }
  4518. }
  4519. MyFree (pBuf);
  4520. break;
  4521. }
  4522. case ws_WSACreateEvent:
  4523. {
  4524. FUNC_PARAM_HEADER paramsHeader =
  4525. { 0, funcIndex, NULL, NULL };
  4526. if (LetUserMungeParams (&paramsHeader))
  4527. {
  4528. WSAEVENT wsaEvent;
  4529. if ((wsaEvent = WSACreateEvent ()) != WSA_INVALID_EVENT)
  4530. {
  4531. char buf[20];
  4532. LRESULT index;
  4533. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4534. ShowStr (" wsaEvent=x%x", wsaEvent);
  4535. wsprintf (buf, "hEvent=x%x", wsaEvent);
  4536. index = SendMessage(
  4537. ghwndList3,
  4538. LB_ADDSTRING,
  4539. 0,
  4540. (LPARAM) buf
  4541. );
  4542. SendMessage(
  4543. ghwndList3,
  4544. LB_SETITEMDATA,
  4545. (WPARAM) index,
  4546. (LPARAM) wsaEvent
  4547. );
  4548. }
  4549. else
  4550. {
  4551. ShowError (funcIndex, 0);
  4552. }
  4553. }
  4554. break;
  4555. }
  4556. case ws_WSADuplicateSocketA:
  4557. case ws_WSADuplicateSocketW:
  4558. {
  4559. LPWSAPROTOCOL_INFOA pProtoInfo = (gbWideStringParams ?
  4560. &gWSAProtocolInfoA :
  4561. (LPWSAPROTOCOL_INFOA) &gWSAProtocolInfoW);
  4562. FUNC_PARAM params[] =
  4563. {
  4564. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  4565. { "hTargetProcess", PT_DWORD, (ULONG_PTR) 0, NULL },
  4566. { "lpProtocolInfo", PT_PTRNOEDIT, (ULONG_PTR) pProtoInfo, pProtoInfo}
  4567. };
  4568. FUNC_PARAM_HEADER paramsHeader =
  4569. { 3, funcIndex, params, NULL };
  4570. if (LetUserMungeParams (&paramsHeader))
  4571. {
  4572. if (gbWideStringParams)
  4573. {
  4574. i = WSADuplicateSocketW(
  4575. (SOCKET) params[0].dwValue,
  4576. (DWORD) params[1].dwValue,
  4577. (LPWSAPROTOCOL_INFOW) params[2].dwValue
  4578. );
  4579. }
  4580. else
  4581. {
  4582. i = WSADuplicateSocketA(
  4583. (SOCKET) params[0].dwValue,
  4584. (DWORD) params[1].dwValue,
  4585. (LPWSAPROTOCOL_INFOA) params[2].dwValue
  4586. );
  4587. }
  4588. if (i == 0)
  4589. {
  4590. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4591. ShowStr (" lpProtocolInfo=x%x", params[2].dwValue);
  4592. ShowProtoInfo(
  4593. (LPWSAPROTOCOL_INFOA) params[2].dwValue,
  4594. 0xffffffff,
  4595. !gbWideStringParams
  4596. );
  4597. }
  4598. else if (i == SOCKET_ERROR)
  4599. {
  4600. ShowError (funcIndex, 0);
  4601. }
  4602. else
  4603. {
  4604. ShowUnknownError (funcIndex, i);
  4605. }
  4606. }
  4607. break;
  4608. }
  4609. case ws_WSAEnumNameSpaceProvidersA:
  4610. case ws_WSAEnumNameSpaceProvidersW:
  4611. {
  4612. DWORD dwSize = dwBigBufSize;
  4613. FUNC_PARAM params[] =
  4614. {
  4615. { "lpdwBufferLength", PT_POINTER, (ULONG_PTR) &dwSize, &dwSize },
  4616. { "lpNSPBuffer", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf }
  4617. };
  4618. FUNC_PARAM_HEADER paramsHeader =
  4619. { 2, funcIndex, params, NULL };
  4620. if (LetUserMungeParams (&paramsHeader))
  4621. {
  4622. if (funcIndex == ws_WSAEnumNameSpaceProvidersA)
  4623. {
  4624. i = WSAEnumNameSpaceProvidersA(
  4625. (LPDWORD) params[0].dwValue,
  4626. (LPWSANAMESPACE_INFOA) params[1].dwValue
  4627. );
  4628. }
  4629. else
  4630. {
  4631. i = WSAEnumNameSpaceProvidersW(
  4632. (LPDWORD) params[0].dwValue,
  4633. (LPWSANAMESPACE_INFOW) params[1].dwValue
  4634. );
  4635. }
  4636. if (i != SOCKET_ERROR)
  4637. {
  4638. LPWSANAMESPACE_INFOA pInfo = (LPWSANAMESPACE_INFOA)
  4639. params[1].dwValue;
  4640. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4641. ShowStr(
  4642. " *lpdwBufferLength=x%x",
  4643. *((LPDWORD) params[0].dwValue)
  4644. );
  4645. for (j = 0; j < i; j++, pInfo++)
  4646. {
  4647. char szNSInfoN[16];
  4648. wsprintf (szNSInfoN, " nsInfo[%d].", j);
  4649. ShowStr ("%sNSProviderId=", szNSInfoN);
  4650. ShowStr(
  4651. " %x %x %x %02x%02x%02x%02x%02x%02x%02x%02x",
  4652. pInfo->NSProviderId.Data1,
  4653. pInfo->NSProviderId.Data2,
  4654. pInfo->NSProviderId.Data3,
  4655. (DWORD) pInfo->NSProviderId.Data4[0],
  4656. (DWORD) pInfo->NSProviderId.Data4[1],
  4657. (DWORD) pInfo->NSProviderId.Data4[2],
  4658. (DWORD) pInfo->NSProviderId.Data4[3],
  4659. (DWORD) pInfo->NSProviderId.Data4[4],
  4660. (DWORD) pInfo->NSProviderId.Data4[5],
  4661. (DWORD) pInfo->NSProviderId.Data4[6],
  4662. (DWORD) pInfo->NSProviderId.Data4[7]
  4663. );
  4664. ShowStr(
  4665. "%sdwNameSpace=%d, %s",
  4666. szNSInfoN,
  4667. pInfo->dwNameSpace,
  4668. GetStringFromOrdinalValue(
  4669. pInfo->dwNameSpace,
  4670. aNameSpaces
  4671. )
  4672. );
  4673. ShowStr(
  4674. "%sfActive=%s",
  4675. szNSInfoN,
  4676. (pInfo->fActive ? "TRUE" : "FALSE")
  4677. );
  4678. ShowStr ("%sdwVersion=x%x", szNSInfoN, pInfo->dwVersion);
  4679. ShowStr(
  4680. (funcIndex == ws_WSAEnumNameSpaceProvidersA ?
  4681. "%slpszIdentifier=%s" : "%slpszIdentifier=%ws"),
  4682. szNSInfoN,
  4683. pInfo->lpszIdentifier
  4684. );
  4685. }
  4686. }
  4687. else
  4688. {
  4689. ShowError (funcIndex, 0);
  4690. if (WSAGetLastError() == WSAEFAULT)
  4691. {
  4692. ShowStr(
  4693. " *lpdwBufferLength=x%x",
  4694. *((LPDWORD) params[0].dwValue)
  4695. );
  4696. }
  4697. }
  4698. }
  4699. break;
  4700. }
  4701. case ws_WSAEnumNetworkEvents:
  4702. {
  4703. WSANETWORKEVENTS netEvents;
  4704. FUNC_PARAM params[] =
  4705. {
  4706. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  4707. { "hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL },
  4708. { "lpNetworkEvents", PT_PTRNOEDIT, (ULONG_PTR) &netEvents, &netEvents }
  4709. };
  4710. FUNC_PARAM_HEADER paramsHeader =
  4711. { 3, funcIndex, params, NULL };
  4712. if (LetUserMungeParams (&paramsHeader))
  4713. {
  4714. if ((i = WSAEnumNetworkEvents(
  4715. (SOCKET) params[0].dwValue,
  4716. (WSAEVENT) params[1].dwValue,
  4717. (LPWSANETWORKEVENTS) params[2].dwValue
  4718. )) == 0)
  4719. {
  4720. LPWSANETWORKEVENTS pNetEvents = (LPWSANETWORKEVENTS)
  4721. params[2].dwValue;
  4722. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4723. ShowStr (" lpNetworkEvents=x%x", pNetEvents);
  4724. ShowStr(
  4725. " ->lNetworkEvents=x%x",
  4726. pNetEvents->lNetworkEvents
  4727. );
  4728. ShowStr(
  4729. " ->iErrorCode[READ]=x%x",
  4730. pNetEvents->iErrorCode[FD_READ_BIT]
  4731. );
  4732. ShowStr(
  4733. " ->iErrorCode[WRITE]=x%x",
  4734. pNetEvents->iErrorCode[FD_WRITE_BIT]
  4735. );
  4736. ShowStr(
  4737. " ->iErrorCode[OOB]=x%x",
  4738. pNetEvents->iErrorCode[FD_OOB_BIT]
  4739. );
  4740. ShowStr(
  4741. " ->iErrorCode[ACCEPT]=x%x",
  4742. pNetEvents->iErrorCode[FD_ACCEPT_BIT]
  4743. );
  4744. ShowStr(
  4745. " ->iErrorCode[CONNECT]=x%x",
  4746. pNetEvents->iErrorCode[FD_CONNECT_BIT]
  4747. );
  4748. ShowStr(
  4749. " ->iErrorCode[CLOSE]=x%x",
  4750. pNetEvents->iErrorCode[FD_CLOSE_BIT]
  4751. );
  4752. ShowStr(
  4753. " ->iErrorCode[QOS]=x%x",
  4754. pNetEvents->iErrorCode[FD_QOS_BIT]
  4755. );
  4756. ShowStr(
  4757. " ->iErrorCode[GROUP_QOS]=x%x",
  4758. pNetEvents->iErrorCode[FD_GROUP_QOS_BIT]
  4759. );
  4760. }
  4761. else if (i == SOCKET_ERROR)
  4762. {
  4763. ShowError (funcIndex, 0);
  4764. }
  4765. else
  4766. {
  4767. ShowUnknownError (funcIndex, i);
  4768. }
  4769. }
  4770. break;
  4771. }
  4772. case ws_WSAEnumProtocolsA:
  4773. case ws_WSAEnumProtocolsW:
  4774. {
  4775. int aProtocols[32];
  4776. DWORD dwSize = dwBigBufSize;
  4777. FUNC_PARAM params[] =
  4778. {
  4779. { "lpiProtocols", PT_POINTER, (ULONG_PTR) NULL, aProtocols },
  4780. { "lpProtocolBuffer", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  4781. { "lpdwBufferLength", PT_POINTER, (ULONG_PTR) &dwSize, &dwSize }
  4782. };
  4783. FUNC_PARAM_HEADER paramsHeader =
  4784. { 3, funcIndex, params, NULL };
  4785. if (LetUserMungeParams (&paramsHeader))
  4786. {
  4787. if (funcIndex == ws_WSAEnumProtocolsA)
  4788. {
  4789. i = WSAEnumProtocolsA(
  4790. (LPINT) params[0].dwValue,
  4791. (LPWSAPROTOCOL_INFOA) params[1].dwValue,
  4792. (LPDWORD) params[2].dwValue
  4793. );
  4794. }
  4795. else
  4796. {
  4797. i = WSAEnumProtocolsW(
  4798. (LPINT) params[0].dwValue,
  4799. (LPWSAPROTOCOL_INFOW) params[1].dwValue,
  4800. (LPDWORD) params[2].dwValue
  4801. );
  4802. }
  4803. if (i != SOCKET_ERROR)
  4804. {
  4805. LPWSAPROTOCOL_INFOA pInfo = (LPWSAPROTOCOL_INFOA)
  4806. params[1].dwValue;
  4807. UpdateResults (TRUE);
  4808. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4809. ShowStr ("%s SUCCESS (result=%d)", aFuncNames[funcIndex], i);
  4810. ShowStr(
  4811. " *lpdwBufferLength=x%x",
  4812. *((LPDWORD) params[2].dwValue)
  4813. );
  4814. for (j = 0; j < i; j++)
  4815. {
  4816. if (funcIndex == ws_WSAEnumProtocolsA)
  4817. {
  4818. ShowProtoInfo (pInfo, j, TRUE);
  4819. pInfo++;
  4820. }
  4821. else
  4822. {
  4823. ShowProtoInfo (pInfo, j, FALSE);
  4824. pInfo = (LPWSAPROTOCOL_INFOA)
  4825. (((LPBYTE) pInfo) + sizeof (WSAPROTOCOL_INFOW));
  4826. }
  4827. }
  4828. UpdateResults (FALSE);
  4829. }
  4830. else
  4831. {
  4832. if (ShowError (funcIndex, 0) == WSAENOBUFS)
  4833. {
  4834. dwSize = *((LPDWORD) params[2].dwValue);
  4835. ShowStr (" *lpdwBufferLength=%d (x%lx)", dwSize, dwSize);
  4836. }
  4837. }
  4838. }
  4839. break;
  4840. }
  4841. case ws_WSAEventSelect:
  4842. {
  4843. WSAPROTOCOL_INFOW info;
  4844. FUNC_PARAM params[] =
  4845. {
  4846. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  4847. { "hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL },
  4848. { "lNetworkEvents", PT_FLAGS, (ULONG_PTR) 0, aNetworkEvents }
  4849. };
  4850. FUNC_PARAM_HEADER paramsHeader =
  4851. { 3, funcIndex, params, NULL };
  4852. if (LetUserMungeParams (&paramsHeader))
  4853. {
  4854. if ((i = WSAEventSelect(
  4855. (SOCKET) params[0].dwValue,
  4856. (WSAEVENT) params[1].dwValue,
  4857. (long) params[2].dwValue
  4858. )) == 0)
  4859. {
  4860. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4861. }
  4862. else if (i == SOCKET_ERROR)
  4863. {
  4864. ShowError (funcIndex, 0);
  4865. }
  4866. else
  4867. {
  4868. ShowUnknownError (funcIndex, i);
  4869. }
  4870. }
  4871. break;
  4872. }
  4873. case ws_WSAGetLastError:
  4874. {
  4875. FUNC_PARAM_HEADER paramsHeader =
  4876. { 0, funcIndex, NULL, NULL };
  4877. if (LetUserMungeParams (&paramsHeader))
  4878. {
  4879. WSAEVENT wsaEvent;
  4880. i = (DWORD) WSAGetLastError ();
  4881. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4882. ShowStr(
  4883. " LastError=%d, %s",
  4884. i,
  4885. GetStringFromOrdinalValue (i, aWSAErrors)
  4886. );
  4887. }
  4888. break;
  4889. }
  4890. case ws_WSAGetOverlappedResult:
  4891. {
  4892. DWORD cbTransfer = 0, dwFlags = 0;
  4893. FUNC_PARAM params[] =
  4894. {
  4895. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  4896. { "lpOverlapped", PT_DWORD, (ULONG_PTR) 0, NULL },
  4897. { "lpcbTransfer", PT_PTRNOEDIT, (ULONG_PTR) &cbTransfer, &cbTransfer },
  4898. { "fWait", PT_DWORD, (ULONG_PTR) 0, NULL },
  4899. { "lpdwFlags", PT_PTRNOEDIT, (ULONG_PTR) &dwFlags, &dwFlags }
  4900. };
  4901. FUNC_PARAM_HEADER paramsHeader =
  4902. { 5, funcIndex, params, NULL };
  4903. if (LetUserMungeParams (&paramsHeader))
  4904. {
  4905. if (WSAGetOverlappedResult(
  4906. (SOCKET) params[0].dwValue,
  4907. (LPWSAOVERLAPPED) params[1].dwValue,
  4908. (LPDWORD) params[2].dwValue,
  4909. (BOOL) params[3].dwValue,
  4910. (LPDWORD) params[4].dwValue
  4911. ) == TRUE)
  4912. {
  4913. PMYOVERLAPPED pOverlapped = (PMYOVERLAPPED) params[1].dwValue;
  4914. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4915. ShowStr(
  4916. " Overlapped %s completed",
  4917. aFuncNames[pOverlapped->FuncIndex]
  4918. );
  4919. ShowStr(
  4920. " *lpcbTransfer=x%x",
  4921. *((LPDWORD) params[2].dwValue)
  4922. );
  4923. ShowFlags(
  4924. *((LPDWORD) params[4].dwValue),
  4925. " *lpdwFlags=",
  4926. aWSASendAndRecvFlags
  4927. );
  4928. switch (pOverlapped->FuncIndex)
  4929. {
  4930. case ws_WSAIoctl:
  4931. if (*((LPDWORD) params[2].dwValue))
  4932. {
  4933. ShowStr (" lpvOUTBuffer=x%x", (pOverlapped + 1));
  4934. ShowBytes(
  4935. *((LPDWORD) params[2].dwValue),
  4936. (pOverlapped + 1),
  4937. 2
  4938. );
  4939. }
  4940. break;
  4941. case ws_WSARecv:
  4942. case ws_WSARecvFrom:
  4943. {
  4944. LPWSABUF pWSABuf = (LPWSABUF) (pOverlapped + 1);
  4945. for (i = 0; i < (int) pOverlapped->dwFuncSpecific1; i++)
  4946. {
  4947. ShowStr (" wsaBuf[0].buf=x%x", pWSABuf->buf);
  4948. ShowBytes (pWSABuf->len, pWSABuf->buf, 2);
  4949. pWSABuf++;
  4950. }
  4951. break;
  4952. }
  4953. }
  4954. MyFree (pOverlapped);
  4955. }
  4956. else
  4957. {
  4958. ShowError (funcIndex, 0);
  4959. }
  4960. }
  4961. // MyFree (pOverlapped); as appropriate
  4962. break;
  4963. }
  4964. case ws_WSAGetQOSByName:
  4965. {
  4966. LPQOS pQOS = (LPQOS) pBigBuf;
  4967. LPWSABUF pQOSName = (LPWSABUF)
  4968. MyAlloc (dwBigBufSize + sizeof (WSABUF));
  4969. FUNC_PARAM params[] =
  4970. {
  4971. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  4972. { "lpQOSName", PT_PTRNOEDIT, (ULONG_PTR) pQOSName, pQOSName },
  4973. { " ->len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  4974. { " ->buf", PT_POINTER, (ULONG_PTR) (pQOSName+1), (pQOSName+1) },
  4975. { "lpQOS", PT_PTRNOEDIT, (ULONG_PTR) pQOS, pQOS }
  4976. };
  4977. FUNC_PARAM_HEADER paramsHeader =
  4978. { 5, funcIndex, params, NULL };
  4979. if (!pQOSName)
  4980. {
  4981. break;
  4982. }
  4983. if (LetUserMungeParams (&paramsHeader))
  4984. {
  4985. pQOSName->len = (u_long) params[2].dwValue;
  4986. pQOSName->buf = (char FAR *) params[3].dwValue;
  4987. if (WSAGetQOSByName(
  4988. (SOCKET) params[0].dwValue,
  4989. (LPWSABUF) params[1].dwValue,
  4990. (LPQOS) params[4].dwValue
  4991. ) == TRUE)
  4992. {
  4993. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  4994. ShowStr (" lpQOS=x%x", pQOS);
  4995. ShowStr(
  4996. " ->SendingFlowspec.TokenRate=x%x",
  4997. pQOS->SendingFlowspec.TokenRate
  4998. );
  4999. ShowStr(
  5000. " ->SendingFlowspec.TokenBucketSize=x%x",
  5001. pQOS->SendingFlowspec.TokenBucketSize
  5002. );
  5003. ShowStr(
  5004. " ->SendingFlowspec.PeakBandwidth=x%x",
  5005. pQOS->SendingFlowspec.PeakBandwidth
  5006. );
  5007. ShowStr(
  5008. " ->SendingFlowspec.Latency=x%x",
  5009. pQOS->SendingFlowspec.Latency
  5010. );
  5011. ShowStr(
  5012. " ->SendingFlowspec.DelayVariation=x%x",
  5013. pQOS->SendingFlowspec.DelayVariation
  5014. );
  5015. ShowStr(
  5016. " ->SendingFlowspec.ServiceType=%s (x%x)",
  5017. GetStringFromOrdinalValue(
  5018. (DWORD) pQOS->SendingFlowspec.ServiceType,
  5019. aQOSServiceTypes
  5020. ),
  5021. (DWORD) pQOS->SendingFlowspec.ServiceType
  5022. );
  5023. ShowStr(
  5024. " ->SendingFlowspec.MaxSduSize=x%x",
  5025. pQOS->SendingFlowspec.MaxSduSize
  5026. );
  5027. ShowStr(
  5028. " ->SendingFlowspec.MinimumPolicedSize=x%x",
  5029. pQOS->SendingFlowspec.MinimumPolicedSize
  5030. );
  5031. ShowStr(
  5032. " ->ReceivingFlowspec.TokenRate=x%x",
  5033. pQOS->ReceivingFlowspec.TokenRate
  5034. );
  5035. ShowStr(
  5036. " ->ReceivingFlowspec.TokenBucketSize=x%x",
  5037. pQOS->ReceivingFlowspec.TokenBucketSize
  5038. );
  5039. ShowStr(
  5040. " ->ReceivingFlowspec.PeakBandwidth=x%x",
  5041. pQOS->ReceivingFlowspec.PeakBandwidth
  5042. );
  5043. ShowStr(
  5044. " ->ReceivingFlowspec.Latency=x%x",
  5045. pQOS->ReceivingFlowspec.Latency
  5046. );
  5047. ShowStr(
  5048. " ->ReceivingFlowspec.DelayVariation=x%x",
  5049. pQOS->ReceivingFlowspec.DelayVariation
  5050. );
  5051. ShowStr(
  5052. " ->ReceivingFlowspec.ServiceType=%s (x%x)",
  5053. GetStringFromOrdinalValue(
  5054. (DWORD) pQOS->ReceivingFlowspec.ServiceType,
  5055. aQOSServiceTypes
  5056. ),
  5057. (DWORD) pQOS->SendingFlowspec.ServiceType
  5058. );
  5059. ShowStr(
  5060. " ->ReceivingFlowspec.MaxSduSize=x%x",
  5061. pQOS->ReceivingFlowspec.MaxSduSize
  5062. );
  5063. ShowStr(
  5064. " ->ReceivingFlowspec.MinimumPolicedSize=x%x",
  5065. pQOS->ReceivingFlowspec.MinimumPolicedSize
  5066. );
  5067. ShowStr(
  5068. " ->ProviderSpecific.len=x%x",
  5069. pQOS->ProviderSpecific.len
  5070. );
  5071. if (pQOS->ProviderSpecific.len)
  5072. {
  5073. ShowStr(
  5074. " ->ProviderSpecific.buf=x%x",
  5075. pQOS->ProviderSpecific.buf
  5076. );
  5077. ShowBytes(
  5078. pQOS->ProviderSpecific.len,
  5079. pQOS->ProviderSpecific.buf,
  5080. 3
  5081. );
  5082. }
  5083. }
  5084. else
  5085. {
  5086. ShowError (funcIndex, 0);
  5087. }
  5088. }
  5089. MyFree (pQOSName);
  5090. break;
  5091. }
  5092. case ws_WSAGetServiceClassInfoA:
  5093. case ws_WSAGetServiceClassInfoW:
  5094. {
  5095. DWORD dwSize = dwBigBufSize;
  5096. GUID ProviderId, ServiceClassId;
  5097. FUNC_PARAM params[] =
  5098. {
  5099. { "lpProviderId", PT_POINTER, (ULONG_PTR) &ProviderId, &ProviderId },
  5100. { "lpServiceClassId", PT_POINTER, (ULONG_PTR) &ServiceClassId, &ServiceClassId },
  5101. { "lpdwBufSize", PT_POINTER, (ULONG_PTR) &dwSize, &dwSize },
  5102. { "lpServiceClassInfo", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf }
  5103. };
  5104. FUNC_PARAM_HEADER paramsHeader =
  5105. { 4, funcIndex, params, NULL };
  5106. if (LetUserMungeParams (&paramsHeader))
  5107. {
  5108. if (funcIndex == ws_WSAGetServiceClassInfoA)
  5109. {
  5110. i = WSAGetServiceClassInfoA(
  5111. (LPGUID) params[0].dwValue,
  5112. (LPGUID) params[1].dwValue,
  5113. (LPDWORD) params[2].dwValue,
  5114. (LPWSASERVICECLASSINFOA) params[3].dwValue
  5115. );
  5116. }
  5117. else
  5118. {
  5119. i = WSAGetServiceClassInfoW(
  5120. (LPGUID) params[0].dwValue,
  5121. (LPGUID) params[1].dwValue,
  5122. (LPDWORD) params[2].dwValue,
  5123. (LPWSASERVICECLASSINFOW) params[3].dwValue
  5124. );
  5125. }
  5126. if (i == 0)
  5127. {
  5128. LPWSANSCLASSINFOA pClassInfo;
  5129. LPWSASERVICECLASSINFOA pInfo = (LPWSASERVICECLASSINFOA)
  5130. params[3].dwValue;
  5131. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5132. ShowStr (" lpServiceClassInfo=x%x", pInfo);
  5133. ShowStr(
  5134. " ->lpServiceClassId=%x %x %x %02x%02x%02x%02x%02x%02x%02x%02x",
  5135. pInfo->lpServiceClassId->Data1,
  5136. pInfo->lpServiceClassId->Data2,
  5137. pInfo->lpServiceClassId->Data3,
  5138. (DWORD) pInfo->lpServiceClassId->Data4[0],
  5139. (DWORD) pInfo->lpServiceClassId->Data4[1],
  5140. (DWORD) pInfo->lpServiceClassId->Data4[2],
  5141. (DWORD) pInfo->lpServiceClassId->Data4[3],
  5142. (DWORD) pInfo->lpServiceClassId->Data4[4],
  5143. (DWORD) pInfo->lpServiceClassId->Data4[5],
  5144. (DWORD) pInfo->lpServiceClassId->Data4[6],
  5145. (DWORD) pInfo->lpServiceClassId->Data4[7]
  5146. );
  5147. ShowStr(
  5148. (funcIndex == ws_WSAGetServiceClassInfoA ?
  5149. " ->lpszServiceClassName=%s" :
  5150. " ->lpszServiceClassName=%ws"),
  5151. pInfo->lpszServiceClassName
  5152. );
  5153. ShowStr (" ->dwCount=%d", pInfo->dwCount);
  5154. pClassInfo = pInfo->lpClassInfos;
  5155. for (i = 0; i < (int) pInfo->dwCount; i++, pClassInfo++)
  5156. {
  5157. char szClassInfoN[32];
  5158. wsprintf (szClassInfoN, " ->ClassInfos[%d].", i);
  5159. ShowStr(
  5160. (funcIndex == ws_WSAGetServiceClassInfoA ?
  5161. "%s.lpszName=%s" :
  5162. "%s.lpszName=%ws"),
  5163. szClassInfoN,
  5164. pClassInfo->lpszName
  5165. );
  5166. ShowStr(
  5167. "%sdwNameSpace=%d, %s",
  5168. szClassInfoN,
  5169. pClassInfo->dwNameSpace,
  5170. GetStringFromOrdinalValue(
  5171. pClassInfo->dwNameSpace,
  5172. aNameSpaces
  5173. )
  5174. );
  5175. ShowStr(
  5176. "%sdwValueType=%d",
  5177. szClassInfoN,
  5178. pClassInfo->dwValueType
  5179. ); // supposed to be flags?
  5180. ShowStr(
  5181. "%sdwValueSize=%d",
  5182. szClassInfoN,
  5183. pClassInfo->dwValueSize
  5184. );
  5185. ShowStr(
  5186. "%slpValue=x%x",
  5187. szClassInfoN,
  5188. pClassInfo->lpValue
  5189. );
  5190. ShowBytes(
  5191. pClassInfo->dwValueSize,
  5192. pClassInfo->lpValue,
  5193. 3
  5194. );
  5195. }
  5196. }
  5197. else if (i == SOCKET_ERROR)
  5198. {
  5199. ShowError (funcIndex, 0);
  5200. }
  5201. else
  5202. {
  5203. ShowUnknownError (funcIndex, i);
  5204. }
  5205. }
  5206. break;
  5207. }
  5208. case ws_WSAGetServiceClassNameByClassIdA:
  5209. case ws_WSAGetServiceClassNameByClassIdW:
  5210. {
  5211. DWORD dwLength = dwBigBufSize;
  5212. GUID guid[2];
  5213. FUNC_PARAM params[] =
  5214. {
  5215. { "lpServiceClassId", PT_POINTER, (ULONG_PTR) guid, guid },
  5216. { "lpServiceClassName", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  5217. { "lpdwBufferLength", PT_POINTER, (ULONG_PTR) &dwLength, &dwLength }
  5218. };
  5219. FUNC_PARAM_HEADER paramsHeader =
  5220. { 3, funcIndex, params, NULL };
  5221. if (LetUserMungeParams (&paramsHeader))
  5222. {
  5223. if (funcIndex == ws_WSAGetServiceClassNameByClassIdA)
  5224. {
  5225. i = WSAGetServiceClassNameByClassIdA(
  5226. (LPGUID) params[0].dwValue,
  5227. (LPSTR) params[1].dwValue,
  5228. (LPDWORD) params[2].dwValue
  5229. );
  5230. }
  5231. else
  5232. {
  5233. i = WSAGetServiceClassNameByClassIdW(
  5234. (LPGUID) params[0].dwValue,
  5235. (LPWSTR) params[1].dwValue,
  5236. (LPDWORD) params[2].dwValue
  5237. );
  5238. }
  5239. if (i == 0)
  5240. {
  5241. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5242. ShowStr(
  5243. " *lpdwBufferLength=x%x",
  5244. *((LPDWORD) params[2].dwValue)
  5245. );
  5246. if (funcIndex == ws_WSAGetServiceClassNameByClassIdA)
  5247. {
  5248. ShowStr (" *lpServiceClassName=%s", params[1].dwValue);
  5249. }
  5250. else
  5251. {
  5252. ShowStr (" *lpServiceClassName=%ws", params[1].dwValue);
  5253. }
  5254. }
  5255. else if (i == SOCKET_ERROR)
  5256. {
  5257. ShowError (funcIndex, 0);
  5258. }
  5259. else
  5260. {
  5261. ShowUnknownError (funcIndex, i);
  5262. }
  5263. }
  5264. break;
  5265. }
  5266. case ws_WSAHtonl:
  5267. {
  5268. u_long ulNetLong;
  5269. FUNC_PARAM params[] =
  5270. {
  5271. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5272. { "hostLong", PT_DWORD, (ULONG_PTR) 0, NULL },
  5273. { "lpNetLong", PT_PTRNOEDIT, (ULONG_PTR) &ulNetLong, &ulNetLong }
  5274. };
  5275. FUNC_PARAM_HEADER paramsHeader =
  5276. { 3, funcIndex, params, NULL };
  5277. if (LetUserMungeParams (&paramsHeader))
  5278. {
  5279. if ((i = WSAHtonl(
  5280. (SOCKET) params[0].dwValue,
  5281. (u_long) params[1].dwValue,
  5282. (u_long *) params[2].dwValue
  5283. )) == 0)
  5284. {
  5285. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5286. ShowStr (" hostLong=x%x", params[1].dwValue);
  5287. ShowStr (" *lpNetLong=x%x", *((u_long *) params[2].dwValue));
  5288. }
  5289. else if (i == SOCKET_ERROR)
  5290. {
  5291. ShowError (funcIndex, 0);
  5292. }
  5293. else
  5294. {
  5295. ShowUnknownError (funcIndex, i);
  5296. }
  5297. }
  5298. break;
  5299. }
  5300. case ws_WSAHtons:
  5301. {
  5302. u_short usNetShort;
  5303. FUNC_PARAM params[] =
  5304. {
  5305. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5306. { "hostShort", PT_DWORD, (ULONG_PTR) 0, NULL },
  5307. { "lpNetShort", PT_PTRNOEDIT, (ULONG_PTR) &usNetShort, &usNetShort }
  5308. };
  5309. FUNC_PARAM_HEADER paramsHeader =
  5310. { 3, funcIndex, params, NULL };
  5311. if (LetUserMungeParams (&paramsHeader))
  5312. {
  5313. if ((i = WSAHtons(
  5314. (SOCKET) params[0].dwValue,
  5315. (u_short) params[1].dwValue,
  5316. (u_short *) params[2].dwValue
  5317. )) == 0)
  5318. {
  5319. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5320. ShowStr (" hostShort=x%x", (DWORD) LOWORD(params[1].dwValue));
  5321. ShowStr(
  5322. " *lpNetShort=x%x",
  5323. (DWORD) *((u_short *) params[2].dwValue)
  5324. );
  5325. }
  5326. else if (i == SOCKET_ERROR)
  5327. {
  5328. ShowError (funcIndex, 0);
  5329. }
  5330. else
  5331. {
  5332. ShowUnknownError (funcIndex, i);
  5333. }
  5334. }
  5335. break;
  5336. }
  5337. case ws_WSAInstallServiceClassA:
  5338. case ws_WSAInstallServiceClassW:
  5339. // case ws_WSAInstallServiceClassA:/W
  5340. break;
  5341. case ws_WSAIoctl:
  5342. {
  5343. DWORD cbBytesRet = 0;
  5344. PMYOVERLAPPED pOverlapped = MyAlloc (sizeof (MYOVERLAPPED) + dwBigBufSize);
  5345. FUNC_PARAM params[] =
  5346. {
  5347. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5348. { "dwIoControlCode", PT_ORDINAL, (ULONG_PTR) 0, aWSAIoctlCmds },
  5349. { "lpvInBuffer", PT_POINTER, (ULONG_PTR) (pOverlapped+1), (pOverlapped+1) },
  5350. { "cbInBuffer", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5351. { "lpvOutBuffer", PT_PTRNOEDIT, (ULONG_PTR) (pOverlapped+1), (pOverlapped+1) },
  5352. { "cbOutBuffer", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5353. { "lpcbBytesReturned", PT_PTRNOEDIT, (ULONG_PTR) &cbBytesRet, &cbBytesRet },
  5354. { "lpOverlapped", PT_PTRNOEDIT, (ULONG_PTR) 0, pOverlapped },
  5355. { " ->hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL },
  5356. { "lpfnCompletionProc", PT_PTRNOEDIT, (ULONG_PTR) 0, CompletionProc }
  5357. };
  5358. FUNC_PARAM_HEADER paramsHeader =
  5359. { 10, funcIndex, params, NULL };
  5360. if (!pOverlapped)
  5361. {
  5362. break;
  5363. }
  5364. if (LetUserMungeParams (&paramsHeader))
  5365. {
  5366. pOverlapped->WSAOverlapped.hEvent = (WSAEVENT) params[8].dwValue;
  5367. pOverlapped->FuncIndex = funcIndex;
  5368. pOverlapped->dwFuncSpecific1 = (DWORD) params[5].dwValue;
  5369. if ((i = WSAIoctl(
  5370. (SOCKET) params[0].dwValue,
  5371. (DWORD) params[1].dwValue,
  5372. (LPVOID) params[2].dwValue,
  5373. (DWORD) params[3].dwValue,
  5374. (LPVOID) params[4].dwValue,
  5375. (DWORD) params[5].dwValue,
  5376. (LPDWORD) params[6].dwValue,
  5377. (LPWSAOVERLAPPED) params[7].dwValue,
  5378. (LPWSAOVERLAPPED_COMPLETION_ROUTINE) params[9].dwValue
  5379. )) == 0)
  5380. {
  5381. cbBytesRet = *((LPDWORD) params[6].dwValue);
  5382. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5383. ShowStr (" bytesReturned=x%x", cbBytesRet);
  5384. ShowStr (" *lpvOutBuffer=");
  5385. ShowBytes (cbBytesRet, pOverlapped+1, 2);
  5386. }
  5387. else if (i == SOCKET_ERROR)
  5388. {
  5389. if (ShowError (funcIndex, 0) == WSA_IO_PENDING)
  5390. {
  5391. ShowStr (" lpOverlapped=x%x", params[7].dwValue);
  5392. break;
  5393. }
  5394. }
  5395. else
  5396. {
  5397. ShowUnknownError (funcIndex, i);
  5398. }
  5399. if (i == 0 && params[9].dwValue)
  5400. {
  5401. // Let CompletionProc free overlapped struct
  5402. }
  5403. else
  5404. {
  5405. MyFree (pOverlapped);
  5406. }
  5407. }
  5408. break;
  5409. }
  5410. // case ws_WSAIsBlocking: not implemented in ws 2
  5411. //
  5412. // break;
  5413. case ws_WSAJoinLeaf:
  5414. {
  5415. LPBYTE pBuf = MyAlloc (5 * dwBigBufSize + 2 * sizeof (QOS));
  5416. LPSOCKADDR pSA = (LPSOCKADDR) pBuf;
  5417. LPBYTE pCallerBuf = pBuf + dwBigBufSize,
  5418. pCalleeBuf = pBuf + 2 * dwBigBufSize;
  5419. LPQOS pSQOS = (LPQOS) (pBuf + 3 * dwBigBufSize),
  5420. pGQOS = (LPQOS) (pBuf + 4 * dwBigBufSize + sizeof (QOS));
  5421. WSABUF callerData, calleeData;
  5422. FUNC_PARAM params[] =
  5423. {
  5424. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5425. { "name", PT_PTRNOEDIT, (ULONG_PTR) pSA, pSA },
  5426. { " ->sa_family", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  5427. { " ->sa_data", PT_POINTER, (ULONG_PTR) &pSA->sa_data, &pSA->sa_data },
  5428. { "namelen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5429. { "lpCallerData", PT_PTRNOEDIT, (ULONG_PTR) &callerData, &callerData },
  5430. { " ->len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5431. { " ->buf", PT_POINTER, (ULONG_PTR) pCallerBuf, pCallerBuf },
  5432. { "lpCalleeData", PT_PTRNOEDIT, (ULONG_PTR) &calleeData, &calleeData },
  5433. { " ->len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5434. { " ->buf", PT_POINTER, (ULONG_PTR) pCalleeBuf, pCalleeBuf },
  5435. { "lpSQOS", PT_QOS, (ULONG_PTR) pSQOS, pSQOS },
  5436. { "lpGQOS", PT_QOS, (ULONG_PTR) pGQOS, pGQOS },
  5437. { "dwFlags", PT_ORDINAL, (ULONG_PTR) 0, aJLFlags }
  5438. };
  5439. FUNC_PARAM_HEADER paramsHeader =
  5440. { 14, funcIndex, params, NULL };
  5441. if (!pBuf)
  5442. {
  5443. break;
  5444. }
  5445. ZeroMemory (pSQOS, sizeof (QOS));
  5446. pSQOS->ProviderSpecific.len = dwBigBufSize;
  5447. ZeroMemory (pGQOS, sizeof (QOS));
  5448. pGQOS->ProviderSpecific.len = dwBigBufSize;
  5449. if (LetUserMungeParams (&paramsHeader))
  5450. {
  5451. pSA->sa_family = (u_short) LOWORD(params[2].dwValue);
  5452. callerData.len = (DWORD) params[6].dwValue;
  5453. calleeData.len = (DWORD) params[9].dwValue;
  5454. if ((i = (int)WSAJoinLeaf(
  5455. (SOCKET) params[0].dwValue,
  5456. (LPSOCKADDR) params[1].dwValue,
  5457. (int) params[4].dwValue,
  5458. (LPWSABUF) params[5].dwValue,
  5459. (LPWSABUF) params[8].dwValue,
  5460. (LPQOS) params[11].dwValue,
  5461. (LPQOS) params[12].dwValue,
  5462. (DWORD) params[13].dwValue
  5463. )) == 0)
  5464. {
  5465. LPWSABUF pCalleeData = (LPWSABUF) params[8].dwValue;
  5466. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5467. ShowStr (" lpCalleeData->len=x%x", pCalleeData->len);
  5468. if (pCalleeData->len)
  5469. {
  5470. ShowStr (" lpCalleeData->buf=x%x", pCalleeData->buf);
  5471. ShowBytes (pCalleeData->len, pCalleeData->buf, 2);
  5472. }
  5473. }
  5474. else if (i == SOCKET_ERROR)
  5475. {
  5476. ShowError (funcIndex, 0);
  5477. }
  5478. else
  5479. {
  5480. ShowUnknownError (funcIndex, i);
  5481. }
  5482. }
  5483. MyFree (pBuf);
  5484. break;
  5485. }
  5486. case ws_WSALookupServiceBeginA:
  5487. case ws_WSALookupServiceBeginW:
  5488. // case ws_WSALookupServiceBeginA:/W
  5489. break;
  5490. case ws_WSALookupServiceEnd:
  5491. {
  5492. u_long ulHostLong;
  5493. FUNC_PARAM params[] =
  5494. {
  5495. { "hLookup", PT_DWORD, (DWORD) 0, NULL },
  5496. };
  5497. FUNC_PARAM_HEADER paramsHeader =
  5498. { 1, funcIndex, params, NULL };
  5499. if (LetUserMungeParams (&paramsHeader))
  5500. {
  5501. if ((i = WSALookupServiceEnd ((HANDLE) params[0].dwValue)) == 0)
  5502. {
  5503. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5504. }
  5505. else if (i == SOCKET_ERROR)
  5506. {
  5507. ShowError (funcIndex, 0);
  5508. }
  5509. else
  5510. {
  5511. ShowUnknownError (funcIndex, i);
  5512. }
  5513. }
  5514. break;
  5515. }
  5516. case ws_WSALookupServiceNextA:
  5517. case ws_WSALookupServiceNextW:
  5518. {
  5519. DWORD dwLength = dwBigBufSize;
  5520. FUNC_PARAM params[] =
  5521. {
  5522. { "hLookup", PT_DWORD, (ULONG_PTR) 0, NULL },
  5523. { "dwControlFlags", PT_DWORD, (ULONG_PTR) 0, NULL }, // flags
  5524. { "lpdwBufferLength", PT_POINTER, (ULONG_PTR) &dwLength, &dwLength },
  5525. { "lpqsResults", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf }
  5526. };
  5527. FUNC_PARAM_HEADER paramsHeader =
  5528. { 4, funcIndex, params, NULL };
  5529. if (LetUserMungeParams (&paramsHeader))
  5530. {
  5531. if (funcIndex == ws_WSALookupServiceNextA)
  5532. {
  5533. i = WSALookupServiceNextA(
  5534. (HANDLE) params[0].dwValue,
  5535. (DWORD) params[1].dwValue,
  5536. (LPDWORD) params[2].dwValue,
  5537. (LPWSAQUERYSETA) params[3].dwValue
  5538. );
  5539. }
  5540. else
  5541. {
  5542. i = WSALookupServiceNextW(
  5543. (HANDLE) params[0].dwValue,
  5544. (DWORD) params[1].dwValue,
  5545. (LPDWORD) params[2].dwValue,
  5546. (LPWSAQUERYSETW) params[3].dwValue
  5547. );
  5548. }
  5549. if (i == 0)
  5550. {
  5551. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5552. // show query/set results
  5553. }
  5554. else if (i == SOCKET_ERROR)
  5555. {
  5556. ShowError (funcIndex, 0);
  5557. }
  5558. else
  5559. {
  5560. ShowUnknownError (funcIndex, i);
  5561. }
  5562. }
  5563. break;
  5564. }
  5565. case ws_WSANtohl:
  5566. {
  5567. u_long ulHostLong;
  5568. FUNC_PARAM params[] =
  5569. {
  5570. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5571. { "netLong", PT_DWORD, (ULONG_PTR) 0, NULL },
  5572. { "lpHostLong", PT_PTRNOEDIT, (ULONG_PTR) &ulHostLong, &ulHostLong }
  5573. };
  5574. FUNC_PARAM_HEADER paramsHeader =
  5575. { 3, funcIndex, params, NULL };
  5576. if (LetUserMungeParams (&paramsHeader))
  5577. {
  5578. if ((i = WSANtohl(
  5579. (SOCKET) params[0].dwValue,
  5580. (u_long) params[1].dwValue,
  5581. (u_long *) params[2].dwValue
  5582. )) == 0)
  5583. {
  5584. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5585. ShowStr (" netLong=x%x", params[1].dwValue);
  5586. ShowStr (" *lpHostLong=x%x", *((u_long *) params[2].dwValue));
  5587. }
  5588. else if (i == SOCKET_ERROR)
  5589. {
  5590. ShowError (funcIndex, 0);
  5591. }
  5592. else
  5593. {
  5594. ShowUnknownError (funcIndex, i);
  5595. }
  5596. }
  5597. break;
  5598. }
  5599. case ws_WSANtohs:
  5600. {
  5601. u_short usHostShort;
  5602. FUNC_PARAM params[] =
  5603. {
  5604. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5605. { "netShort", PT_DWORD, (ULONG_PTR) 0, NULL },
  5606. { "lpHostShort", PT_PTRNOEDIT, (ULONG_PTR) &usHostShort, &usHostShort }
  5607. };
  5608. FUNC_PARAM_HEADER paramsHeader =
  5609. { 3, funcIndex, params, NULL };
  5610. if (LetUserMungeParams (&paramsHeader))
  5611. {
  5612. if ((i = WSANtohs(
  5613. (SOCKET) params[0].dwValue,
  5614. (u_short) params[1].dwValue,
  5615. (u_short *) params[2].dwValue
  5616. )) == 0)
  5617. {
  5618. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5619. ShowStr (" netShort=x%x", (DWORD) LOWORD(params[1].dwValue));
  5620. ShowStr(
  5621. " *lpHostShort=x%x",
  5622. (DWORD) *((u_short *) params[2].dwValue)
  5623. );
  5624. }
  5625. else if (i == SOCKET_ERROR)
  5626. {
  5627. ShowError (funcIndex, 0);
  5628. }
  5629. else
  5630. {
  5631. ShowUnknownError (funcIndex, i);
  5632. }
  5633. }
  5634. break;
  5635. }
  5636. case ws_WSARecv:
  5637. {
  5638. PMYOVERLAPPED pOverlapped = MyAlloc(
  5639. sizeof (MYOVERLAPPED) +
  5640. 2 * sizeof (WSABUF) +
  5641. 2 * dwBigBufSize
  5642. );
  5643. LPWSABUF lpBuffers = (LPWSABUF) (pOverlapped + 1);
  5644. LPBYTE pBuf0 = (LPBYTE) (lpBuffers + 2),
  5645. pBuf1 = pBuf0 + dwBigBufSize;
  5646. DWORD dwNumBytesRecvd, dwFlags;
  5647. FUNC_PARAM params[] =
  5648. {
  5649. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5650. { "lpBuffers", PT_PTRNOEDIT, (ULONG_PTR) lpBuffers, lpBuffers },
  5651. { " buf[0].len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5652. { " buf[0].buf", PT_PTRNOEDIT, (ULONG_PTR) pBuf0, pBuf0 },
  5653. { " buf[1].len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5654. { " buf[1].buf", PT_PTRNOEDIT, (ULONG_PTR) pBuf1, pBuf1 },
  5655. { "dwBufferCount", PT_DWORD, (ULONG_PTR) 2, NULL },
  5656. { "lpdwNumBytesRecvd", PT_PTRNOEDIT, (ULONG_PTR) &dwNumBytesRecvd, &dwNumBytesRecvd },
  5657. { "lpdwFlags", PT_POINTER, (ULONG_PTR) &dwFlags, &dwFlags },
  5658. { " ->dwFlags", PT_FLAGS, (ULONG_PTR) gdwDefRecvFlags, aWSARecvFlags },
  5659. { "lpOverlapped", PT_PTRNOEDIT, (ULONG_PTR) 0, pOverlapped },
  5660. { " ->hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL },
  5661. { "lpfnCompletionProc", PT_PTRNOEDIT, (ULONG_PTR) 0, CompletionProc }
  5662. };
  5663. FUNC_PARAM_HEADER paramsHeader =
  5664. { 13, funcIndex, params, NULL };
  5665. if (!pOverlapped)
  5666. {
  5667. break;
  5668. }
  5669. if (LetUserMungeParams (&paramsHeader))
  5670. {
  5671. pOverlapped->WSAOverlapped.hEvent = (WSAEVENT) params[10].dwValue;
  5672. pOverlapped->FuncIndex = funcIndex;
  5673. pOverlapped->dwFuncSpecific1 = (DWORD) params[6].dwValue; // bufCount
  5674. dwFlags = (DWORD) params[9].dwValue;
  5675. if ((i = WSARecv(
  5676. (SOCKET) params[0].dwValue,
  5677. (LPWSABUF) params[1].dwValue,
  5678. (DWORD) params[6].dwValue,
  5679. (LPDWORD) params[7].dwValue,
  5680. (LPDWORD) params[8].dwValue,
  5681. (LPWSAOVERLAPPED) params[10].dwValue,
  5682. (LPWSAOVERLAPPED_COMPLETION_ROUTINE) params[12].dwValue
  5683. )) == 0)
  5684. {
  5685. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5686. ShowStr(
  5687. " *lpdwNumBytesRecvd=x%x",
  5688. *((LPDWORD) params[7].dwValue)
  5689. );
  5690. ShowFlags(
  5691. *((LPDWORD) params[8].dwValue),
  5692. " *lpdwFlags",
  5693. aWSASendFlags
  5694. );
  5695. }
  5696. else if (i == SOCKET_ERROR)
  5697. {
  5698. if (ShowError (funcIndex, 0) == WSA_IO_PENDING)
  5699. {
  5700. ShowStr (" lpOverlapped=x%x", params[10].dwValue);
  5701. break;
  5702. }
  5703. }
  5704. else
  5705. {
  5706. ShowUnknownError (funcIndex, i);
  5707. }
  5708. }
  5709. MyFree (pOverlapped);
  5710. break;
  5711. }
  5712. case ws_WSARecvDisconnect:
  5713. {
  5714. FUNC_PARAM params[] =
  5715. {
  5716. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5717. { "lpInboundDisconnectData", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  5718. { " ->len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5719. { " ->buf", PT_POINTER, (ULONG_PTR) (pBigBuf + sizeof (u_long)), (pBigBuf + sizeof (u_long)) }
  5720. };
  5721. FUNC_PARAM_HEADER paramsHeader =
  5722. { 4, funcIndex, params, NULL };
  5723. if (LetUserMungeParams (&paramsHeader))
  5724. {
  5725. if ((i = WSARecvDisconnect(
  5726. (SOCKET) params[0].dwValue,
  5727. (LPWSABUF) params[1].dwValue
  5728. )) == 0)
  5729. {
  5730. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5731. }
  5732. else if (i == SOCKET_ERROR)
  5733. {
  5734. ShowError (funcIndex, 0);
  5735. }
  5736. else
  5737. {
  5738. ShowUnknownError (funcIndex, i);
  5739. }
  5740. }
  5741. break;
  5742. }
  5743. case ws_WSARecvFrom:
  5744. {
  5745. PMYOVERLAPPED pOverlapped = MyAlloc(
  5746. sizeof (MYOVERLAPPED) +
  5747. 2 * sizeof (WSABUF) +
  5748. 2 * dwBigBufSize
  5749. );
  5750. LPWSABUF lpBuffers = (LPWSABUF) (pOverlapped + 1);
  5751. LPBYTE pBuf0 = (LPBYTE) (lpBuffers + 2),
  5752. pBuf1 = pBuf0 + dwBigBufSize;
  5753. DWORD dwNumBytesSent, dwFlags;
  5754. LPSOCKADDR psa = (LPSOCKADDR) pBigBuf;
  5755. FUNC_PARAM params[] =
  5756. {
  5757. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5758. { "lpBuffers", PT_PTRNOEDIT, (ULONG_PTR) lpBuffers, lpBuffers },
  5759. { " buf[0].len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5760. { " buf[0].buf", PT_PTRNOEDIT, (ULONG_PTR) pBuf0, pBuf0 },
  5761. { " buf[1].len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5762. { " buf[1].buf", PT_PTRNOEDIT, (ULONG_PTR) pBuf1, pBuf1 },
  5763. { "dwBufferCount", PT_DWORD, (ULONG_PTR) 2, NULL },
  5764. { "lpdwNumBytesRecvd", PT_PTRNOEDIT, (ULONG_PTR) &dwNumBytesSent, &dwNumBytesSent },
  5765. { "lpdwFlags", PT_POINTER, (ULONG_PTR) &dwFlags, &dwFlags },
  5766. { " ->dwFlags", PT_FLAGS, (ULONG_PTR) gdwDefRecvFlags, aWSARecvFlags },
  5767. { "lpTo", PT_PTRNOEDIT, (ULONG_PTR) psa, psa },
  5768. { " ->sa_family", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  5769. { " ->sa_data", PT_POINTER, (ULONG_PTR) psa->sa_data, psa->sa_data },
  5770. { "iToLen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5771. { "lpOverlapped", PT_PTRNOEDIT, (ULONG_PTR) 0, pOverlapped },
  5772. { " ->hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL },
  5773. { "lpfnCompletionProc", PT_PTRNOEDIT, (ULONG_PTR) 0, CompletionProc }
  5774. };
  5775. FUNC_PARAM_HEADER paramsHeader =
  5776. { 17, funcIndex, params, NULL };
  5777. if (!pOverlapped)
  5778. {
  5779. break;
  5780. }
  5781. if (LetUserMungeParams (&paramsHeader))
  5782. {
  5783. pOverlapped->WSAOverlapped.hEvent = (WSAEVENT) params[14].dwValue;
  5784. pOverlapped->FuncIndex = funcIndex;
  5785. pOverlapped->dwFuncSpecific1 = (DWORD) params[6].dwValue; // bufCount
  5786. dwFlags = (DWORD) params[9].dwValue;
  5787. psa->sa_family = (u_short) LOWORD(params[11].dwValue);
  5788. if ((i = WSASendTo(
  5789. (SOCKET) params[0].dwValue,
  5790. (LPWSABUF) params[1].dwValue,
  5791. (DWORD) params[6].dwValue,
  5792. (LPDWORD) params[7].dwValue,
  5793. (DWORD) params[8].dwValue,
  5794. (LPSOCKADDR) params[10].dwValue,
  5795. (int) params[13].dwValue,
  5796. (LPWSAOVERLAPPED) params[14].dwValue,
  5797. (LPWSAOVERLAPPED_COMPLETION_ROUTINE) params[16].dwValue
  5798. )) == 0)
  5799. {
  5800. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5801. ShowStr(
  5802. " *lpdwNumBytesSent=x%x",
  5803. *((LPDWORD) params[7].dwValue)
  5804. );
  5805. ShowFlags(
  5806. *((LPDWORD) params[8].dwValue),
  5807. " *lpdwNumBytesSent=x%x",
  5808. aWSAFlags
  5809. );
  5810. }
  5811. else if (i == SOCKET_ERROR)
  5812. {
  5813. if (ShowError (funcIndex, 0) == WSA_IO_PENDING)
  5814. {
  5815. ShowStr (" lpOverlapped=x%x", params[14].dwValue);
  5816. break;
  5817. }
  5818. }
  5819. else
  5820. {
  5821. ShowUnknownError (funcIndex, i);
  5822. }
  5823. }
  5824. MyFree (pOverlapped);
  5825. break;
  5826. }
  5827. case ws_WSARemoveServiceClass:
  5828. {
  5829. GUID guid[2]; // add padding to keep dumb user from hosing stack
  5830. FUNC_PARAM params[] =
  5831. {
  5832. { "lpServiceClassId", PT_POINTER, (ULONG_PTR) guid, guid },
  5833. };
  5834. FUNC_PARAM_HEADER paramsHeader =
  5835. { 1, funcIndex, params, NULL };
  5836. if (LetUserMungeParams (&paramsHeader))
  5837. {
  5838. if ((i = WSARemoveServiceClass ((LPGUID) params[0].dwValue)) == 0)
  5839. {
  5840. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5841. }
  5842. else if (i == SOCKET_ERROR)
  5843. {
  5844. ShowError (funcIndex, 0);
  5845. }
  5846. else
  5847. {
  5848. ShowUnknownError (funcIndex, i);
  5849. }
  5850. }
  5851. break;
  5852. }
  5853. case ws_WSAResetEvent:
  5854. {
  5855. FUNC_PARAM params[] =
  5856. {
  5857. { "hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL }
  5858. };
  5859. FUNC_PARAM_HEADER paramsHeader =
  5860. { 1, funcIndex, params, NULL };
  5861. if (LetUserMungeParams (&paramsHeader))
  5862. {
  5863. if (WSAResetEvent ((WSAEVENT) params[0].dwValue) == TRUE)
  5864. {
  5865. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5866. }
  5867. else
  5868. {
  5869. ShowError (funcIndex, 0);
  5870. }
  5871. }
  5872. break;
  5873. }
  5874. case ws_WSASend:
  5875. {
  5876. PMYOVERLAPPED pOverlapped = MyAlloc(
  5877. sizeof (MYOVERLAPPED) +
  5878. 2 * sizeof (WSABUF) +
  5879. 2 * dwBigBufSize
  5880. );
  5881. LPWSABUF lpBuffers = (LPWSABUF) (pOverlapped + 1);
  5882. LPBYTE pBuf0 = (LPBYTE) (lpBuffers + 2),
  5883. pBuf1 = pBuf0 + dwBigBufSize;
  5884. DWORD dwNumBytesSent;
  5885. FUNC_PARAM params[] =
  5886. {
  5887. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5888. { "lpBuffers", PT_PTRNOEDIT, (ULONG_PTR) lpBuffers, lpBuffers },
  5889. { " buf[0].len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5890. { " buf[0].buf", PT_POINTER, (ULONG_PTR) pBuf0, pBuf0 },
  5891. { " buf[1].len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5892. { " buf[1].buf", PT_POINTER, (ULONG_PTR) pBuf1, pBuf1 },
  5893. { "dwBufferCount", PT_DWORD, (ULONG_PTR) 2, NULL },
  5894. { "lpdwNumBytesSent", PT_PTRNOEDIT, (ULONG_PTR) &dwNumBytesSent, &dwNumBytesSent },
  5895. { "dwFlags", PT_FLAGS, (ULONG_PTR) gdwDefSendFlags, aWSASendFlags },
  5896. { "lpOverlapped", PT_PTRNOEDIT, (ULONG_PTR) 0, pOverlapped },
  5897. { " ->hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL },
  5898. { "lpfnCompletionProc", PT_PTRNOEDIT, (ULONG_PTR) 0, CompletionProc }
  5899. };
  5900. FUNC_PARAM_HEADER paramsHeader =
  5901. { 12, funcIndex, params, NULL };
  5902. if (!pOverlapped)
  5903. {
  5904. break;
  5905. }
  5906. if (LetUserMungeParams (&paramsHeader))
  5907. {
  5908. pOverlapped->WSAOverlapped.hEvent = (WSAEVENT) params[10].dwValue;
  5909. pOverlapped->FuncIndex = funcIndex;
  5910. pOverlapped->dwFuncSpecific1 = (DWORD) params[6].dwValue; // bufCount
  5911. if ((i = WSASend(
  5912. (SOCKET) params[0].dwValue,
  5913. (LPWSABUF) params[1].dwValue,
  5914. (DWORD) params[6].dwValue,
  5915. (LPDWORD) params[7].dwValue,
  5916. (DWORD) params[8].dwValue,
  5917. (LPWSAOVERLAPPED) params[9].dwValue,
  5918. (LPWSAOVERLAPPED_COMPLETION_ROUTINE) params[11].dwValue
  5919. )) == 0)
  5920. {
  5921. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5922. ShowStr(
  5923. " *lpdwNumBytesSent=x%x",
  5924. *((LPDWORD) params[7].dwValue)
  5925. );
  5926. }
  5927. else if (i == SOCKET_ERROR)
  5928. {
  5929. if (ShowError (funcIndex, 0) == WSA_IO_PENDING)
  5930. {
  5931. ShowStr (" lpOverlapped=x%x", params[9].dwValue);
  5932. break;
  5933. }
  5934. }
  5935. else
  5936. {
  5937. ShowUnknownError (funcIndex, i);
  5938. }
  5939. }
  5940. MyFree (pOverlapped);
  5941. break;
  5942. }
  5943. case ws_WSASendDisconnect:
  5944. {
  5945. FUNC_PARAM params[] =
  5946. {
  5947. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5948. { "lpOutboundDisconnectData", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  5949. { " ->len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5950. { " ->buf", PT_POINTER, (ULONG_PTR) (pBigBuf + sizeof (u_long)), (pBigBuf + sizeof (u_long)) }
  5951. };
  5952. FUNC_PARAM_HEADER paramsHeader =
  5953. { 4, funcIndex, params, NULL };
  5954. if (LetUserMungeParams (&paramsHeader))
  5955. {
  5956. if ((i = WSASendDisconnect(
  5957. (SOCKET) params[0].dwValue,
  5958. (LPWSABUF) params[1].dwValue
  5959. )) == 0)
  5960. {
  5961. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  5962. }
  5963. else if (i == SOCKET_ERROR)
  5964. {
  5965. ShowError (funcIndex, 0);
  5966. }
  5967. else
  5968. {
  5969. ShowUnknownError (funcIndex, i);
  5970. }
  5971. }
  5972. break;
  5973. }
  5974. case ws_WSASendTo:
  5975. {
  5976. PMYOVERLAPPED pOverlapped = MyAlloc(
  5977. sizeof (MYOVERLAPPED) +
  5978. 2 * sizeof (WSABUF) +
  5979. 2 * dwBigBufSize
  5980. );
  5981. LPWSABUF lpBuffers = (LPWSABUF) (pOverlapped + 1);
  5982. LPBYTE pBuf0 = (LPBYTE) (lpBuffers + 2),
  5983. pBuf1 = pBuf0 + dwBigBufSize;
  5984. DWORD dwNumBytesSent;
  5985. LPSOCKADDR psa = (LPSOCKADDR) pBigBuf;
  5986. FUNC_PARAM params[] =
  5987. {
  5988. { gszSocket, PT_DWORD, (ULONG_PTR) gpSelectedSocket->Sock, NULL },
  5989. { "lpBuffers", PT_PTRNOEDIT, (ULONG_PTR) lpBuffers, lpBuffers },
  5990. { " buf[0].len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5991. { " buf[0].buf", PT_POINTER, (ULONG_PTR) pBuf0, pBuf0 },
  5992. { " buf[1].len", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  5993. { " buf[1].buf", PT_POINTER, (ULONG_PTR) pBuf1, pBuf1 },
  5994. { "dwBufferCount", PT_DWORD, (ULONG_PTR) 2, NULL },
  5995. { "lpdwNumBytesSent", PT_PTRNOEDIT, (ULONG_PTR) &dwNumBytesSent, &dwNumBytesSent },
  5996. { "dwFlags", PT_FLAGS, (ULONG_PTR) gdwDefSendFlags, aWSASendFlags },
  5997. { "lpTo", PT_PTRNOEDIT, (ULONG_PTR) psa, psa },
  5998. { " ->sa_family", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  5999. { " ->sa_data", PT_POINTER, (ULONG_PTR) psa->sa_data, psa->sa_data },
  6000. { "iToLen", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL },
  6001. { "lpOverlapped", PT_PTRNOEDIT, (ULONG_PTR) 0, pOverlapped },
  6002. { " ->hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL },
  6003. { "lpfnCompletionProc", PT_PTRNOEDIT, (ULONG_PTR) 0, CompletionProc }
  6004. };
  6005. FUNC_PARAM_HEADER paramsHeader =
  6006. { 16, funcIndex, params, NULL };
  6007. if (!pOverlapped)
  6008. {
  6009. break;
  6010. }
  6011. if (LetUserMungeParams (&paramsHeader))
  6012. {
  6013. pOverlapped->WSAOverlapped.hEvent = (WSAEVENT) params[14].dwValue;
  6014. pOverlapped->FuncIndex = funcIndex;
  6015. pOverlapped->dwFuncSpecific1 = (DWORD) params[6].dwValue; // bufCount
  6016. psa->sa_family = (u_short) LOWORD(params[10].dwValue);
  6017. if ((i = WSASendTo(
  6018. (SOCKET) params[0].dwValue,
  6019. (LPWSABUF) params[1].dwValue,
  6020. (DWORD) params[6].dwValue,
  6021. (LPDWORD) params[7].dwValue,
  6022. (DWORD) params[8].dwValue,
  6023. (LPSOCKADDR) params[9].dwValue,
  6024. (int) params[12].dwValue,
  6025. (LPWSAOVERLAPPED) params[13].dwValue,
  6026. (LPWSAOVERLAPPED_COMPLETION_ROUTINE) params[15].dwValue
  6027. )) == 0)
  6028. {
  6029. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6030. ShowStr(
  6031. " *lpdwNumBytesSent=x%x",
  6032. *((LPDWORD) params[7].dwValue)
  6033. );
  6034. }
  6035. else if (i == SOCKET_ERROR)
  6036. {
  6037. if (ShowError (funcIndex, 0) == WSA_IO_PENDING)
  6038. {
  6039. ShowStr (" lpOverlapped=x%x", params[13].dwValue);
  6040. break;
  6041. }
  6042. }
  6043. else
  6044. {
  6045. ShowUnknownError (funcIndex, i);
  6046. }
  6047. }
  6048. MyFree (pOverlapped);
  6049. break;
  6050. }
  6051. // case ws_WSASetBlockingHook: not implemented in ws 2
  6052. //
  6053. // break;
  6054. case ws_WSASetEvent:
  6055. {
  6056. FUNC_PARAM params[] =
  6057. {
  6058. { "hEvent", PT_DWORD, (ULONG_PTR) ghSelectedEvent, NULL }
  6059. };
  6060. FUNC_PARAM_HEADER paramsHeader =
  6061. { 1, funcIndex, params, NULL };
  6062. if (LetUserMungeParams (&paramsHeader))
  6063. {
  6064. if (WSASetEvent ((WSAEVENT) params[0].dwValue) == TRUE)
  6065. {
  6066. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6067. }
  6068. else
  6069. {
  6070. ShowError (funcIndex, 0);
  6071. }
  6072. }
  6073. break;
  6074. }
  6075. case ws_WSASetLastError:
  6076. {
  6077. FUNC_PARAM params[] =
  6078. {
  6079. { "iError", PT_DWORD, (ULONG_PTR) 0, NULL }
  6080. };
  6081. FUNC_PARAM_HEADER paramsHeader =
  6082. { 1, funcIndex, params, NULL };
  6083. if (LetUserMungeParams (&paramsHeader))
  6084. {
  6085. WSASetLastError ((int) params[0].dwValue);
  6086. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6087. }
  6088. break;
  6089. }
  6090. case ws_WSASetServiceA:
  6091. case ws_WSASetServiceW:
  6092. // case ws_WSASetServiceA:/W
  6093. break;
  6094. case ws_WSASocketA:
  6095. case ws_WSASocketW:
  6096. {
  6097. FUNC_PARAM params[] =
  6098. {
  6099. { "address family", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  6100. { "socket type", PT_ORDINAL, (ULONG_PTR) gdwDefSocketType, aSocketTypes },
  6101. { "protocol", PT_DWORD, (ULONG_PTR) gdwDefProtocol, aProtocols },
  6102. { "protocol info", PT_WSAPROTOCOLINFO, 0, (gbWideStringParams ?
  6103. (LPVOID) &gWSAProtocolInfoW : (LPVOID) &gWSAProtocolInfoA) },
  6104. { "group", PT_DWORD, (ULONG_PTR) 0, NULL },
  6105. { "flags", PT_FLAGS, (ULONG_PTR) gdwDefWSASocketFlags, aWSAFlags },
  6106. };
  6107. FUNC_PARAM_HEADER paramsHeader =
  6108. { 6, funcIndex, params, NULL };
  6109. if (LetUserMungeParams (&paramsHeader))
  6110. {
  6111. PMYSOCKET pSocket;
  6112. if (!(pSocket = MyAlloc (sizeof (MYSOCKET))))
  6113. {
  6114. break;
  6115. }
  6116. if (gbWideStringParams)
  6117. {
  6118. pSocket->Sock = WSASocketW(
  6119. (int) params[0].dwValue,
  6120. (int) params[1].dwValue,
  6121. (int) params[2].dwValue,
  6122. (LPWSAPROTOCOL_INFOW) params[3].dwValue,
  6123. (GROUP) params[4].dwValue,
  6124. (DWORD) params[5].dwValue
  6125. );
  6126. }
  6127. else
  6128. {
  6129. pSocket->Sock = WSASocketA(
  6130. (int) params[0].dwValue,
  6131. (int) params[1].dwValue,
  6132. (int) params[2].dwValue,
  6133. (LPWSAPROTOCOL_INFOA) params[3].dwValue,
  6134. (GROUP) params[4].dwValue,
  6135. (DWORD) params[5].dwValue
  6136. );
  6137. }
  6138. if (pSocket->Sock != INVALID_SOCKET)
  6139. {
  6140. char buf[128];
  6141. LRESULT index;
  6142. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6143. pSocket->bWSASocket = TRUE;
  6144. pSocket->dwAddressFamily = (DWORD) params[0].dwValue;
  6145. pSocket->dwSocketType = (DWORD) params[1].dwValue;
  6146. pSocket->dwFlags = (DWORD) params[5].dwValue;
  6147. wsprintf(
  6148. buf,
  6149. "WSASocket=x%x (%s %s%s)",
  6150. pSocket->Sock,
  6151. GetStringFromOrdinalValue (pSocket->dwAddressFamily, aAddressFamilies),
  6152. GetStringFromOrdinalValue (pSocket->dwSocketType, aSocketTypes),
  6153. (pSocket->dwFlags & WSA_FLAG_OVERLAPPED ?
  6154. " OVERLAPPED" : "")
  6155. );
  6156. index = SendMessage(
  6157. ghwndList1,
  6158. LB_ADDSTRING,
  6159. 0,
  6160. (LPARAM) buf
  6161. );
  6162. SendMessage(
  6163. ghwndList1,
  6164. LB_SETITEMDATA,
  6165. index,
  6166. (LPARAM) pSocket
  6167. );
  6168. }
  6169. else
  6170. {
  6171. ShowError (funcIndex, 0);
  6172. MyFree (pSocket);
  6173. }
  6174. }
  6175. break;
  6176. }
  6177. case ws_WSAStartup:
  6178. {
  6179. WSADATA wsaData;
  6180. FUNC_PARAM params[] =
  6181. {
  6182. { "wVersionRequested", PT_DWORD, (ULONG_PTR) 0x101, NULL },
  6183. { "lpWSAData", PT_PTRNOEDIT, (ULONG_PTR) &wsaData, &wsaData },
  6184. };
  6185. FUNC_PARAM_HEADER paramsHeader =
  6186. { 2, funcIndex, params, NULL };
  6187. if (LetUserMungeParams (&paramsHeader))
  6188. {
  6189. if ((i = WSAStartup(
  6190. LOWORD(params[0].dwValue),
  6191. (LPWSADATA) params[1].dwValue
  6192. )) == 0)
  6193. {
  6194. char szButtonText[32];
  6195. LPWSADATA pWSAData = (LPWSADATA) params[1].dwValue;
  6196. wsprintf (szButtonText, "Startup (%d)", ++giCurrNumStartups);
  6197. SetDlgItemText (ghwndMain, IDC_BUTTON1, szButtonText);
  6198. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6199. ShowStr (" wVersion=x%x", (DWORD) pWSAData->wVersion);
  6200. ShowStr (" wHighVersion=x%x", (DWORD) pWSAData->wHighVersion);
  6201. ShowStr (" szDescription=%s", pWSAData->szDescription);
  6202. ShowStr (" szSystemStatus=%s", pWSAData->szSystemStatus);
  6203. ShowStr (" iMaxSockets=%d", (DWORD) pWSAData->iMaxSockets);
  6204. ShowStr (" iMaxUdpDg=%d", (DWORD) pWSAData->iMaxUdpDg);
  6205. // ignored for 2.0+ ShowStr (" ", pWSAData->lpVendorInfo);
  6206. }
  6207. else
  6208. {
  6209. ShowError (funcIndex, i);
  6210. }
  6211. }
  6212. break;
  6213. }
  6214. case ws_WSAStringToAddressA:
  6215. case ws_WSAStringToAddressW:
  6216. {
  6217. INT iAddrLen = (INT) dwBigBufSize;
  6218. char szAddrString[MAX_STRING_PARAM_SIZE] = "";
  6219. LPWSAPROTOCOL_INFOA pInfo = (funcIndex == ws_WSAStringToAddressA ?
  6220. &gWSAProtocolInfoA :
  6221. (LPWSAPROTOCOL_INFOA) &gWSAProtocolInfoW);
  6222. FUNC_PARAM params[] =
  6223. {
  6224. { "lpszAddressString", PT_STRING, (ULONG_PTR) szAddrString, szAddrString },
  6225. { "iAddressFamily", PT_ORDINAL, (ULONG_PTR) gdwDefAddrFamily, aAddressFamilies },
  6226. { "lpProtocolInfo", PT_WSAPROTOCOLINFO, (ULONG_PTR) pInfo, pInfo },
  6227. { "lpAddress", PT_POINTER, (ULONG_PTR) pBigBuf, pBigBuf },
  6228. { "lpAddressLength", PT_POINTER, (ULONG_PTR) &iAddrLen, &iAddrLen }
  6229. };
  6230. FUNC_PARAM_HEADER paramsHeader =
  6231. { 5, funcIndex, params, NULL };
  6232. if (LetUserMungeParams (&paramsHeader))
  6233. {
  6234. if (funcIndex == ws_WSAStringToAddressA)
  6235. {
  6236. i = WSAStringToAddressA(
  6237. (LPSTR) params[0].dwValue,
  6238. (INT) params[1].dwValue,
  6239. (LPWSAPROTOCOL_INFOA) params[2].dwValue,
  6240. (LPSOCKADDR) params[3].dwValue,
  6241. (LPINT) params[4].dwValue
  6242. );
  6243. }
  6244. else
  6245. {
  6246. i = WSAStringToAddressW(
  6247. (LPWSTR) params[0].dwValue,
  6248. (INT) params[1].dwValue,
  6249. (LPWSAPROTOCOL_INFOW) params[2].dwValue,
  6250. (LPSOCKADDR) params[3].dwValue,
  6251. (LPINT) params[4].dwValue
  6252. );
  6253. }
  6254. if (i == 0)
  6255. {
  6256. LPSOCKADDR pSockAddr = (LPSOCKADDR) params[3].dwValue;
  6257. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6258. ShowStr(
  6259. " *lpAddressLength=x%x",
  6260. *((LPINT) params[4].dwValue)
  6261. );
  6262. ShowStr (" lpAddress=x%x", params[3].dwValue);
  6263. ShowStr(
  6264. " ->sa_family=%d, %s",
  6265. (DWORD) pSockAddr->sa_family,
  6266. GetStringFromOrdinalValue(
  6267. (DWORD) pSockAddr->sa_family,
  6268. aAddressFamilies
  6269. )
  6270. );
  6271. ShowStr (" ->sa_data=");
  6272. ShowBytes (14, pSockAddr->sa_data, 3);
  6273. }
  6274. else if (i == SOCKET_ERROR)
  6275. {
  6276. ShowError (funcIndex, 0);
  6277. }
  6278. else
  6279. {
  6280. ShowUnknownError (funcIndex, i);
  6281. }
  6282. }
  6283. break;
  6284. }
  6285. // case ws_WSAUnhookBlockingHook:
  6286. //
  6287. // break;
  6288. case ws_WSAWaitForMultipleEvents:
  6289. // case ws_WSAWaitForMultipleEvents:
  6290. break;
  6291. case ws_WSCEnumProtocols:
  6292. {
  6293. int aProtocols[32], iErrno;
  6294. DWORD dwSize = dwBigBufSize;
  6295. FUNC_PARAM params[] =
  6296. {
  6297. { "lpiProtocols", PT_POINTER, (ULONG_PTR) NULL, aProtocols },
  6298. { "lpProtocolBuffer", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  6299. { "lpdwBufferLength", PT_POINTER, (ULONG_PTR) &dwSize, &dwSize },
  6300. { "lpErrno", PT_POINTER, (ULONG_PTR) &iErrno, &iErrno }
  6301. };
  6302. FUNC_PARAM_HEADER paramsHeader =
  6303. { 4, funcIndex, params, NULL };
  6304. if (LetUserMungeParams (&paramsHeader))
  6305. {
  6306. i = WSCEnumProtocols(
  6307. (LPINT) params[0].dwValue,
  6308. (LPWSAPROTOCOL_INFOW) params[1].dwValue,
  6309. (LPDWORD) params[2].dwValue,
  6310. (LPINT) params[3].dwValue
  6311. );
  6312. if (i != SOCKET_ERROR)
  6313. {
  6314. LPWSAPROTOCOL_INFOW pInfo = (LPWSAPROTOCOL_INFOW)
  6315. params[1].dwValue;
  6316. UpdateResults (TRUE);
  6317. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6318. ShowStr(
  6319. " *lpdwBufferLength=x%x",
  6320. *((LPDWORD) params[2].dwValue)
  6321. );
  6322. for (j = 0; j < i; j++)
  6323. {
  6324. ShowProtoInfo ((LPWSAPROTOCOL_INFOA) pInfo, j, FALSE);
  6325. pInfo++;
  6326. }
  6327. UpdateResults (FALSE);
  6328. }
  6329. else
  6330. {
  6331. ShowError (funcIndex, iErrno);
  6332. if (iErrno == WSAENOBUFS)
  6333. {
  6334. ShowStr(
  6335. " *lpdwBufferLength=x%x",
  6336. *((LPDWORD) params[2].dwValue)
  6337. );
  6338. }
  6339. }
  6340. }
  6341. break;
  6342. }
  6343. case ws_WSCGetProviderPath:
  6344. {
  6345. GUID guid[2];
  6346. INT iPathLen = dwBigBufSize, iErrno = 0;
  6347. FUNC_PARAM params[] =
  6348. {
  6349. { "lpProviderId", PT_POINTER, (ULONG_PTR) guid, guid },
  6350. { "lpszProviderDllPath", PT_PTRNOEDIT,(ULONG_PTR) pBigBuf, pBigBuf },
  6351. { "lpProviderDllPathLen", PT_POINTER, (ULONG_PTR) &iPathLen, &iPathLen },
  6352. { "lpErrno", PT_PTRNOEDIT,(ULONG_PTR) &iErrno, &iErrno }
  6353. };
  6354. FUNC_PARAM_HEADER paramsHeader =
  6355. { 4, funcIndex, params, NULL };
  6356. if (LetUserMungeParams (&paramsHeader))
  6357. {
  6358. if ((i = WSCGetProviderPath(
  6359. (LPGUID) params[0].dwValue,
  6360. (LPWSTR) params[1].dwValue,
  6361. (LPINT) params[2].dwValue,
  6362. (LPINT) params[3].dwValue
  6363. )) == 0)
  6364. {
  6365. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6366. ShowStr ("*lpszProviderDllPath='%ws'", params[1].dwValue);
  6367. ShowStr ("*lpProviderDllPathLen=%d", *((LPINT)params[2].dwValue));
  6368. }
  6369. else
  6370. {
  6371. ShowError (funcIndex, iErrno);
  6372. }
  6373. }
  6374. break;
  6375. }
  6376. case ws_EnumProtocolsA:
  6377. case ws_EnumProtocolsW:
  6378. {
  6379. INT aiProtocols[32];
  6380. DWORD dwBufSize = dwBigBufSize;
  6381. FUNC_PARAM params[] =
  6382. {
  6383. { "lpiProtocols", PT_POINTER, (ULONG_PTR) NULL, aiProtocols },
  6384. { "lpProtocolBuffer", PT_PTRNOEDIT,(ULONG_PTR) pBigBuf, pBigBuf },
  6385. { "lpdwBufferLength", PT_POINTER, (ULONG_PTR) &dwBufSize, &dwBufSize }
  6386. };
  6387. FUNC_PARAM_HEADER paramsHeader =
  6388. { 3, funcIndex, params, NULL };
  6389. if (LetUserMungeParams (&paramsHeader))
  6390. {
  6391. i = (funcIndex == ws_EnumProtocolsA ?
  6392. EnumProtocolsA(
  6393. (LPINT) params[0].dwValue,
  6394. (LPVOID) params[1].dwValue,
  6395. (LPDWORD) params[2].dwValue
  6396. ) :
  6397. EnumProtocolsW(
  6398. (LPINT) params[0].dwValue,
  6399. (LPVOID) params[1].dwValue,
  6400. (LPDWORD) params[2].dwValue
  6401. ));
  6402. if (i >= 0)
  6403. {
  6404. char szProtoInfoN[20], buf[36];
  6405. PROTOCOL_INFO *pInfo;
  6406. UpdateResults (TRUE);
  6407. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6408. ShowStr ("iResult=%d", i);
  6409. ShowStr(
  6410. "*lpdwBufferLength=x%x",
  6411. *((LPDWORD) params[2].dwValue)
  6412. );
  6413. for(
  6414. j = 0, pInfo = (PROTOCOL_INFO *) params[1].dwValue;
  6415. j < i;
  6416. j++, pInfo++
  6417. )
  6418. {
  6419. wsprintf (szProtoInfoN, " protoInfo[%d].", j);
  6420. wsprintf (buf, "%sdwServiceFlags", szProtoInfoN);
  6421. ShowFlags (pInfo->dwServiceFlags, buf, aServiceFlags);
  6422. ShowStr(
  6423. "%siAddressFamily=%d, %s",
  6424. szProtoInfoN,
  6425. (DWORD) pInfo->iAddressFamily,
  6426. GetStringFromOrdinalValue(
  6427. (DWORD) pInfo->iAddressFamily,
  6428. aAddressFamilies
  6429. )
  6430. );
  6431. ShowStr(
  6432. "%siMaxSockAddr=%d",
  6433. szProtoInfoN,
  6434. (DWORD) pInfo->iMaxSockAddr
  6435. );
  6436. ShowStr(
  6437. "%siMinSockAddr=%d",
  6438. szProtoInfoN,
  6439. (DWORD) pInfo->iMinSockAddr
  6440. );
  6441. ShowStr(
  6442. "%siSocketType=%d, %s",
  6443. szProtoInfoN,
  6444. (DWORD) pInfo->iSocketType,
  6445. GetStringFromOrdinalValue(
  6446. (DWORD) pInfo->iSocketType,
  6447. aSocketTypes
  6448. )
  6449. );
  6450. ShowStr(
  6451. "%siProtocol=%d (x%x)", // ought to be flags???
  6452. szProtoInfoN,
  6453. (DWORD) pInfo->iProtocol,
  6454. (DWORD) pInfo->iProtocol
  6455. );
  6456. ShowStr(
  6457. "%sdwMessageSize=x%x",
  6458. szProtoInfoN,
  6459. (DWORD) pInfo->dwMessageSize
  6460. );
  6461. ShowStr(
  6462. "%slpProtocol=x%x",
  6463. szProtoInfoN,
  6464. pInfo->lpProtocol
  6465. );
  6466. if (funcIndex == ws_EnumProtocolsA)
  6467. {
  6468. ShowStr(
  6469. "%s*lpProtocol=%s",
  6470. szProtoInfoN,
  6471. pInfo->lpProtocol
  6472. );
  6473. ShowBytes(
  6474. (lstrlenA (pInfo->lpProtocol) + 1) * sizeof(CHAR),
  6475. pInfo->lpProtocol,
  6476. 2
  6477. );
  6478. }
  6479. else
  6480. {
  6481. ShowStr(
  6482. "%s*lpProtocol=%ws",
  6483. szProtoInfoN,
  6484. pInfo->lpProtocol
  6485. );
  6486. ShowBytes(
  6487. (lstrlenW ((WCHAR *) pInfo->lpProtocol) + 1)
  6488. * sizeof(WCHAR),
  6489. pInfo->lpProtocol,
  6490. 2
  6491. );
  6492. }
  6493. }
  6494. UpdateResults (FALSE);
  6495. }
  6496. else
  6497. {
  6498. if (ShowError (funcIndex, 0) == ERROR_INSUFFICIENT_BUFFER)
  6499. {
  6500. ShowStr(
  6501. "*lpdwBufferLength=x%x",
  6502. *((LPDWORD) params[2].dwValue)
  6503. );
  6504. }
  6505. }
  6506. }
  6507. break;
  6508. }
  6509. case ws_GetAddressByNameA:
  6510. case ws_GetAddressByNameW:
  6511. {
  6512. GUID guid[2];
  6513. WCHAR szSvcName[MAX_STRING_PARAM_SIZE] = L"";
  6514. INT aiProtocols[32];
  6515. char *pBigBuf2 = (char *) LocalAlloc (LPTR, dwBigBufSize);
  6516. DWORD dwCsaddrBufLen = dwBigBufSize, dwAliasBufLen = dwBigBufSize;
  6517. FUNC_PARAM params[] =
  6518. {
  6519. { "dwNameSpace", PT_ORDINAL, (ULONG_PTR) 0, aNameSpaces },
  6520. { "lpServiceType", PT_POINTER, (ULONG_PTR) guid, guid },
  6521. { "lpServiceName", PT_STRING, (ULONG_PTR) NULL, szSvcName },
  6522. { "lpiProtocols", PT_POINTER, (ULONG_PTR) NULL, aiProtocols },
  6523. { "dwResolution", PT_FLAGS, (ULONG_PTR) 0, aResFlags },
  6524. { "lpServiceAsyncInfo", PT_DWORD, (ULONG_PTR) 0, 0 },
  6525. { "lpCsaddrBuffer", PT_PTRNOEDIT,(ULONG_PTR) pBigBuf, pBigBuf },
  6526. { "lpdwCsaddrBufLen", PT_POINTER, (ULONG_PTR) &dwCsaddrBufLen, &dwCsaddrBufLen },
  6527. { "lpAliasBuf", PT_PTRNOEDIT,(ULONG_PTR) pBigBuf2, pBigBuf2 },
  6528. { "lpdwAliasBufLen", PT_POINTER, (ULONG_PTR) &dwAliasBufLen, &dwAliasBufLen }
  6529. };
  6530. FUNC_PARAM_HEADER paramsHeader =
  6531. { 10, funcIndex, params, NULL };
  6532. if (LetUserMungeParams (&paramsHeader))
  6533. {
  6534. i = (funcIndex == ws_GetAddressByNameA ?
  6535. GetAddressByNameA(
  6536. (DWORD) params[0].dwValue,
  6537. (LPGUID) params[1].dwValue,
  6538. (LPSTR) params[2].dwValue,
  6539. (LPINT) params[3].dwValue,
  6540. (DWORD) params[4].dwValue,
  6541. (LPSERVICE_ASYNC_INFO) params[5].dwValue,
  6542. (LPVOID) params[6].dwValue,
  6543. (LPDWORD) params[7].dwValue,
  6544. (LPSTR) params[8].dwValue,
  6545. (LPDWORD) params[9].dwValue
  6546. ) :
  6547. GetAddressByNameW(
  6548. (DWORD) params[0].dwValue,
  6549. (LPGUID) params[1].dwValue,
  6550. (LPWSTR) params[2].dwValue,
  6551. (LPINT) params[3].dwValue,
  6552. (DWORD) params[4].dwValue,
  6553. (LPSERVICE_ASYNC_INFO) params[5].dwValue,
  6554. (LPVOID) params[6].dwValue,
  6555. (LPDWORD) params[7].dwValue,
  6556. (LPWSTR) params[8].dwValue,
  6557. (LPDWORD) params[9].dwValue
  6558. ));
  6559. if (i >= 0)
  6560. {
  6561. char szAddrInfoN[20];
  6562. CSADDR_INFO *pInfo;
  6563. UpdateResults (TRUE);
  6564. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6565. ShowStr ("iResult=%d", i);
  6566. ShowStr(
  6567. "*lpdwCsaddrBufLen=x%x",
  6568. *((LPDWORD) params[7].dwValue)
  6569. );
  6570. for(
  6571. j = 0, pInfo = (CSADDR_INFO *) params[6].dwValue;
  6572. j < i;
  6573. j++, pInfo++
  6574. )
  6575. {
  6576. wsprintf (szAddrInfoN, " addrInfo[%d].", j);
  6577. ShowStr(
  6578. "%sLocalAddr.lpSockaddr=x%x",
  6579. szAddrInfoN,
  6580. pInfo->LocalAddr.lpSockaddr
  6581. );
  6582. ShowBytes(
  6583. pInfo->LocalAddr.iSockaddrLength,
  6584. pInfo->LocalAddr.lpSockaddr,
  6585. 2
  6586. );
  6587. ShowStr(
  6588. "%sLocalAddr.iSockaddrLen=%d (x%x)",
  6589. szAddrInfoN,
  6590. pInfo->LocalAddr.iSockaddrLength,
  6591. pInfo->LocalAddr.iSockaddrLength
  6592. );
  6593. ShowStr(
  6594. "%sRemoteAddr.lpSockaddr=x%x",
  6595. szAddrInfoN,
  6596. pInfo->RemoteAddr.lpSockaddr
  6597. );
  6598. ShowBytes(
  6599. pInfo->RemoteAddr.iSockaddrLength,
  6600. pInfo->RemoteAddr.lpSockaddr,
  6601. 2
  6602. );
  6603. ShowStr(
  6604. "%sRemoteAddr.iSockaddrLen=%d (x%x)",
  6605. szAddrInfoN,
  6606. pInfo->RemoteAddr.iSockaddrLength,
  6607. pInfo->RemoteAddr.iSockaddrLength
  6608. );
  6609. ShowStr(
  6610. "%siSocketType=%d, %s",
  6611. szAddrInfoN,
  6612. (DWORD) pInfo->iSocketType,
  6613. GetStringFromOrdinalValue(
  6614. (DWORD) pInfo->iSocketType,
  6615. aSocketTypes
  6616. )
  6617. );
  6618. ShowStr(
  6619. "%siProtocol=%d (x%x)", // ought to be flags???
  6620. szAddrInfoN,
  6621. (DWORD) pInfo->iProtocol,
  6622. (DWORD) pInfo->iProtocol
  6623. );
  6624. }
  6625. UpdateResults (FALSE);
  6626. }
  6627. else
  6628. {
  6629. if (ShowError (funcIndex, 0) == ERROR_INSUFFICIENT_BUFFER)
  6630. {
  6631. ShowStr(
  6632. "*lpdwCsaddrBufLen=x%x",
  6633. *((LPDWORD) params[7].dwValue)
  6634. );
  6635. }
  6636. }
  6637. }
  6638. LocalFree (pBigBuf2);
  6639. break;
  6640. }
  6641. case ws_GetNameByTypeA:
  6642. case ws_GetNameByTypeW:
  6643. {
  6644. GUID guid[2];
  6645. FUNC_PARAM params[] =
  6646. {
  6647. { "lpServiceType", PT_POINTER, (ULONG_PTR) guid, guid },
  6648. { "lpServiceName", PT_PTRNOEDIT,(ULONG_PTR) pBigBuf, pBigBuf },
  6649. { "dwNameLength", PT_DWORD, (ULONG_PTR) dwBigBufSize, NULL }
  6650. };
  6651. FUNC_PARAM_HEADER paramsHeader =
  6652. { 3, funcIndex, params, NULL };
  6653. if (LetUserMungeParams (&paramsHeader))
  6654. {
  6655. i = (funcIndex == ws_GetNameByTypeA ?
  6656. GetNameByTypeA(
  6657. (LPGUID) params[0].dwValue,
  6658. (LPSTR) params[1].dwValue,
  6659. (DWORD) params[2].dwValue
  6660. ) :
  6661. GetNameByTypeW(
  6662. (LPGUID) params[0].dwValue,
  6663. (LPWSTR) params[1].dwValue,
  6664. (DWORD) params[2].dwValue
  6665. ));
  6666. if (i != SOCKET_ERROR)
  6667. {
  6668. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6669. if (funcIndex == ws_GetNameByTypeA)
  6670. {
  6671. ShowStr ("*lpServiceName=%s", (char *) params[1].dwValue);
  6672. }
  6673. else
  6674. {
  6675. ShowStr ("*lpServiceName=%ws", (char *) params[1].dwValue);
  6676. }
  6677. }
  6678. else
  6679. {
  6680. ShowError (funcIndex, 0);
  6681. }
  6682. }
  6683. break;
  6684. }
  6685. case ws_GetServiceA:
  6686. case ws_GetServiceW:
  6687. {
  6688. GUID guid[2];
  6689. WCHAR szSvcName[MAX_STRING_PARAM_SIZE] = L"";
  6690. DWORD dwBufSize = dwBigBufSize;
  6691. FUNC_PARAM params[] =
  6692. {
  6693. { "dwNameSpace", PT_ORDINAL, (ULONG_PTR) 0, aNameSpaces },
  6694. { "lpGuid", PT_POINTER, (ULONG_PTR) guid, guid },
  6695. { "lpServiceName", PT_STRING, (ULONG_PTR) szSvcName, szSvcName },
  6696. { "dwProperties", PT_FLAGS, (ULONG_PTR) 0, aProperties },
  6697. { "lpBuffer", PT_PTRNOEDIT, (ULONG_PTR) pBigBuf, pBigBuf },
  6698. { "lpdwBufLen", PT_POINTER, (ULONG_PTR) &dwBufSize, &dwBufSize },
  6699. { "lpSvcAsyncInfo", PT_DWORD, (ULONG_PTR) 0, 0 }
  6700. };
  6701. FUNC_PARAM_HEADER paramsHeader =
  6702. { 7, funcIndex, params, NULL };
  6703. if (LetUserMungeParams (&paramsHeader))
  6704. {
  6705. i = (funcIndex == ws_GetServiceA ?
  6706. GetServiceA(
  6707. (DWORD) params[0].dwValue,
  6708. (LPGUID) params[1].dwValue,
  6709. (LPSTR) params[2].dwValue,
  6710. (DWORD) params[3].dwValue,
  6711. (LPVOID) params[4].dwValue,
  6712. (LPDWORD) params[5].dwValue,
  6713. (LPSERVICE_ASYNC_INFO) params[6].dwValue
  6714. ) :
  6715. GetServiceW(
  6716. (DWORD) params[0].dwValue,
  6717. (LPGUID) params[1].dwValue,
  6718. (LPWSTR) params[2].dwValue,
  6719. (DWORD) params[3].dwValue,
  6720. (LPVOID) params[4].dwValue,
  6721. (LPDWORD) params[5].dwValue,
  6722. (LPSERVICE_ASYNC_INFO) params[6].dwValue
  6723. ));
  6724. if (i >= 0)
  6725. {
  6726. char szSvcInfoN[20], buf[36];
  6727. SERVICE_INFO *pInfo;
  6728. SERVICE_ADDRESS *pAddr;
  6729. UpdateResults (TRUE);
  6730. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6731. ShowStr ("iResult=%d", i);
  6732. ShowStr(
  6733. "*lpdwBufLen=x%x",
  6734. *((LPDWORD) params[5].dwValue)
  6735. );
  6736. for(
  6737. j = 0, pInfo = (SERVICE_INFO *) params[4].dwValue;
  6738. j < i;
  6739. j++, pInfo++
  6740. )
  6741. {
  6742. wsprintf (szSvcInfoN, " svcInfo[%d].", j);
  6743. wsprintf (buf, "lpServiceType=");
  6744. ShowGUID (buf, pInfo->lpServiceType);
  6745. ShowStr(
  6746. (funcIndex == ws_GetServiceA ?
  6747. "%slpServiceName=%s" : "%slpServiceName=%ws"),
  6748. szSvcInfoN,
  6749. pInfo->lpServiceName
  6750. );
  6751. ShowStr(
  6752. (funcIndex == ws_GetServiceA ?
  6753. "%slpComment=%s" : "%slpComment=%ws"),
  6754. szSvcInfoN,
  6755. pInfo->lpServiceName
  6756. );
  6757. ShowStr(
  6758. (funcIndex == ws_GetServiceA ?
  6759. "%slpLocale=%s" : "%slpLocale=%ws"),
  6760. szSvcInfoN,
  6761. pInfo->lpLocale
  6762. );
  6763. ShowStr(
  6764. "%sdwDisplayHint=%d, %s",
  6765. szSvcInfoN,
  6766. (DWORD) pInfo->dwDisplayHint,
  6767. GetStringFromOrdinalValue(
  6768. (DWORD) pInfo->dwDisplayHint,
  6769. aResDisplayTypes
  6770. )
  6771. );
  6772. ShowStr ("%sdwVersion=x%x", szSvcInfoN, pInfo->dwVersion);
  6773. ShowStr ("%sdwTime=x%x", szSvcInfoN, pInfo->dwTime);
  6774. ShowStr(
  6775. (funcIndex == ws_GetServiceA ?
  6776. "%slpMachineName=%s" : "%slpMachineName=%ws"),
  6777. szSvcInfoN,
  6778. pInfo->lpMachineName
  6779. );
  6780. ShowStr(
  6781. "%slpServiceAddress.dwAddressCount=%d (x%x)",
  6782. szSvcInfoN,
  6783. pInfo->lpServiceAddress->dwAddressCount,
  6784. pInfo->lpServiceAddress->dwAddressCount
  6785. );
  6786. for(
  6787. k = 0, pAddr = pInfo->lpServiceAddress->Addresses;
  6788. k < (int) pInfo->lpServiceAddress->dwAddressCount;
  6789. k++, pAddr++
  6790. )
  6791. {
  6792. }
  6793. ShowStr(
  6794. "%sServiceSpecificInfo.cbSize=%d (x%x)",
  6795. szSvcInfoN,
  6796. pInfo->ServiceSpecificInfo.cbSize,
  6797. pInfo->ServiceSpecificInfo.cbSize
  6798. );
  6799. ShowBytes(
  6800. pInfo->ServiceSpecificInfo.cbSize,
  6801. pInfo->ServiceSpecificInfo.pBlobData,
  6802. 2
  6803. );
  6804. }
  6805. UpdateResults (FALSE);
  6806. }
  6807. else
  6808. {
  6809. if (ShowError (funcIndex, i) == ERROR_INSUFFICIENT_BUFFER)
  6810. {
  6811. ShowStr(
  6812. "*lpdwBufLen=x%x",
  6813. *((LPDWORD) params[5].dwValue)
  6814. );
  6815. }
  6816. }
  6817. }
  6818. break;
  6819. }
  6820. case ws_GetTypeByNameA:
  6821. case ws_GetTypeByNameW:
  6822. {
  6823. GUID guid[2];
  6824. WCHAR szSvcName[MAX_STRING_PARAM_SIZE] = L"";
  6825. FUNC_PARAM params[] =
  6826. {
  6827. { "lpServiceName", PT_PTRNOEDIT,(ULONG_PTR) szSvcName, szSvcName },
  6828. { "lpServiceType", PT_POINTER, (ULONG_PTR) guid, guid }
  6829. };
  6830. FUNC_PARAM_HEADER paramsHeader =
  6831. { 2, funcIndex, params, NULL };
  6832. if (LetUserMungeParams (&paramsHeader))
  6833. {
  6834. i = (funcIndex == ws_GetTypeByNameA ?
  6835. GetTypeByNameA(
  6836. (LPSTR) params[0].dwValue,
  6837. (LPGUID) params[1].dwValue
  6838. ) :
  6839. GetTypeByNameW(
  6840. (LPWSTR) params[0].dwValue,
  6841. (LPGUID) params[1].dwValue
  6842. ));
  6843. if (i != SOCKET_ERROR)
  6844. {
  6845. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6846. ShowGUID ("*lpServiceType=", (LPGUID) params[1].dwValue);
  6847. }
  6848. else
  6849. {
  6850. ShowError (funcIndex, 0);
  6851. }
  6852. }
  6853. break;
  6854. }
  6855. case ws_SetServiceA:
  6856. case ws_SetServiceW:
  6857. {
  6858. DWORD dwStatusFlags;
  6859. FUNC_PARAM params[] =
  6860. {
  6861. { "dwNameSpace", PT_ORDINAL, (ULONG_PTR) 0, aNameSpaces },
  6862. { "dwOperation", PT_ORDINAL, (ULONG_PTR) 0, aServiceOps },
  6863. { "dwFlags", PT_FLAGS, (ULONG_PTR) 0, aSvcFlags },
  6864. { "lpServiceInfo", PT_POINTER, (ULONG_PTR) pBigBuf, pBigBuf },
  6865. { "lpServiceAsnycInfo", PT_DWORD, (ULONG_PTR) 0, NULL },
  6866. { "lpdwStatusFlags", PT_PTRNOEDIT, (ULONG_PTR) &dwStatusFlags, &dwStatusFlags },
  6867. };
  6868. FUNC_PARAM_HEADER paramsHeader =
  6869. { 6, funcIndex, params, NULL };
  6870. if (LetUserMungeParams (&paramsHeader))
  6871. {
  6872. i = (funcIndex == ws_SetServiceA ?
  6873. SetServiceA(
  6874. (DWORD) params[0].dwValue,
  6875. (DWORD) params[1].dwValue,
  6876. (DWORD) params[2].dwValue,
  6877. (LPSERVICE_INFOA) params[3].dwValue,
  6878. (LPSERVICE_ASYNC_INFO) params[4].dwValue,
  6879. (LPDWORD) params[5].dwValue
  6880. ) :
  6881. SetServiceW(
  6882. (DWORD) params[0].dwValue,
  6883. (DWORD) params[1].dwValue,
  6884. (DWORD) params[2].dwValue,
  6885. (LPSERVICE_INFOW) params[3].dwValue,
  6886. (LPSERVICE_ASYNC_INFO) params[4].dwValue,
  6887. (LPDWORD) params[5].dwValue
  6888. ));
  6889. if (i != SOCKET_ERROR)
  6890. {
  6891. ShowStr (gszXxxSUCCESS, aFuncNames[funcIndex]);
  6892. }
  6893. else
  6894. {
  6895. ShowError (funcIndex, 0);
  6896. }
  6897. }
  6898. break;
  6899. }
  6900. // case CloseHandl:
  6901. //
  6902. // break;
  6903. // case DumpBuffer:
  6904. //
  6905. // break;
  6906. }
  6907. }
  6908. void
  6909. FAR
  6910. ShowHostEnt(
  6911. struct hostent *phe
  6912. )
  6913. {
  6914. DWORD i, j;
  6915. ShowStr (" pHostEnt=x%x", phe);
  6916. ShowStr (" ->h_name=%s", phe->h_name);
  6917. for (i = 0; *(phe->h_aliases + i); i++)
  6918. {
  6919. ShowStr (" ->h_aliases[%d]=%s", i, *(phe->h_aliases + i));
  6920. }
  6921. ShowStr (" ->h_addrtype=%x", (DWORD) phe->h_addrtype);
  6922. ShowStr (" ->h_length=%x", (DWORD) phe->h_length);
  6923. for (i = 0; *(phe->h_addr_list + i); i++)
  6924. {
  6925. char far *pAddr = *(phe->h_addr_list + i);
  6926. if (phe->h_addrtype == AF_INET)
  6927. {
  6928. ShowStr (" ->h_addr_list[%d]=", i);
  6929. ShowBytes (sizeof (DWORD) + lstrlenA (pAddr+4), pAddr, 2);
  6930. }
  6931. else
  6932. {
  6933. ShowStr (" ->h_addr_list[%d]=%s", i, *(phe->h_addr_list + i));
  6934. }
  6935. }
  6936. }
  6937. void
  6938. FAR
  6939. ShowProtoEnt(
  6940. struct protoent *ppe
  6941. )
  6942. {
  6943. DWORD i;
  6944. ShowStr (" pProtoEnt=x%x", ppe);
  6945. ShowStr (" ->p_name=%s", ppe->p_name);
  6946. for (i = 0; *(ppe->p_aliases + i); i++)
  6947. {
  6948. ShowStr (" ->p_aliases[%d]=%s", i, *(ppe->p_aliases + i));
  6949. }
  6950. ShowStr (" ->p_proto=%x", (DWORD) ppe->p_proto);
  6951. }
  6952. void
  6953. FAR
  6954. ShowServEnt(
  6955. struct servent *pse
  6956. )
  6957. {
  6958. DWORD i;
  6959. ShowStr (" pServEnt=x%x", pse);
  6960. ShowStr (" ->s_name=%s", pse->s_name);
  6961. for (i = 0; *(pse->s_aliases + i); i++)
  6962. {
  6963. ShowStr (" ->s_aliases[%d]=%s", i, *(pse->s_aliases + i));
  6964. }
  6965. ShowStr (" ->s_port=%d (x%x)", (DWORD) pse->s_port, (DWORD) pse->s_port);
  6966. ShowStr (" ->s_proto=%s", pse->s_proto);
  6967. }
  6968. void
  6969. PASCAL
  6970. QueueAsyncRequestInfo(
  6971. PASYNC_REQUEST_INFO pAsyncReqInfo
  6972. )
  6973. {
  6974. pAsyncReqInfo->pNext = gpAsyncReqInfoList;
  6975. gpAsyncReqInfoList = pAsyncReqInfo;
  6976. }
  6977. PASYNC_REQUEST_INFO
  6978. PASCAL
  6979. DequeueAsyncRequestInfo(
  6980. HANDLE hRequest
  6981. )
  6982. {
  6983. PASYNC_REQUEST_INFO pAsyncReqInfo;
  6984. for(
  6985. pAsyncReqInfo = gpAsyncReqInfoList;
  6986. pAsyncReqInfo && pAsyncReqInfo->hRequest != hRequest;
  6987. pAsyncReqInfo = pAsyncReqInfo->pNext
  6988. );
  6989. if (pAsyncReqInfo)
  6990. {
  6991. if (pAsyncReqInfo->pPrev)
  6992. {
  6993. pAsyncReqInfo->pPrev->pNext = pAsyncReqInfo->pNext;
  6994. }
  6995. else
  6996. {
  6997. gpAsyncReqInfoList = pAsyncReqInfo->pNext;
  6998. }
  6999. if (pAsyncReqInfo->pNext)
  7000. {
  7001. pAsyncReqInfo->pNext->pPrev = pAsyncReqInfo->pPrev;
  7002. }
  7003. }
  7004. return pAsyncReqInfo;
  7005. }
  7006. void
  7007. PASCAL
  7008. ShowModBytes(
  7009. DWORD dwSize,
  7010. unsigned char far *lpc,
  7011. char *pszTab,
  7012. char *buf
  7013. )
  7014. {
  7015. DWORD dwSize2 = dwSize, i, j, k;
  7016. strcpy (buf, pszTab);
  7017. k = strlen (buf);
  7018. for (i = 8; i < 36; i += 9)
  7019. {
  7020. buf[k + i] = ' ';
  7021. for (j = 2; j < 9; j += 2)
  7022. {
  7023. char buf2[8] = "xx";
  7024. if (dwSize2)
  7025. {
  7026. sprintf (buf2, "%02x", (int) (*lpc));
  7027. dwSize2--;
  7028. }
  7029. buf[k + i - j] = buf2[0];
  7030. buf[k + i - j + 1] = buf2[1];
  7031. lpc++;
  7032. }
  7033. }
  7034. k += 37;
  7035. buf[k - 1] = ' ';
  7036. lpc -= 16;
  7037. for (i = 0; i < dwSize; i++)
  7038. {
  7039. buf[k + i] = aAscii[*(lpc+i)];
  7040. }
  7041. buf[k + i] = 0;
  7042. ShowStr (buf);
  7043. }
  7044. void
  7045. UpdateResults(
  7046. BOOL bBegin
  7047. )
  7048. {
  7049. //
  7050. // In order to maximize speed, minimize flash, & have the
  7051. // latest info in the edit control scrolled into view we
  7052. // shrink the window down and hide it. Later, when all the
  7053. // text has been inserted in the edit control, we show
  7054. // the window (since window must be visible in order to
  7055. // scroll caret into view), then tell it to scroll the caret
  7056. // (at this point the window is still 1x1 so the painting
  7057. // overhead is 0), and finally restore the control to it's
  7058. // full size. In doing so we have zero flash and only 1 real
  7059. // complete paint. Also put up the hourglass for warm fuzzies.
  7060. //
  7061. static RECT rect;
  7062. static HCURSOR hCurSave;
  7063. static int iNumBegins = 0;
  7064. if (bBegin)
  7065. {
  7066. iNumBegins++;
  7067. if (iNumBegins > 1)
  7068. {
  7069. return;
  7070. }
  7071. hCurSave = SetCursor (LoadCursor ((HINSTANCE)NULL, IDC_WAIT));
  7072. GetWindowRect (ghwndEdit, &rect);
  7073. SetWindowPos(
  7074. ghwndEdit,
  7075. (HWND) NULL,
  7076. 0,
  7077. 0,
  7078. 1,
  7079. 1,
  7080. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOREDRAW |
  7081. SWP_NOZORDER | SWP_HIDEWINDOW
  7082. );
  7083. }
  7084. else
  7085. {
  7086. iNumBegins--;
  7087. if (iNumBegins > 0)
  7088. {
  7089. return;
  7090. }
  7091. //
  7092. // Do control restoration as described above
  7093. //
  7094. ShowWindow (ghwndEdit, SW_SHOW);
  7095. #ifdef WIN32
  7096. SendMessage (ghwndEdit, EM_SCROLLCARET, 0, 0);
  7097. #else
  7098. SendMessage(
  7099. ghwndEdit,
  7100. EM_SETSEL,
  7101. (WPARAM)0,
  7102. (LPARAM) MAKELONG(0xfffd,0xfffe)
  7103. );
  7104. #endif
  7105. SetWindowPos(
  7106. ghwndEdit,
  7107. (HWND) NULL,
  7108. 0,
  7109. 0,
  7110. rect.right - rect.left,
  7111. rect.bottom - rect.top,
  7112. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER
  7113. );
  7114. SetCursor (hCurSave);
  7115. }
  7116. }
  7117. void
  7118. PASCAL
  7119. ShowBytes(
  7120. DWORD dwSize,
  7121. LPVOID lp,
  7122. DWORD dwNumTabs
  7123. )
  7124. {
  7125. char tabBuf[17] = "";
  7126. char buf[80];
  7127. DWORD i, j, k, dwNumDWORDs, dwMod4 = (DWORD)(((ULONG_PTR) lp) % 4);
  7128. LPDWORD lpdw;
  7129. unsigned char far *lpc = (unsigned char far *) lp;
  7130. UpdateResults (TRUE);
  7131. for (i = 0; i < dwNumTabs; i++)
  7132. {
  7133. strcat (tabBuf, szTab);
  7134. }
  7135. //
  7136. // Special case for unaligned pointers (will fault on ppc/mips)
  7137. //
  7138. if (dwMod4)
  7139. {
  7140. DWORD dwNumUnalignedBytes = 4 - dwMod4,
  7141. dwNumBytesToShow = (dwNumUnalignedBytes > dwSize ?
  7142. dwSize : dwNumUnalignedBytes);
  7143. ShowModBytes (dwNumBytesToShow, lpc, tabBuf, buf);
  7144. lpc += dwNumUnalignedBytes;
  7145. lpdw = (LPDWORD) lpc;
  7146. dwSize -= dwNumBytesToShow;
  7147. }
  7148. else
  7149. {
  7150. lpdw = (LPDWORD) lp;
  7151. }
  7152. //
  7153. // Dump full lines of four DWORDs in hex & corresponding ASCII
  7154. //
  7155. if (dwSize >= (4*sizeof(DWORD)))
  7156. {
  7157. dwNumDWORDs = dwSize / 4; // adjust from numBytes to num DWORDs
  7158. for (i = 0; i < (dwNumDWORDs - (dwNumDWORDs%4)); i += 4)
  7159. {
  7160. sprintf (
  7161. buf,
  7162. "%s%08lx %08lx %08lx %08lx ",
  7163. tabBuf,
  7164. *lpdw,
  7165. *(lpdw+1),
  7166. *(lpdw+2),
  7167. *(lpdw+3)
  7168. );
  7169. k = strlen (buf);
  7170. for (j = 0; j < 16; j++)
  7171. {
  7172. buf[k + j] = aAscii[*(lpc + j)];
  7173. }
  7174. buf[k + j] = 0;
  7175. ShowStr (buf);
  7176. lpdw += 4;
  7177. lpc += 16;
  7178. }
  7179. }
  7180. //
  7181. // Special case for remaining bytes to dump (0 < n < 16)
  7182. //
  7183. if ((dwSize %= 16))
  7184. {
  7185. ShowModBytes (dwSize, lpc, tabBuf, buf);
  7186. }
  7187. UpdateResults (FALSE);
  7188. }
  7189. void
  7190. PASCAL
  7191. ShowFlags(
  7192. DWORD dwValue,
  7193. char FAR *pszValueName,
  7194. PLOOKUP pLookup
  7195. )
  7196. {
  7197. char buf[80];
  7198. DWORD i;
  7199. wsprintf (buf, "%s=x%lx, ", pszValueName, dwValue);
  7200. for (i = 0; dwValue && pLookup[i].lpszVal; i++)
  7201. {
  7202. if (dwValue & pLookup[i].dwVal)
  7203. {
  7204. if (buf[0] == 0)
  7205. {
  7206. lstrcpyA (buf, " ");
  7207. }
  7208. lstrcatA (buf, pLookup[i].lpszVal);
  7209. lstrcat (buf, " ");
  7210. dwValue &= ~pLookup[i].dwVal;
  7211. if (lstrlen (buf) > 50)
  7212. {
  7213. //
  7214. // We don't want strings getting so long that
  7215. // they're going offscreen, so break them up.
  7216. //
  7217. ShowStr (buf);
  7218. buf[0] = 0;
  7219. }
  7220. }
  7221. }
  7222. if (dwValue)
  7223. {
  7224. lstrcat (buf, "<unknown flag(s)>");
  7225. }
  7226. if (buf[0])
  7227. {
  7228. ShowStr (buf);
  7229. }
  7230. }
  7231. LPSTR
  7232. PASCAL
  7233. GetStringFromOrdinalValue(
  7234. DWORD dwValue,
  7235. PLOOKUP pLookup
  7236. )
  7237. {
  7238. DWORD i;
  7239. for (i = 0; pLookup[i].lpszVal && dwValue != pLookup[i].dwVal; i++);
  7240. return (pLookup[i].lpszVal ? pLookup[i].lpszVal : gszUnknown);
  7241. }
  7242. VOID
  7243. PASCAL
  7244. ShowGUID(
  7245. char *pszProlog,
  7246. GUID *pGuid
  7247. )
  7248. {
  7249. ShowStr(
  7250. "%s%08x %04x %04x %02x%02x%02x%02x%02x%02x%02x%02x",
  7251. (ULONG_PTR) pszProlog,
  7252. (DWORD) pGuid->Data1,
  7253. (DWORD) pGuid->Data2,
  7254. (DWORD) pGuid->Data3,
  7255. (DWORD) pGuid->Data4[0],
  7256. (DWORD) pGuid->Data4[1],
  7257. (DWORD) pGuid->Data4[2],
  7258. (DWORD) pGuid->Data4[3],
  7259. (DWORD) pGuid->Data4[4],
  7260. (DWORD) pGuid->Data4[5],
  7261. (DWORD) pGuid->Data4[6],
  7262. (DWORD) pGuid->Data4[7]
  7263. );
  7264. //
  7265. // Dump the GUID in a form that can be copied & pasted into other
  7266. // API params
  7267. //
  7268. {
  7269. LPBYTE p = (LPBYTE) pGuid;
  7270. ShowStr(
  7271. " (%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x)",
  7272. (DWORD) *p,
  7273. (DWORD) *(p + 1),
  7274. (DWORD) *(p + 2),
  7275. (DWORD) *(p + 3),
  7276. (DWORD) *(p + 4),
  7277. (DWORD) *(p + 5),
  7278. (DWORD) *(p + 6),
  7279. (DWORD) *(p + 7),
  7280. (DWORD) *(p + 8),
  7281. (DWORD) *(p + 9),
  7282. (DWORD) *(p + 10),
  7283. (DWORD) *(p + 11),
  7284. (DWORD) *(p + 12),
  7285. (DWORD) *(p + 13),
  7286. (DWORD) *(p + 14),
  7287. (DWORD) *(p + 15)
  7288. );
  7289. }
  7290. }
  7291. VOID
  7292. PASCAL
  7293. ShowProtoInfo(
  7294. LPWSAPROTOCOL_INFOA pInfo,
  7295. DWORD dwIndex,
  7296. BOOL bAscii
  7297. )
  7298. {
  7299. char szProtoInfoN[20], buf[40];
  7300. if (dwIndex == 0xffffffff)
  7301. {
  7302. wsprintf (szProtoInfoN, " protoInfo");
  7303. }
  7304. else
  7305. {
  7306. wsprintf (szProtoInfoN, " protoInfo[%d].", dwIndex);
  7307. }
  7308. wsprintf (buf, "%sdwServiceFlags", szProtoInfoN);
  7309. ShowFlags (pInfo->dwServiceFlags1, buf, aServiceFlags);
  7310. ShowStr(
  7311. "%sdwServiceFlags2=x%x",
  7312. szProtoInfoN,
  7313. pInfo->dwServiceFlags2
  7314. );
  7315. ShowStr(
  7316. "%sdwServiceFlags3=x%x",
  7317. szProtoInfoN,
  7318. pInfo->dwServiceFlags3
  7319. );
  7320. ShowStr(
  7321. "%sdwServiceFlags4=x%x",
  7322. szProtoInfoN,
  7323. pInfo->dwServiceFlags4
  7324. );
  7325. wsprintf (buf, "%sdwProviderFlags", szProtoInfoN);
  7326. ShowFlags (pInfo->dwProviderFlags, buf, aProviderFlags);
  7327. wsprintf (buf, "%sProviderId=", szProtoInfoN);
  7328. ShowGUID (buf, &pInfo->ProviderId);
  7329. ShowStr(
  7330. "%sdwCatalogEntryId=x%x",
  7331. szProtoInfoN,
  7332. pInfo->dwCatalogEntryId
  7333. );
  7334. ShowStr(
  7335. "%sProtocolChain.ChainLen=x%x",
  7336. szProtoInfoN,
  7337. (DWORD) pInfo->ProtocolChain.ChainLen
  7338. );
  7339. ShowStr(
  7340. "%sProtocolChain.ChainEntries=",
  7341. szProtoInfoN
  7342. );
  7343. ShowBytes(
  7344. sizeof (DWORD) * MAX_PROTOCOL_CHAIN,
  7345. pInfo->ProtocolChain.ChainEntries,
  7346. 2
  7347. );
  7348. ShowStr(
  7349. "%siVersion=x%x",
  7350. szProtoInfoN,
  7351. (DWORD) pInfo->iVersion
  7352. );
  7353. ShowStr(
  7354. "%siAddressFamily=%d, %s",
  7355. szProtoInfoN,
  7356. (DWORD) pInfo->iAddressFamily,
  7357. GetStringFromOrdinalValue(
  7358. (DWORD) pInfo->iAddressFamily,
  7359. aAddressFamilies
  7360. )
  7361. );
  7362. ShowStr(
  7363. "%siMaxSockAddr=%d",
  7364. szProtoInfoN,
  7365. (DWORD) pInfo->iMaxSockAddr
  7366. );
  7367. ShowStr(
  7368. "%siMinSockAddr=%d",
  7369. szProtoInfoN,
  7370. (DWORD) pInfo->iMinSockAddr
  7371. );
  7372. ShowStr(
  7373. "%siSocketType=%d, %s",
  7374. szProtoInfoN,
  7375. (DWORD) pInfo->iSocketType,
  7376. GetStringFromOrdinalValue(
  7377. (DWORD) pInfo->iSocketType,
  7378. aSocketTypes
  7379. )
  7380. );
  7381. ShowStr(
  7382. "%siProtocol=%d (x%x)", // ought to be flags???
  7383. szProtoInfoN,
  7384. (DWORD) pInfo->iProtocol,
  7385. (DWORD) pInfo->iProtocol
  7386. );
  7387. ShowStr(
  7388. "%siProtocolMaxOffset=%d",
  7389. szProtoInfoN,
  7390. (DWORD) pInfo->iProtocolMaxOffset
  7391. );
  7392. ShowStr(
  7393. "%siNetworkByteOrder=%d, %s",
  7394. szProtoInfoN,
  7395. (DWORD) pInfo->iNetworkByteOrder,
  7396. GetStringFromOrdinalValue(
  7397. (DWORD) pInfo->iNetworkByteOrder,
  7398. aNetworkByteOrders
  7399. )
  7400. );
  7401. ShowStr(
  7402. "%siSecurityScheme=x%x",
  7403. szProtoInfoN,
  7404. (DWORD) pInfo->iSecurityScheme
  7405. );
  7406. ShowStr(
  7407. "%sdwMessageSize=x%x",
  7408. szProtoInfoN,
  7409. (DWORD) pInfo->dwMessageSize
  7410. );
  7411. ShowStr(
  7412. "%sdwProviderReserved=x%x",
  7413. szProtoInfoN,
  7414. (DWORD) pInfo->dwMessageSize
  7415. );
  7416. if (bAscii)
  7417. {
  7418. ShowStr(
  7419. "%sszProtocol=%s",
  7420. szProtoInfoN,
  7421. pInfo->szProtocol
  7422. );
  7423. ShowBytes(
  7424. (lstrlenA (pInfo->szProtocol) + 1) * sizeof(CHAR),
  7425. pInfo->szProtocol,
  7426. 2
  7427. );
  7428. }
  7429. else
  7430. {
  7431. ShowStr(
  7432. "%sszProtocol=%ws",
  7433. szProtoInfoN,
  7434. pInfo->szProtocol
  7435. );
  7436. ShowBytes(
  7437. (lstrlenW (((LPWSAPROTOCOL_INFOW) pInfo)->szProtocol) + 1)
  7438. * sizeof(WCHAR),
  7439. pInfo->szProtocol,
  7440. 2
  7441. );
  7442. }
  7443. }