Browse Source

+ Initial import

yuri 21 years ago
parent
commit
5785fe3801
3 changed files with 2632 additions and 0 deletions
  1. 759 0
      packages/extra/os2units/wpstk/wpstk.pp
  2. 1576 0
      rtl/os2/so32dll.pas
  3. 297 0
      rtl/os2/sockets.pas

+ 759 - 0
packages/extra/os2units/wpstk/wpstk.pp

@@ -0,0 +1,759 @@
+{
+    $Id$
+    Copyright (c) 2000-2003 by WPS Toolkit Project - Christian Langanke
+    Copyright (c) 2003-2004 by Yuri Prokushev ([email protected])
+
+    Workplace Toolkit API
+
+    This file is part of the WPS Toolkit package and is free software.
+    You can redistribute it and/or modify it under the terms of the GNU
+    Library General Public License as published by the Free Software
+    Foundation, in version 2 as it comes in the "COPYING.LIB" file
+    of the WPS Toolkit main distribution. This library is distributed
+    in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
+    License for more details.
+
+ **********************************************************************}
+
+Unit wpstk;
+
+Interface
+
+{$Mode ObjFpc}
+
+Uses
+  OS2Def, PMWin;
+
+// Please, rename wpstk.dll to another name to avoid version conflicts
+const
+  wpstkdll='wpstk';
+
+Function WtkQueryVersion(pszBuffer: PChar; ulBuflen: Cardinal): Cardinal; cdecl;
+  external wpstkdll name 'WtkQueryVersion';
+
+//*** handle types used by EA manager ***************************************/
+Type
+  LHANDLE=Cardinal;
+  HEA=LHANDLE;
+  PHEA=^HEA;
+
+Const
+  HEA_CREATE=HEA(-1);
+
+//*** EA type wildcard for WtkFindNextEaValue *******************************/
+  WTK_EAT_ANY=-1;
+
+//*** get size of all values of an EA ***************************************/
+Function WtkQueryEaSize(pszName, pszEaName: PChar; var pulSize: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkQueryEaSize';
+
+//*** read complete ea into memory and scan it ******************************/
+Function WtkReadEa(pszName: PChar; pszEaName: PChar; P_HEA: PHEA): Longint; cdecl;
+  external wpstkdll name 'WtkReadEa';
+
+Function WtkFindFirstEaValue(_HEA: HEA; var pulEaType: Cardinal; pszValue: PChar; var pulBuflen: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkFindFirstEaValue';
+
+Function WtkFindNextEaValue(_HEA: HEA; var pulEaType: Cardinal; pszValue: PChar; var pulBuflen: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkFindNextEaValue';
+
+//*** create new EA list in memory ******************************************/
+Function WtkCreateEa(pszName: PChar; pszEaName: PChar; _PHEA: PHEA): Longint; cdecl;
+  external wpstkdll name 'WtkCreateEa';
+
+//*** append a value ********************************************************/
+Function WtkAppendEaValue(HEA_: HEA; ulMultiType: Cardinal; ulEaType: Cardinal; var pbValue: Byte; ulValuelen: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkAppendEaValue';
+
+//*** write EA to disk ******************************************************/
+Function WtkSaveEa(_HEA: HEA; fWriteThru: Longbool; fEA: Byte): Longint; cdecl;
+  external wpstkdll name 'WtkSaveEa';
+
+//*** destroy EA in memory **************************************************/
+Function WtkCloseEa(_HEA: hea): Longint; cdecl;
+  external wpstkdll name 'WtkCloseEa';
+
+//*** WtkGetNextFile alike API, does WtkReadEa/WtkFind*EaValue/WtkCloseEa in one API */
+Function WtkGetNextEaValue(pszName, pszEaName: PChar; var pulEaType: Cardinal; PHEA_: PHEA; pszValue: PChar; var pulBuflen: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkGetNextEaValue';
+
+//*** read/appendWrite EA in one step ***************************************/
+Function WtkPutEaValue(pszName, pszEaName: PChar; ulMultiType, ulEaType: Cardinal; var pbValue: Byte; ulValuelen: Cardinal; fWriteThru: Longbool; fEA: Byte): Longint; cdecl;
+  external wpstkdll name 'WtkPutEaValue';
+
+//*** simplified APIs to read/write exatcly one string EA********************/
+Function WtkWriteStringEa(pszName, pszEaName, pszEaValue: PChar): Longint; cdecl;
+  external wpstkdll name 'WtkWriteStringEa';
+Function WtkReadStringEa(pszName, pszEaName, pszEaValue: PChar; var pulBuflen: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkReadStringEa';
+
+Const
+  WTK_CFGSYS_UPDATE_ADD=0;
+  WTK_CFGSYS_UPDATE_DELETE=1;
+
+Function WtkUpdateConfigsys(pszUpdate: PChar; ulUpdateMode: Cardinal; pszBackupExtension: PChar): Longint; cdecl;
+  external wpstkdll name 'WtkUpdateConfigsys';
+
+//* file handle type and structures */
+Type
+  HINIT=LHANDLE;
+  PHINIT=^HINIT;
+
+
+// structure to override default behaviour of parser
+  TINITPARMS=record
+    // specify all valid comment characters
+    // - specify nil to use ';' as default and only comment character
+    // - specify '/' to use "//" (c++ style comments)
+    pszCommentChars: PChar;
+    // specify all valid delimiter characters
+    // - specify nil to use '=' as default and only delimiter character
+    // - when multiple characters are specified, the first will be used
+    //   for new entries
+    pszDelimiterChars: PChar;
+    // define layout for keys in new files
+    // (if keys already exist, the layout of
+    //  the last read key is used)
+    //
+    // [SECTION]
+    //
+    //      newkeyname1   =   keyvalue1
+    // |   |  -> ulKeyIndent
+    //
+    //      newkeyname2   =   keyvalue2
+    //      |            | ->  ulKeyNameLen
+    //
+    //      newkeyname3   =   keyvalue3
+    //                     | | -> ulValueIndent
+    ulKeyIndent,
+    ulKeyNameLen,
+    ulValueIndent: Cardinal;
+  end;
+  PINITPARMS=^TINITPARMS;
+
+//* define open modes (WtkOpenInitProfile - ulOpenMode) */
+Const
+  WTK_INIT_OPEN_READONLY=$0000;
+  WTK_INIT_OPEN_READWRITE=$0001;
+
+  WTK_INIT_OPEN_ALLOWERRORS=$8000;
+  WTK_INIT_OPEN_INMEMORY=$FFFF;
+
+//* define update modes (WtkOpenInitProfile - ulUpdateMode) */
+  WTK_INIT_UPDATE_DISCARDCOMMENTS=$0001;
+  WTK_INIT_UPDATE_SOFTDELETEKEYS=$0002;
+
+//* open and close file */
+Function WtkOpenInitProfile(pszName: PChar; var phinit: HINIT; ulOpenMode: Cardinal;
+                          ulUpdateMode: Cardinal; pip: PINITPARMS): Longint; cdecl;
+  external wpstkdll name 'WtkOpenInitProfile';
+
+Function WtkCloseInitProfile(HINIT: HINIT; fUpdate: Longbool): Longint; cdecl;
+  external wpstkdll name 'WtkCloseInitProfile';
+
+const
+  WTK_INIT_CLOSE_DISCARD=0;
+  WTK_INIT_CLOSE_UPDATE=1;
+
+Function WtkCloseInitProfileBackup(_hinit: HINIT; fUpdateOriginal: Longbool; pszBackupFile: PChar): Longint; cdecl;
+  external wpstkdll name 'WtkCloseInitProfileBackup';
+Function WtkInitProfileModified(_hinit: HINIT): Longbool; cdecl;
+  external wpstkdll name 'WtkInitProfileModified';
+
+//* query values */
+Function WtkQueryInitProfileString(_HINIT: hinit; pszSectionName, pszKeyName, pszDefault, pszBuffer: PChar; ulBuflen: Cardinal): Cardinal; cdecl;
+  external wpstkdll name 'WtkQueryInitProfileString';
+Function WtkQueryInitProfileSize(_HINIT: hinit; pszSectionName, pszKeyName: PChar; var pulDataLen: Cardinal): Longbool; cdecl;
+  external wpstkdll name 'WtkQueryInitProfileSize';
+
+//* update or delete keys and/or sections */
+Function WtkWriteInitProfileString(_HINIT: hinit; pszSectionName, pszKeyName, pszNewValue: PChar): Longint; cdecl;
+  external wpstkdll name 'WtkWriteInitProfileString';
+
+//* file handle type and structures */
+
+Type
+  HSYSLEVEL = LHANDLE;
+  PHSYSLEVEL = ^HSYSLEVEL;
+
+Const
+  WTK_SYSLEVEL_MAXLEN_COMPID = 9;
+  WTK_SYSLEVEL_MAXLEN_NAME = 79;
+  WTK_SYSLEVEL_MAXLEN_PREFIX = 2;
+  WTK_SYSLEVEL_MAXLEN_CSDNUM = 4;
+  WTK_SYSLEVEL_MAXLEN_APPTYPE = 8;
+
+//* external data structure                 */
+//* NOTE:                                   */
+//*  - read/write version fields in hex     */
+//*  - use the WTK_SYSLEVEL_MAXLEN_* with   */
+//*    strncpy() to properly copy strings   */
+//*    to string fields (see sample !)      */
+
+Type
+  TSYLEVELINFO = record
+    cbSize : Cardinal;
+    usSysId : Word;
+    szComponentId : array[0..(WTK_SYSLEVEL_MAXLEN_COMPID + 1)-1] of CHAR;
+    szName : array[0..(WTK_SYSLEVEL_MAXLEN_NAME + 1)-1] of CHAR;
+    bVersionMajor : BYTE;
+    bVersionMinor : BYTE;
+    bVersionRefresh : BYTE;
+    szCsdPrefix : array[0..(WTK_SYSLEVEL_MAXLEN_PREFIX + 1)-1] of CHAR;
+    chCsdLanguage : CHAR;
+    szCurrentCsd : array[0..(WTK_SYSLEVEL_MAXLEN_CSDNUM + 1)-1] of CHAR;
+    szPreviousCsd : array[0..(WTK_SYSLEVEL_MAXLEN_CSDNUM + 1)-1] of CHAR;
+    usDate : Word;
+    szAppType : array[0..(WTK_SYSLEVEL_MAXLEN_APPTYPE + 1)-1] of CHAR;
+  end;
+  PSYLEVELINFO = ^TSYLEVELINFO;
+
+Function WtkOpenSyslevel(pszName: PChar; var phsl: HSYSLEVEL): Longint; cdecl;
+  external wpstkdll name 'WtkOpenSyslevel';
+Function WtkCloseSyslevel(hsl: HSYSLEVEL; ulUpdateMode: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkCloseSyslevel';
+
+Const
+  WTK_SYSLEVEL_CLOSE_DISCARD = 0;
+  WTK_SYSLEVEL_CLOSE_UPDATE = 1;
+
+Function WtkQuerySyslevelInfo(hsl: HSYSLEVEL; var psli: TSYLEVELINFO): Longint; cdecl;
+  external wpstkdll name 'WtkCloseSyslevel';
+Function WtkSetSyslevelInfo(hsl: HSYSLEVEL; ulUpdateFlags: Cardinal; var psli: TSYLEVELINFO): Longint; cdecl;
+  external wpstkdll name 'WtkCloseSyslevel';
+
+Const
+  WTK_SYSLEVEL_UPDATE_ALL = -(1);
+  WTK_SYSLEVEL_UPDATE_SYSID = $00000001;
+  WTK_SYSLEVEL_UPDATE_COMPONENTID = $00000002;
+  WTK_SYSLEVEL_UPDATE_NAME = $00000004;
+  WTK_SYSLEVEL_UPDATE_VERSION = $00000008;
+  WTK_SYSLEVEL_UPDATE_CSDPREFIX = $00000010;
+  WTK_SYSLEVEL_UPDATE_CSDLANGUAGE = $00000020;
+  WTK_SYSLEVEL_UPDATE_CURRENTCSD = $00000040;
+  WTK_SYSLEVEL_UPDATE_PREVIOUSCSD = $00000080;
+  WTK_SYSLEVEL_UPDATE_DATE = $00000010;
+  WTK_SYSLEVEL_UPDATE_APPTYPE = $00000020;
+
+  {* flags for MmfAlloc parm ulOpenFlags                                       */ }
+  {* NOTE: for all except MMF_ACCESS_READWRITE, only write by others is denied */ }
+  {*       otherwise both read and write by others is denied                   */ }
+  MMF_ACCESS_READONLY = $00000000;
+  MMF_ACCESS_WRITEONLY = $00000001;
+  MMF_ACCESS_READWRITE = $00000002;
+  MMF_OPENMODE_OPENFILE = $00000000;
+  MMF_OPENMODE_RESETFILE = $00010000;
+
+  {* some sizes for usage with MmfAlloc parameter ulMaxSize */ }
+  MMF_MAXSIZE_KB = 1024;
+  MMF_MAXSIZE_MB = 1048576;
+
+  {* special NULL filename for MmfAlloc parameter pszFilename */ }
+  MMF_FILE_INMEMORY = nil;
+  {* define a handle type */ }
+
+//* define a handle type */
+Type
+  THMMF = LHANDLE;
+  PHMMF = ^THMMF;
+
+//* prototypes */
+Function WtkInitializeMmf(var phmmf: THMMF; ulMaxBuffer: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkInitializeMmf';
+Function WtkTerminateMmf(hmmf: THMMF): Longint; cdecl;
+  external wpstkdll name 'WtkTerminateMmf';
+Function WtkAllocMmf(hmmf: THMMF; Var ppvdata: Pointer; pszFilename: PChar; ulOpenFlags, ulMaxSize: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkAllocMmf';
+Function WtkFreeMmf(hmmf: THMMF; pvData: Pointer): Longint; cdecl;
+  external wpstkdll name 'WtkFreeMmfl';
+Function WtkUpdateMmf(hmmf: THMMF; pvData: Pointer): Longint; cdecl;
+  external wpstkdll name 'WtkUpdateMmf';
+
+Function WtkSetMmfSize(hmmf: THMMF; pvData: Pointer; ulNewSize: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkSetMmfSize';
+Function WtkQueryMmfSize(hmmf: THMMF; pvData: Pointer; var pulSize: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkQueryMmfSize';
+
+//* only be used for string translation for indexed */
+//* values by callback STM_CALLBACK_QUERYSTRING     */
+Const
+  _STM_MAX_SETTINGSVALUE = 64;
+
+//*** handle types used by Setting manager **********************************/
+Type
+  HSETTINGTABLE = LHANDLE;
+  HVALUETABLE = LHANDLE;
+
+//*** callback procedure prototype ******************************************/
+Type
+  TFnCB=Function(ulAction: Cardinal; pvData, pvObjectInstance, pvObjectData: Pointer): Longbool; cdecl;
+  PFNCB = ^TFnCB;
+
+//*** callback actions ******************************************************/
+
+Const
+  { reports that class is being initialized          }
+  STM_CALLBACK_REPORTINIT = $0000;
+  { queries infos about (sub)value                   }
+  STM_CALLBACK_QUERYVALUEINFO = $0001;
+  { queries target buffer when creating value table  }
+  STM_CALLBACK_QUERYTARGETBUF = $0002;
+  { ask WPS class to validate a (sub)value           }
+  STM_CALLBACK_VALIDATE = $0003;
+  { reports the change of a setting                  }
+  STM_CALLBACK_REPORTCHANGED = $0004;
+  { asks for update of target buffers                }
+  STM_CALLBACK_QUERYVALUE = $0005;
+  { translates strings to array indicees             }
+  STM_CALLBACK_QUERYINDEX = $0006;
+  { translates strings to array indicees             }
+  STM_CALLBACK_QUERYSTRING = $0007;
+  { asks for initialization of GUI controls,         }
+  STM_CALLBACK_INITCONTROL = $0008;
+  { useful for listboxes comboboxes etc.             }
+  { reports errors from WtkValidateObjectValueTable  }
+  STM_CALLBACK_REPORTERROR = $0009;
+  { reports that settings have been saved            }
+  STM_CALLBACK_REPORTSAVED = $000A;
+  { reports that class settings table is destroyed   }
+  STM_CALLBACK_REPORTDESTROYED = $000B;
+
+//*** data structure for callback STM_CALLBACK_REPORTINIT *************/
+//*** Note: on this callback, pvObjectInstance and pvObjectData are NULL ****/
+Type
+  TCBREPORTINIT = record
+    fInitialized : Longbool; //*  no data really required here yet       */
+  end;
+
+//*** data structures for callback STM_CALLBACK_QUERYVALUEINFO ********/
+//*** Note: on this callback, pvObjectInstance and pvObjectData are NULL ****/
+  TCBQUERYVALUEINFO = record
+    pszName : PChar;                     //* out - name of setting                   */
+    ulSettingId : Cardinal;              //* out - id of setting                     */
+    ulValueIndex : Cardinal;             //* out - index of subvalue                 */
+    ulValueType : Cardinal;              //* #in - type of value - see VALUETYPE_*   */
+    usDialogid : Word;                   //*  in - id of dialog containing control   */
+    usControlid : Word;                  //*  in - id of control                     */
+    pfnwpSubclass : proc;               //*  in - subclass window proc for control  */
+    pszDetailsTitle : PChar;             //*  in - title of folderdetails view       */
+  end;
+  PCBQUERYVALUEINFO = ^TCBQUERYVALUEINFO;
+
+//*** data structures for callback CALLBACK_QUERYTARGETBUF ************/
+//* values marked with # MUST be specified, all others are optional */
+
+Type
+  TCBQUERYTARGETBUF = record
+    pvObjectInstance : Pointer; //* out - somSelf of object instance        */
+    pszName : PChar;            //* out - name of setting                   */
+    ulSettingId : Cardinal;     //* out - id of setting                     */
+    ulValueIndex : Cardinal;    //* out - index of subvalue (only > 0 for multivalue settings)   */
+    ulBufMax : Cardinal;        //* #in - len of target buffer              */
+    pvTarget : Pointer;         //* #in - target buffer                     */
+  end;
+  PCBQUERYTARGETBUF = ^TCBQUERYTARGETBUF;
+
+//* supported GUI controls:                                                             */
+//* - WC_ENTRYFIELD WC_MLE WC_BUTTON (checkbox and radio button)                        */
+//* - WC_LISTBOX WC_COMBOBOX WC_SPINBUTTON                                              */
+//* - WC_SLIDER WC_CIRCULARSLIDER                                                       */
+
+//* types of possible values                                                            */
+//*                                                                                     */
+//* type          validation target buffer possible GUI update                          */
+//* ------------- ---------- ------------- -------------------------------              */
+//* STRING        NO         CHAR[]        <all supported> except WC_*SLIDER            */
+//*                                        - WC_COMBOBOX, WC_SPINBUTTON as listbox      */
+//* INDEX         YES        LONG          <all supported>                              */
+//* ITEM          YES        LONG          selects item with WC_LISTBOX, WC_COMBOBOX,   */
+//*                                        behaves like LONG otherwise                  */
+//* LONG          NO         LONG          <all supported>                              */
+//* TRUEFALSE     YES        BOOL          <all supported> except WC_*SLIDER            */
+//* YESNO         YES        BOOL          <all supported> except WC_*SLIDER            */
+//* ONOFF         YES        BOOL          <all supported> except WC_*SLIDER            */
+
+
+//*** value types for value target buffers **********************************/
+Const
+  STM_VALUETYPE_STRING = 0;
+  STM_VALUETYPE_INDEX = 1;
+  STM_VALUETYPE_LONG = 2;
+  STM_VALUETYPE_TRUEFALSE = 3;
+  STM_VALUETYPE_YESNO = 4;
+  STM_VALUETYPE_ONOFF = 5;
+  { for details only !  }
+  STM_VALUETYPE_CDATE = 6;
+  { for details only !  }
+  STM_VALUETYPE_CTIME = 7;
+  STM_VALUETYPE_INDEXITEM = 8;
+
+//*** data structures for callback CALLBACK_VALIDATION ****************/
+Type
+  TCBVALIDATE = record
+    pvObjectInstance : Pointer; //* out - somSelf of object instance        */
+    ulSettingId : Cardinal;     //* out - id of setting                     */
+    pszName : PChar;            //* out - name of setting                   */
+    pszValue : PChar;           //* out - name of value to be validated     */
+    ulValueIndex : Cardinal;    //* out - index of subvalue                 */
+    fResult : Longbool;         //*  in - result of validation              */
+  end;                          //* return TRUE if your callback validates, */
+  PCBVALIDATE = ^TCBVALIDATE;   //* FALSE for using standard validation     */
+
+//*** data structures for callback CALLBACK_REPORTCHANGED ****************/
+Type
+  TCBREPORTCHANGED = record
+    pvObjectInstance : Pointer; //* out - somSelf of object instance        */
+    ulSettingId : Cardinal;     //* out - id of setting                     */
+    pszName : PChar;            //* out - name of setting                   */
+  end;
+  PCBREPORTCHANGED = ^TCBREPORTCHANGED;
+
+//*** data structures for callback CALLBACK_QUERYVALUE ****************/
+  TCBQUERYVALUE = record
+    pvObjectInstance : Pointer; //* out - somSelf of object instance        */
+    ulSettingId : Cardinal;     //* out - id of setting                     */
+    pszName : PChar;            //* out - name of setting                   */
+    ulQueryIndex : Cardinal;    //* out - index of query                    */
+  end;
+  PCBQUERYVALUE = ^TCBQUERYVALUE;
+
+//*** data structures for callback CALLBACK_QUERYINDEX ****************/
+  TCBQUERYINDEX = record
+    pvObjectInstance : Pointer; //* out - somSelf of object instance        */
+    ulSettingId : Cardinal;     //* out - id of setting                     */
+    pszName : PChar;            //* out - name of setting                   */
+    pszValue : PChar;           //* out - string value to be translated     */
+    ulValueIndex : Cardinal;    //* out - index of subvalue                 */
+    ulStringIndex : Cardinal;   //*  in - index to be used                  */
+  end;                          //* return TRUE if processed, else FALSE    */
+  PCBQUERYINDEX = ^TCBQUERYINDEX;
+
+//*** data structures for callback CALLBACK_QUERYSTRING ***************/
+  TCBQUERYSTRING = record
+    pvObjectInstance : Pointer;                            // out - somSelf of object instance        */
+    ulSettingId : Cardinal;                                // out - id of setting                     */
+    pszName : PChar;                                       // out - name of setting                   */
+    ulStringIndex : Cardinal;                              // out - index to be translated            */
+    ulValueIndex : Cardinal;                               // out - index of subvalue                 */
+    szValue : array[0..(_STM_MAX_SETTINGSVALUE)-1] of CHAR;// in - string value to be used      */
+  end;                                                     // return TRUE if processed, else FALSE    */
+  PCBQUERYSTRING = ^TCBQUERYSTRING;
+
+//*** data structures for callback CALLBACK_INITCONTROL ***************/
+  TCBINITCONTROL = record
+    usDialogid : Word;  //* out - id of dialog                      */
+    usControlid : Word; //* out - id of control                     */
+    hwndDialog : HWND;  //* out - handle of dialog                  */
+    hwndControl : HWND; //* out - handle of control                 */
+  end;
+  PCBINITCONTROL = ^TCBINITCONTROL;
+
+//*** data structures for callback STM_CALLBACK_REPORTERROR ***********/
+  TCBREPORTERROR = record
+    pvObjectInstance : Pointer; //* out - somSelf of object instance        */
+    ulSettingId : Cardinal;     //* out - id of setting                     */
+    pszName : PChar;            //* out - name of setting                   */
+    usDialogid : Word;          //* out - id of dialog                      */
+    usControlid : Word;         //* out - id of control                     */
+    hwndDialog : HWND;          //* out - handle of dialog                  */
+    hwndControl : HWND;         //* out - handle of control                 */
+  end;                          //* return TRUE to ignore error             */
+  PCBREPORTERROR = ^TCBREPORTERROR;
+
+//*** data structures for callback STM_CALLBACK_REPORTSAVED ***********/
+  TCBREPORTSAVED = record
+    fSaved : Longbool; //*  no data really required here yet       */
+  end;
+  PCBREPORTSAVED = ^TCBREPORTSAVED;
+
+//*** data structures for callback STM_CALLBACK_DESTROYED *************/
+//*** Note: on this callback, pvObjectInstance and pvObjectData are NULL ***/
+  TCBREPORTDESTROYED = record
+    fDestroyed : Longbool; //*  no data really required here yet       */
+  end;
+  PCBREPORTDESTROYED = ^TCBREPORTDESTROYED;
+
+// ----------------------------------------
+// prototypes
+// ----------------------------------------
+
+//*** prototypes for (de)initializing the settings table for the metaclass **/
+Function WtkCreateClassSettingsTable(pvObjectClass: Pointer; pfnCallbackValue: PFNCB): HSETTINGTABLE; cdecl;
+  external wpstkdll name 'WtkCreateClassSettingsTable';
+Function WtkDestroyClassSettingsTable(hst: HSETTINGTABLE): Longbool; cdecl;
+  external wpstkdll name 'WtkDestroyClassSettingsTable';
+Function WtkAddClassSetting(hst: HSETTINGTABLE; ulSettingId: Cardinal; pszSetting: Pchar; ulQueryCount: Cardinal): Longbool; cdecl;
+  external wpstkdll name 'WtkAddClassSetting';
+Function WtkAddClassDetail(hst: HSETTINGTABLE; ulSettingId: Cardinal): Longbool; cdecl;
+  external wpstkdll name 'WtkAddClassDetail';
+Function WtkCloseClassSettingsTable(hst: HSETTINGTABLE): Longbool; cdecl;
+  external wpstkdll name 'WtkCloseClassSettingsTable';
+Function WtkDumpClassSettingsTable(hst: HSETTINGTABLE): Longbool; cdecl;  // for testing purposes only, dumps to console
+  external wpstkdll name 'WtkDumpClassSettingsTable';
+
+//*** prototypes for maintaining setting values for object instances ********/
+Function WtkCreateObjectValueTable(hst: HSETTINGTABLE; pvObjectInstance, pvObjectData: Pointer): HVALUETABLE; cdecl;
+  external wpstkdll name 'WtkCreateObjectValueTable';
+Function WtkDestroyObjectValueTable(hvt: HVALUETABLE): Longbool; cdecl;
+  external wpstkdll name 'WtkDestroyObjectValueTable';
+Function WtkEvaluateObjectSettings(hvt: HVALUETABLE; pszSetup: PChar): Longbool; cdecl;
+  external wpstkdll name 'WtkEvaluateObjectSettings';
+Function WtkQueryObjectSettings(hvt: HVALUETABLE; pszBuffer: PChar; var pulMaxlen: Cardinal): Longbool; cdecl;
+  external wpstkdll name 'WtkQueryObjectSettings';
+
+//*** prototypes for providing automatic updates to GUI controls ************/
+Function WtkRegisterSettingsDialog(hvt: HVALUETABLE; hwndDialog: HWND): Longbool; cdecl;
+  external wpstkdll name 'WtkRegisterSettingsDialog';
+Function WtkDeregisterSettingsDialog(hvt: HVALUETABLE; hwndDialog: HWND): Longbool; cdecl;
+  external wpstkdll name 'WtkDeregisterSettingsDialog';
+Function WtkReadObjectValueTable(hvt: HVALUETABLE; hwndDialog: HWND): Longbool; cdecl;
+  external wpstkdll name 'WtkReadObjectValueTable';
+Function WtkWriteObjectValueTable(hvt: HVALUETABLE; hwndDialog: HWND): Longbool; cdecl;
+  external wpstkdll name 'WtkWriteObjectValueTable';
+Function WtkQueryGUIControlsChanged(hvt: HVALUETABLE; hwnd_: HWND; mp1, mp2:MPARAM; var pfOrgValue: Longbool): Longbool; cdecl;
+  external wpstkdll name 'WtkQueryGUIControlsChanged';
+
+//*** prototype for using same dialog templates under WARP 3 and WARP 4 *****/
+Function WtkRelocateNotebookpageControls(hwndDialog: HWND): Longbool; cdecl;
+  external wpstkdll name 'WtkRelocateNotebookpageControls';
+
+//*** prototypes for providing automatic validation of controls   *************/
+//*** on close of settings notebook.                              *************/
+//*** NOTE: WtkValidateObjectValueTable needs not to be           *************/
+//***       explicitely called for this, but is avaliable anyway. *************/
+Function WtkRegisterSettingsNotebook(hvt: HVALUETABLE; hwndNotebook: HWND): Longbool; cdecl;
+  external wpstkdll name 'WtkRegisterSettingsNotebook';
+Function WtkValidateObjectValueTable(hvt: HVALUETABLE; hwndNotebook: HWND): Longbool; cdecl;
+  external wpstkdll name 'WtkValidateObjectValueTable';
+
+//*** prototypes for providing details data *********************************/
+Function WtkQueryClassDetailsInfo(hst: HSETTINGTABLE; var ppClassFieldInfo: Pointer;
+                                         var pSize: Cardinal; ulParentColumns: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkQueryClassDetailsInfo';
+Function WtkQueryObjectDetailsData(hvt: HVALUETABLE; var ppDetailsData: Pointer; var pcp: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkQueryObjectDetailsData';
+
+//*** prototypes for saving/restoring data in WPS repository ****************/
+Function WtkSaveObjectState(hvt: HVALUETABLE; pszClass: PChar): Longint; cdecl;
+  external wpstkdll name 'WtkSaveObjectState';
+Function WtkRestoreObjectState(hvt: HVALUETABLE; pszClass: PChar): Longint; cdecl;
+  external wpstkdll name 'WtkRestoreObjectState';
+
+//*** prototypes for saving/restoring data in extern ini file ***************/
+//*** NOTE: you have to make sure yourself that you save to   ***************/
+//***       a unique place per object instance !!!            ***************/
+//*** NOTE: specify USER or SYSTEM as filename to write to    ***************/
+//***       HINI_USERPROFILE or HINI_SYSTEMPROFILE            ***************/
+Function WtkSaveObjectSettings(hvt: HVALUETABLE; pszFilename, pszApp, pszKey: PChar): Longint; cdecl;
+  external wpstkdll name 'WtkSaveObjectSettings';
+Function WtkRestoreObjectSettings(hvt: HVALUETABLE; pszFilename, pszApp, pszKey: PChar): Longint; cdecl;
+  external wpstkdll name 'WtkRestoreObjectSettings';
+
+Function WtkGetTextMessage(var pTable: PChar; cTable: Cardinal;
+                                   var pbBuffer: Byte; cbBuffer: Cardinal;
+                                   pszMessageName, pszFile: PChar;
+                                   var pcbMsg: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkGetTextMessage';
+
+// data structures for 32-bit memory model
+
+Type
+  TBINDATA = record
+    cbSize : Cardinal;
+    bData : array[0..0] of BYTE;
+  end;
+  PBINDATA = ^TBINDATA;
+
+//*** prototypes for calculating CRC of data in memory *******************/
+//*** initialize pulCRC32 with -1 on first call **************************/
+Function WtkCalcMemCRC32(pvData: Pointer; ulDatalen: Cardinal; var pulCRC32: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkCalcMemCRC32';
+
+//*** prototypes for calculating CRC of files ****************************/
+Function WtkCalcFileCRC32(pszFilename: PChar; var pulCRC32: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkCalcFileCRC32';
+
+//*** prototypes for general functions **************************************/
+Function WtkQueryClassIndex(HWND_: hwnd): PChar; cdecl;
+  external wpstkdll name 'WtkQueryClassIndex';
+Function WtkIsOfPublicPmClass(HWND_: hwnd; pszClassIndex: PChar; ulPrimaryWindowStyle: Cardinal): Longbool; cdecl;
+  external wpstkdll name 'WtkIsOfPublicPmClass';
+
+//*** prototypes for specialized functions for certain window classes *******/
+Function WtkInitializeNumSpinbuttonArray(hwndSpinbutton: HWND; ulMinValue: Cardinal;
+                                               ulMaxValue: Cardinal; ulStep: Cardinal): Longbool; cdecl;
+  external wpstkdll name 'WtkInitializeNumSpinbuttonArray';
+Function WtkQueryNumSpinbuttonIndex(hwndSpinbutton: HWND; ulMinValue: Cardinal;
+                                 ulMaxValue: Cardinal; ulStep: Cardinal; ulValue: Cardinal): Longint; cdecl;
+  external wpstkdll name 'WtkQueryNumSpinbuttonIndex';
+
+//*** prototypes for filling MLEs from diverse resources ********************/
+Function WtkAddTextResourceToMLE(HWND_: hwnd; ulControlId: Cardinal;
+                              hmod: Cardinal;  ulResourceType, ulResId: Cardinal): Longbool; cdecl;
+  external wpstkdll name 'WtkAddTextResourceToMLE';
+
+//*** prototypes for PM error functions *************************************/
+Function WtkSetErrorInfo(rc: Cardinal): Longbool; cdecl;
+  external wpstkdll name 'WtkSetErrorInfo';
+
+Const
+  PMHERR_USE_EXISTING_ERRORINFO = -(1);
+
+//*** check existance of files & directories ********************************/
+Function WtkFileExists(pszName: PChar): Longbool;
+Function WtkDirExists(pszName: PChar): Longbool;
+Function WtkFileMaskExists(pszFileMask, pszFirstFile: PChar; ulBuflen: Cardinal): Longbool;
+Function WtkIsFile(pszName: PChar): Longbool;      (* equivalent to WtkFileExists *)
+Function WtkIsDirectory(pszName: PChar): Longbool; (* equivalent to WtkDirExists  *)
+
+//*** get fullname of directory or file *************************************/
+Function WtkQueryFullname(pszName, pszBuffer: PChar; ulBuflen: Cardinal): Longint;
+
+//*** extended file handling ************************************************/
+Function WtkDeleteFile(pszName: PChar): Longint;
+Function WtkMoveFile(pszOld, pszNew: PChar): Longint;
+
+//*** query disk and directory at one time **********************************/
+Function WtkQueryCurrentDir(ulDiskNum: Cardinal; pszBuffer: PChar; ulBuflen: Cardinal): Longint;
+Function WtkSetCurrentDir(pszDirectory: PChar): Longint;
+
+//*** create/delete path ****************************************************/
+Function WtkCreatePath(pszPath: PChar): Longint;
+Function WtkDeletePath(pszPath: PChar): Longint;
+
+//*** easy version of DosFindFirst/DosFindNext ******************************/
+Function WtkGetNextFile(pszFileMask: PChar; phdir: PHDIR;
+                                pszNextFile: PChar; ulBuflen: Cardinal): Longint;
+Function WtkGetNextDirectory(pszFileMask: PChar; phdir: PHDIR;
+                             pszNextDirectory: PChar; ulBuflen: Cardinal): Longint;
+
+//*** search part of filename ***********************************************/
+Function WtkFilespec(pszName: PChar; ulPart: Cardinal): PChar;
+
+Const
+  WTK_FILESPEC_PATHNAME = 1;
+  WTK_FILESPEC_NAME = 2;
+  WTK_FILESPEC_EXTENSION = 3;
+
+//*** get specific information about file ***********************************/
+Function WtkFileModified(pszName: PChar; pfs3: PFILESTATUS3): Longbool;
+Function WtkQueryFileSize(pszName: PChar): Cardinal;
+
+//*** read file into memory  ************************************************/
+Function WtkReadFile(pszName: PChar; ppszBuffer: PPChar; pulBuflen: PCardinal): Longint;
+Function WtkWriteFile(pszName, pszBuffer: PChar; ulBuflen: Cardinal; fAppend: Longbool): Longint;
+
+//*** create tmp file *******************************************************/
+Function WtkCreateTmpFile(pszFileMask, pszBuffer: PChar; ulBuflen: Cardinal): Longint;
+
+//*** check file contents ***************************************************/
+Function WtkFileIsEmpty(pszName: PChar): Longbool;
+
+//*** prototypes for opening devices ****************************************/
+Function WtkOpenDevice(pszName: PChar; phdevice: PHFILE; ulOpenMode: Cardinal): Longint;
+
+Const
+  WTK_OPENDEVICE_SHARED = $0000;
+  WTK_OPENDEVICE_EXCLUSIVE = $0001;
+  WTK_OPENDEVICE_NOCACHE = $0002;
+  { implicitely set, when pszName specifies drive  }
+  WTK_OPENDEVICE_BLOCKDEVICE = $0004;
+
+//*** prototypes for performing an I/o Control transaction ******************/
+Function WtkDevIOCtl(pszName: PChar; ulOpenMode: Cardinal;
+                             ulCategory: Cardinal; ulFunction: Cardinal;
+                             pvParams: Pointer; pcbParmLen: PCardinal;
+                             pvData: Pointer; pcbDataLen: PCardinal): Longint;
+
+//*** prototypes for module information functions ***************************/
+APIRET APIENTRY WtkGetPackageFilename( PFN pfn, PChar pszSubdir, PChar pszFilename,
+                              PChar pszFileext, PChar pszBuffer, ULONG ulBuflen);
+APIRET APIENTRY WtkGetModuleInfo( PFN pfn, PHMODULE phmod, PChar pszBuffer, ULONG ulBuflen);
+APIRET APIENTRY WtkGetModulePath( PFN pfn, PChar pszBuffer, ULONG ulBuflen);
+HMODULE APIENTRY WtkGetModuleHandle( PFN pfn);
+
+BOOL APIENTRY WtkIsRegularExpressionValid( PChar pszExpression);
+APIRET APIENTRY WtkMatchRegularExpression( PChar pszExpression, PChar pszText,
+                                           PChar pszBuffer, ULONG ulBuflen);
+APIRET APIENTRY WtkSubstRegularExpressionMatch( PChar pszExpression, PChar pszText,
+                                                PChar pszReplacePattern,
+                                                PChar pszBuffer, ULONG ulBuflen);
+
+//*** prototypes for system configuration functions *************************/
+Function WtkIsWarp4: Longbool; cdecl;
+  external wpstkdll name 'WtkIsWarp4';
+
+// distinct between OS/2 Warp and eComStation
+Function WtkQueryOperatingSystem: Cardinal; cdecl;
+  external wpstkdll name 'WtkQueryOperatingSystem';
+
+Const
+  WTK_OSTYPE_OS2 = $0000;
+  WTK_OSTYPE_ECS = $0001;
+
+Function WtkIsOS2: Longbool; cdecl;
+  external wpstkdll name 'WtkIsOS2';
+Function WtkIseComStation: Longbool; cdecl;
+  external wpstkdll name 'WtkIseComStation';
+
+Function WtkQueryBootDrive: Char; cdecl;
+  external wpstkdll name 'WtkQueryBootDrive';
+Function WtkQuerySysLanguage: PChar; cdecl;
+  external wpstkdll name 'WtkQuerySysLanguage';
+
+Function WtkReboot: Cardinal; cdecl;
+  external wpstkdll name 'WtkReboot';
+
+
+//*** prototypes for DATETIME struct handling ****************************/
+BOOL APIENTRY WtkSetDateTime( UCHAR uchDay, UCHAR uchMonth, USHORT usYear, UCHAR uchHours,
+                              UCHAR uchMinutes, UCHAR uchSeconds, PDATETIME pdt);
+BOOL APIENTRY WtkDateTimeToTime( PDATETIME pdt, time_t* ptime);
+BOOL APIENTRY WtkTimeToDateTime( time_t* ptime, PDATETIME pdt);
+
+//*** prototypes for FTIME FDATE struct handling *************************/
+BOOL APIENTRY WtkSetFDateTime( UCHAR uchDay, UCHAR uchMonth, USHORT usYear, UCHAR uchHours,
+                               UCHAR uchMinutes, UCHAR uchSeconds, PFDATE pfdate, PFTIME pftime);
+BOOL APIENTRY WtkFDateTimeToTime( PFDATE pfdate, PFTIME pftime, time_t* ptime);
+BOOL APIENTRY WtkTimeToFDateTime( time_t* ptime, PFDATE pfdate, PFTIME pftime);
+
+//*** prototypes for CDATE/CTIME struct handling ****************************/
+BOOL APIENTRY WtkSetCDateTime( UCHAR uchDay, UCHAR uchMonth, USHORT usYear, UCHAR uchHours,
+                               UCHAR uchMinutes, UCHAR uchSeconds, PCDATE pcdate, PCTIME pctime);
+BOOL APIENTRY WtkCDateTimeToTime( PCDATE pcdate, PCTIME pctime, time_t* ptime);
+BOOL APIENTRY WtkTimeToCDateTime( time_t* ptime, PCDATE pcdate, PCTIME pctime);
+
+//*** prototypes for getting a timestamp *********************************/
+Const
+  WTK_TIMESTAMP_SORTEDDATETIME = 0;
+  WTK_TIMESTAMP_SORTEDDATE = 1;
+  WTK_TIMESTAMP_SORTEDTIME = 2;
+  WTK_TIMESTAMP_NLSDATETIME = 3;
+  WTK_TIMESTAMP_NLSDATE = 4;
+  WTK_TIMESTAMP_NLSTIME = 5;
+
+APIRET APIENTRY WtkQueryDateTimeStamp( PDATETIME pdt, ULONG ulStampType,
+                                                                             PChar pszBuffer, ULONG ulBuflen);
+APIRET APIENTRY WtkQueryFDateTimeStamp( PFDATE pfdate, PFTIME pftime, ULONG ulStampType,
+                                        PChar pszBuffer, ULONG ulBuflen);
+APIRET APIENTRY WtkQueryCDateTimeStamp( PCDATE pcdate, PCTIME pctime, ULONG ulStampType,
+                                        PChar pszBuffer, ULONG ulBuflen);
+
+//*** prototypes for getting last write time from a file or directory ****/
+APIRET APIENTRY WtkQueryFileDateTime( PDATETIME pdt, PChar pszName);
+APIRET APIENTRY WtkQueryFileFDateTime( PFDATE pfdate, PFTIME pftime, PChar pszName);
+APIRET APIENTRY WtkQueryFileCDateTime( PCDATE pcdate, PCTIME pctime, PChar pszName);
+
+
+implementation
+
+end.
+
+{
+$Log$
+Revision 1.1  2004-05-26 16:32:32  yuri
++ Initial import
+
+}

+ 1576 - 0
rtl/os2/so32dll.pas

@@ -0,0 +1,1576 @@
+{
+
+            /c/ 2000, 2001 by madded2 ([email protected]).
+            (C) 2002, 2004 Yuri Prokushev ([email protected]
+
+  Inet & Sockets Unit v1.04.
+  /c/ 2000, 2001 by madded2 ([email protected]).
+  based on units from SIBYL & infos from Toolkit 4.0.
+
+  for help use tcppr.inf and C samples from toolkit.
+
+  without res_* and dh_* funcs, and have very
+  bad suppot for select() and ioctl() funcs
+
+  new in ver 1.04 : little ioctl() & iptrace support + errors SOCE* constants
+  new in ver 1.03 : used inet_lib.lib file for fixing VP linker bug
+  new in ver 1.02 : $saves sections, need for correct registers operations
+  new in ver 1.01 : ip header struct
+
+}
+{
+@abstract(a unit to handle sockets)
+@author(Yuri Prokushev ([email protected]))
+@author(madded2 ([email protected]))
+@created(3 Sep 2002)
+@lastmod(23 Sep 2002)
+@todo(sys/ioctl.h, sys/ioctlos2.h, sys/itypes.h)
+This is functions from SO32DLL.DLL. These functions allows to use
+protocol-independed sockets. Equal to SYS\SOCKET.H, NERRNO.H, SYS\SYSCTL.H.
+}
+unit SO32Dll;
+
+interface
+
+{$MODE ObjFPC}
+{$ASMMODE Intel}
+
+(***************************************************************************)
+(*                                                                         *)
+(*                                     Types                               *)
+(*                                                                         *)
+(***************************************************************************)
+const
+  // stream socket
+  SOCK_STREAM    = 1;
+  // datagram socket
+  SOCK_DGRAM     = 2;
+  // raw-protocol interface
+  SOCK_RAW       = 3;
+  // reliably-delivered message
+  SOCK_RDM       = 4;
+  // sequenced packet stream
+  SOCK_SEQPACKET = 5;
+
+(***************************************************************************)
+(*                                                                         *)
+(*                            Option flags per-socket                      *)
+(*                                                                         *)
+(***************************************************************************)
+const
+  // turn on debugging info recording
+  SO_DEBUG        = $0001;
+  // socket has had listen()
+  SO_ACCEPTCONN   = $0002;
+  // allow local address reuse
+  SO_REUSEADDR    = $0004;
+  // keep connections alive
+  SO_KEEPALIVE    = $0008;
+  // just use interface addresses
+  SO_DONTROUTE    = $0010;
+  // permit sending of broadcast msgs
+  SO_BROADCAST    = $0020;
+  // bypass hardware when possible
+  SO_USELOOPBACK  = $0040;
+  // linger on close if data present
+  SO_LINGER       = $0080;
+  // leave received OOB data in line
+  SO_OOBINLINE    = $0100;
+  // limited broadcast sent on all IFs
+  SO_L_BROADCAST  = $0200;
+  // set if shut down called for rcv
+  SO_RCV_SHUTDOWN = $0400;
+  // set if shutdown called for send
+  SO_SND_SHUTDOWN = $0800;
+  // allow local address & port reuse
+  SO_REUSEPORT    = $1000;
+  // allow t/tcp on socket
+  SO_TTCP         = $2000;
+
+(***************************************************************************)
+(*                                                                         *)
+(*                  Additional options, not kept in so_options             *)
+(*                                                                         *)
+(***************************************************************************)
+const
+  // send buffer size
+  SO_SNDBUF   = $1001;
+  // receive buffer size
+  SO_RCVBUF   = $1002;
+  // send low-water mark
+  SO_SNDLOWAT = $1003;
+  // receive low-water mark
+  SO_RCVLOWAT = $1004;
+  // send timeout
+  SO_SNDTIMEO = $1005;
+  // receive timeout
+  SO_RCVTIMEO = $1006;
+  // get error status and clear
+  SO_ERROR    = $1007;
+  // get socket type
+  SO_TYPE     = $1008;
+  // get socket options
+  SO_OPTIONS  = $1010;
+
+(***************************************************************************)
+(*                                                                         *)
+(*               Structure used for manipulating linger option             *)
+(*                                                                         *)
+(***************************************************************************)
+type
+  //Structure used for manipulating linger option
+  linger = record
+     l_onoff      :  Longint; // option on/off
+     l_linger     : Longint; // linger time
+  end;
+
+(***************************************************************************)
+(*                                                                         *)
+(*      Level number for (get/set)sockopt() to apply to socket itself      *)
+(*                                                                         *)
+(***************************************************************************)
+const
+  // options for socket level
+  SOL_SOCKET = $ffff;
+
+(***************************************************************************)
+(*                                                                         *)
+(*                              Address families                           *)
+(*                                                                         *)
+(***************************************************************************)
+const
+  // unspecified
+  AF_UNSPEC   = 0;
+  // local to host (pipes, portals)
+  AF_LOCAL    = 1;
+  // backward compatibility
+  AF_UNIX     = AF_LOCAL;
+  AF_OS2      = AF_UNIX;
+  // internetwork: UDP, TCP, etc.
+  AF_INET     = 2;
+  // arpanet imp addresses
+  AF_IMPLINK  = 3;
+  // pup protocols: e.g. BSP
+  AF_PUP      = 4;
+  // mit CHAOS protocols
+  AF_CHAOS    = 5;
+  // XEROX NS protocols
+  AF_NS       = 6;
+  // ISO protocols
+  AF_ISO      = 7;
+  // ISO protocols
+  AF_OSI      = AF_ISO;
+  // european computer manufacturers
+  AF_ECMA     = 8;
+  // datakit protocols
+  AF_DATAKIT  = 9;
+  // CCITT protocols, X.25 etc
+  AF_CCITT    = 10;
+  // IBM SNA
+  AF_SNA      = 11;
+  // DECnet
+  AF_DECnet   = 12;
+  // DEC Direct data link interface
+  AF_DLI      = 13;
+  // LAT
+  AF_LAT      = 14;
+  // NSC Hyperchannel
+  AF_HYLINK   = 15;
+  // Apple Talk
+  AF_APPLETALK = 16;
+  // Netbios
+  AF_NB        = 17;
+  // Netbios
+  AF_NETBIOS   = AF_NB;
+  // Link layer interface
+  AF_LINK      = 18;
+  // eXpress Transfer Protocol (no AF)
+  pseudo_AF_XTP = 19;
+  // connection-oriented IP, aka ST II
+  AF_COIP      = 20;
+  // Computer Network Technology
+  AF_CNT       = 21;
+  // Help Identify RTIP packets
+  pseudo_AF_RTIP = 22;
+  // Novell Internet Protocol
+  AF_IPX       = 23;
+  // Simple Internet Protocol
+  AF_SIP       = 24;
+  AF_INET6     = 24;
+  // Help Identify PIP packets
+  pseudo_AF_PIP = 25;
+  // Internal Routing Protocol
+  AF_ROUTE     = 39;
+  // firewall support
+  AF_FWIP      = 40;
+  // IPSEC and encryption techniques
+  AF_IPSEC     = 41;
+  // DES
+  AF_DES       = 42;
+  AF_MD5       = 43;
+  AF_CDMF      = 44;
+
+  AF_MAX       = 45;
+
+(***************************************************************************)
+(*                                                                         *)
+(*             Structure used by kernel to store most addresses            *)
+(*                                                                         *)
+(***************************************************************************)
+type
+  // Structure used by kernel to store most addresses
+  sockaddr = record
+    sa_len:    Byte;                     // total length
+    sa_family: Byte;                     // address family
+    sa_data:   array [0..13] of Byte; // up to 14 bytes of direct address
+  end;
+  psockaddr = ^sockaddr;
+
+(***************************************************************************)
+(*                                                                         *)
+(*  Structure used by kernel to pass protocol information in raw sockets   *)
+(*                                                                         *)
+(***************************************************************************)
+type
+  // Structure used by kernel to pass protocol information in raw sockets
+  sockproto = record
+    sp_family:   Word; // address family
+    sp_protocol: Word; // protocol
+  end;
+
+
+(***************************************************************************)
+(*                                                                         *)
+(*             Protocol families, same as address families for now         *)
+(*                                                                         *)
+(***************************************************************************)
+const
+  PF_UNSPEC    = AF_UNSPEC;
+  PF_LOCAL     = AF_LOCAL;
+  PF_UNIX      = AF_UNIX;
+  PF_OS2       = AF_OS2;
+  PF_INET      = AF_INET;
+  PF_IMPLINK   = AF_IMPLINK;
+  PF_PUP       = AF_PUP;
+  PF_CHAOS     = AF_CHAOS;
+  PF_NS        = AF_NS;
+  PF_ISO       = AF_ISO;
+  PF_OSI       = AF_OSI;
+  PF_ECMA      = AF_ECMA;
+  PF_DATAKIT   = AF_DATAKIT;
+  PF_CCITT     = AF_CCITT;
+  PF_SNA       = AF_SNA;
+  PF_DECnet    = AF_DECnet;
+  PF_DLI       = AF_DLI;
+  PF_LAT       = AF_LAT;
+  PF_HYLINK    = AF_HYLINK;
+  PF_APPLETALK = AF_APPLETALK;
+  PF_NETBIOS   = AF_NB;
+  PF_NB        = AF_NB;
+  PF_ROUTE     = AF_ROUTE;
+  PF_LINK      = AF_LINK;
+  // really just proto family, no AF
+  PF_XTP       = pseudo_AF_XTP;
+  PF_COIP      = AF_COIP;
+  PF_CNT       = AF_CNT;
+  PF_SIP       = AF_SIP;
+  PF_INET6     = AF_INET6;
+  // same format as AF_NS
+  PF_IPX       = AF_IPX;
+  // same format as AF_INET
+  PF_RTIP      = pseudo_AF_RTIP;
+  PF_PIP       = pseudo_AF_PIP;
+
+  PF_MAX       = AF_MAX;
+
+
+(***************************************************************************)
+(*                                                                         *)
+(*  Definitions for sysctl call. The sysctl call uses a hierarchical name  *)
+(* for objects that can be examined or modified.  The name is expressed as *)
+(* a sequence of integers.  Like a file path name, the meaning of each     *)
+(* component depends on its place in the hierarchy. The top-level and kern *)
+(* identifiers are defined here, and other identifiers are defined in the  *)
+(* respective subsystem header files.                                      *)
+(*                                                                         *)
+(***************************************************************************)
+
+const
+// largest number of components supported
+  CTL_MAXNAME    = 12;
+
+(***************************************************************************)
+(*                                                                         *)
+(* Each subsystem defined by sysctl defines a list of variables            *)
+(* for that subsystem. Each name is either a node with further             *)
+(* levels defined below it, or it is a leaf of some particular             *)
+(* type given below. Each sysctl level defines a set of name/type          *)
+(* pairs to be used by sysctl(1) in manipulating the subsystem.            *)
+(*                                                                         *)
+(***************************************************************************)
+
+type
+  ctlname=record
+    ctl_name: PChar;      // subsystem name
+    ctl_type: Longint;    // type of name
+  end;
+
+const
+  // name is a node
+  CTLTYPE_NODE    =1;
+  // name describes an integer
+  CTLTYPE_INT     =2;
+  // name describes a string
+  CTLTYPE_STRING  =3;
+  // name describes a 64-bit number
+  CTLTYPE_QUAD    =4;
+  // name describes a structure
+  CTLTYPE_STRUCT  =5;
+  // inetcfg sysctl code
+  CTLTYPE_INETCFG =6;
+  // inetver sysctl code
+  CTLTYPE_INEVER  =7;
+
+(*
+ * Top-level identifiers
+ *)
+const
+  // "high kernel": proc, limits
+  CTL_KERN       = 1;
+  // network, see socket.h
+  CTL_NET        = 4;
+  // OS/2 specific codes
+  CTL_OS2        = 9;
+
+(*
+
+#define CTL_NAMES { \
+        { 0, 0 }, \
+        { "kern", CTLTYPE_NODE }, \
+        { "net", CTLTYPE_NODE }, \
+        { "os2", CTLTYPE_NODE }, \
+}
+
+/*
+ * CTL_KERN identifiers
+ */
+#define KERN_MAXFILES            7      /* int: max open files */
+#define KERN_HOSTNAME           10      /* string: hostname */
+#define KERN_HOSTID             11      /* int: host identifier */
+
+#define CTL_KERN_NAMES { \
+        { 0, 0 }, \
+        { "ostype", CTLTYPE_STRING }, \
+        { "osrelease", CTLTYPE_STRING }, \
+        { "osrevision", CTLTYPE_INT }, \
+        { "version", CTLTYPE_STRING }, \
+        { "maxvnodes", CTLTYPE_INT }, \
+        { "maxproc", CTLTYPE_INT }, \
+        { "maxfiles", CTLTYPE_INT }, \
+        { "argmax", CTLTYPE_INT }, \
+        { "securelevel", CTLTYPE_INT }, \
+        { "hostname", CTLTYPE_STRING }, \
+        { "hostid", CTLTYPE_INT }, \
+        { "clockrate", CTLTYPE_STRUCT }, \
+        { "vnode", CTLTYPE_STRUCT }, \
+        { "proc", CTLTYPE_STRUCT }, \
+        { "file", CTLTYPE_STRUCT }, \
+        { "profiling", CTLTYPE_NODE }, \
+        { "posix1version", CTLTYPE_INT }, \
+        { "ngroups", CTLTYPE_INT }, \
+        { "job_control", CTLTYPE_INT }, \
+        { "saved_ids", CTLTYPE_INT }, \
+        { "boottime", CTLTYPE_STRUCT }, \
+}
+
+/*
+ * KERN_SYSCTL objects
+ */
+#define KERNCTL_INETVER      70          /* Sysctl code for sockets Inetversion */
+#define OS2_MEMMAPIO         1           /* memory map io */
+#define OS2_QUERY_MEMMAPIO   2           /* Query if mapped memory usable */
+
+/* Generic Structure for Inetcfg calls */
+struct inetcfg_ctl{
+          unsigned long var_name;
+          unsigned long var_cur_val;
+          unsigned long var_max_val;
+          unsigned long var_def_val;
+          unsigned long var_min_val;
+};
+
+/* Inetversion */
+struct inetvers_ctl {
+         float version;
+         char  versionstr[10];           /* Less than 10 chars in version string */
+};
+
+#include <sys/cdefs.h>
+#ifndef KERNEL
+__BEGIN_DECLS
+int _System sysctl __TCPPROTO((int *, u_int, void *, size_t *, void *, size_t));
+__END_DECLS
+#endif
+*)
+
+(* !!TODO!! Not finished yet!!
+/*
+ * Definitions for network related sysctl, CTL_NET.
+ *
+ * Second level is protocol family.
+ * Third level is protocol number.
+ *
+ * Further levels are defined by the individual families below.
+ */
+const
+  NET_MAXID     = AF_MAX;
+
+#define CTL_NET_NAMES { \
+        { 0, 0 }, \
+        { "local", CTLTYPE_NODE }, \
+        { "inet", CTLTYPE_NODE }, \
+        { "implink", CTLTYPE_NODE }, \
+        { "pup", CTLTYPE_NODE }, \
+        { "chaos", CTLTYPE_NODE }, \
+        { "xerox_ns", CTLTYPE_NODE }, \
+        { "iso", CTLTYPE_NODE }, \
+        { "emca", CTLTYPE_NODE }, \
+        { "datakit", CTLTYPE_NODE }, \
+        { "ccitt", CTLTYPE_NODE }, \
+        { "ibm_sna", CTLTYPE_NODE }, \
+        { "decnet", CTLTYPE_NODE }, \
+        { "dec_dli", CTLTYPE_NODE }, \
+        { "lat", CTLTYPE_NODE }, \
+        { "hylink", CTLTYPE_NODE }, \
+        { "appletalk", CTLTYPE_NODE }, \
+        { "netbios", CTLTYPE_NODE }, \
+        { "route", CTLTYPE_NODE }, \
+        { "link_layer", CTLTYPE_NODE }, \
+        { "xtp", CTLTYPE_NODE }, \
+        { "coip", CTLTYPE_NODE }, \
+        { "cnt", CTLTYPE_NODE }, \
+        { "rtip", CTLTYPE_NODE }, \
+        { "ipx", CTLTYPE_NODE }, \
+        { "sip", CTLTYPE_NODE }, \
+        { "pip", CTLTYPE_NODE }, \
+}
+
+/*
+ * PF_ROUTE - Routing table
+ *
+ * Three additional levels are defined:
+ *      Fourth: address family, 0 is wildcard
+ *      Fifth: type of info, defined below
+ *      Sixth: flag(s) to mask with for NET_RT_FLAGS
+ */
+const
+  // dump; may limit to a.f.
+  NET_RT_DUMP   = 1;
+  // by flags, e.g. RESOLVING
+  NET_RT_FLAGS  = 2;
+  // survey interface list
+  NET_RT_IFLIST = 3;
+  NET_RT_MAXID  = 4;
+
+#define CTL_NET_RT_NAMES { \
+        { 0, 0 }, \
+        { "dump", CTLTYPE_STRUCT }, \
+        { "flags", CTLTYPE_STRUCT }, \
+        { "iflist", CTLTYPE_STRUCT }, \
+}
+
+*)
+
+(***************************************************************************)
+(*                                                                         *)
+(*             Maximum queue length specifiable by listen                  *)
+(*                                                                         *)
+(***************************************************************************)
+const
+  // Maximum queue length specifiable by listen
+  SOMAXCONN = 1024;
+
+(***************************************************************************)
+(*                                                                         *)
+(*               Message header for recvmsg and sendmsg calls              *)
+(*          Used value-result for recvmsg, value only for sendmsg          *)
+(*                                                                         *)
+(***************************************************************************)
+type
+  iovec = record
+    iov_base  :  Pointer;
+    iov_len   :  Longint;
+  end;
+
+  // Message header for recvmsg and sendmsg calls
+  msghdr = record
+    msg_name:       pChar;     // optional address
+    msg_namelen:    Longint;   // size of address
+    msg_iov:        ^iovec;    // scatter/gather array
+    msg_iovlen:     Longint;   // # elements in msg_iov (max 1024)
+    msg_control:    pChar;     // ancillary data, see below
+    msg_controllen: Longint;   // ancillary data buffer len
+    msg_flags:      Longint;   // flags on received message
+  end;
+
+const
+  // process out-of-band data
+  MSG_OOB       = $1;
+  // peek at incoming message
+  MSG_PEEK      = $2;
+  // send without using routing tables
+  MSG_DONTROUTE = $4;
+  // send without using routing tables
+  MSG_FULLREAD   = $8;
+  // data completes record
+  MSG_EOR        = $10;
+  // data discarded before delivery
+  MSG_TRUNC      = $20;
+  // control data lost before delivery
+  MSG_CTRUNC     = $40;
+  // wait for full request or error
+  MSG_WAITALL    = $80;
+  // this message should be nonblocking
+  MSG_DONTWAIT   = $100;
+  MSG_EOF        = $200;
+  // mem mapped io
+  MSG_MAPIO      = $400;
+
+(***************************************************************************)
+(*                                                                         *)
+(*        Header for ancillary data objects in msg_control buffer          *)
+(*         Used for additional information with/about a datagram           *)
+(*          not expressible by flags.   The format is a sequence         *)
+(*           of message elements headed by cmsghdr structures              *)
+(*                                                                         *)
+(***************************************************************************)
+type
+  // Header for ancillary data objects in msg_control buffer
+  cmsghdr = record
+    cmsg_len:   Longint; // data byte count, including hdr
+    cmsg_level: Longint; // originating protocol
+    cmsg_type:  Longint; // protocol-specific type
+  end;
+
+  cmsg = record
+    cmsg_hdr:  cmsghdr;
+    cmsg_data: array [0..0] of Byte;
+  end;
+
+(***************************************************************************)
+(*                                                                         *)
+(*                     "Socket"-level control message types                *)
+(*                                                                         *)
+(***************************************************************************)
+const
+  // access rights (array of int)
+  SCM_RIGHTS = $01;
+
+(***************************************************************************)
+(*                                                                         *)
+(*              4.3 compat sockaddr, move to compat file later             *)
+(*                                                                         *)
+(***************************************************************************)
+type
+  // 4.3 compat sockaddr
+  osockaddr = record
+    sa_family: Word;                // address family
+    sa_data: array [0..13] of Byte; // up to 14 bytes of direct address
+  end;
+
+(***************************************************************************)
+(*                                                                         *)
+(*             4.3-compat message header (move to compat file later)       *)
+(*                                                                         *)
+(***************************************************************************)
+type
+  // 4.3-compat message header
+  omsghdr = record
+    msg_name:         pChar;   // optional address
+    msg_namelen:      Longint; // size of address
+    msg_iov:          ^iovec;  // scatter/gather array
+    msg_iovlen:       Longint; // # elements in msg_iov
+    msg_accrights:    pChar;   // access rights sent/received
+    msg_accrightslen: Longint;
+  end;
+
+
+(* !!TODO
+/*
+ * send_file parameter structure
+ */
+struct sf_parms {
+        void   *header_data;      /* ptr to header data */
+        size_t header_length;     /* size of header data */
+        int    file_handle;       /* file handle to send from */
+        size_t file_size;         /* size of file */
+        int    file_offset;       /* byte offset in file to send from */
+        size_t file_bytes;        /* bytes of file to be sent */
+        void   *trailer_data;     /* ptr to trailer data */
+        size_t trailer_length;    /* size of trailer data */
+        size_t bytes_sent;        /* bytes sent in this send_file call */
+};
+*)
+
+{ !!TODO Check is all this functions defined
+__BEGIN_DECLS
+int _System accept_and_recv __TCPPROTO((long, long*, struct sockaddr *, long*, struct sockaddr*, long*, caddr_t, size_t));
+ssize_t _System recvfrom __TCPPROTO((int, void *, size_t, int, struct sockaddr *, int *));
+ssize_t _System recvmsg __TCPPROTO((int, struct msghdr *, int));
+ssize_t _System send __TCPPROTO((int, const void *, size_t, int));
+ssize_t _System sendto __TCPPROTO((int, const void *, size_t, int, const struct sockaddr *, int));
+ssize_t _System sendmsg __TCPPROTO((int, const struct msghdr *, int));
+ssize_t _System send_file __TCPPROTO((int *, struct sf_parms *, int ));
+int _System setsockopt __TCPPROTO((int, int, int, const void *, int));
+int _System shutdown __TCPPROTO((int, int));
+int _System socket __TCPPROTO((int, int, int));
+int _System socketpair __TCPPROTO((int, int, int, int *));
+
+/* OS/2 additions */
+int _System sock_init __TCPPROTO((void));
+int _System sock_errno __TCPPROTO((void));
+void _System psock_errno __TCPPROTO((const char *));
+char * _System sock_strerror __TCPPROTO((int));
+int _System soabort __TCPPROTO((int));
+int _System so_cancel __TCPPROTO((int));
+int _System getinetversion __TCPPROTO((char *));
+void _System addsockettolist __TCPPROTO((int));
+int _System removesocketfromlist __TCPPROTO((int));
+/*int _System removesocketfromlist __TCPPROTO((long *));*/  /*changed on 09-30-98 for corresponding change in sockets.c file*/
+
+/* SOCKS additions */
+int _System Raccept __TCPPROTO((int, struct sockaddr *, int *));
+int _System Rbind __TCPPROTO((int, struct sockaddr *, int, struct sockaddr *));
+int _System Rconnect __TCPPROTO((int, const struct sockaddr *, int));
+int _System Rgetsockname __TCPPROTO((int, struct sockaddr *, int *));
+int _System Rlisten __TCPPROTO((int, int));
+__END_DECLS
+
+
+/* more OS/2 stuff */
+
+const
+  // should be on free list
+  MT_FREE      =  0;
+  // dynamic (data) allocation
+  MT_DATA      =  1;
+  // packet header
+  MT_HEADER    =  2;
+  // socket structure
+  MT_SOCKET    =  3;
+  // protocol control block
+  MT_PCB       =  4;
+  // routing tables
+  MT_RTABLE    =  5;
+  // IMP host tables
+  MT_HTABLE    =  6;
+  // address resolution tables
+  MT_ATABLE    =  7;
+  // socket name
+  MT_SONAME    =  8;
+  // zombie proc status
+  MT_ZOMBIE    =  9;
+  // socket options
+  MT_SOOPTS    =  10;
+  // fragment reassembly header
+  MT_FTABLE    =  11;
+  // access rights
+  MT_RIGHTS    =  12;
+  // interface address
+  MT_IFADDR    =  13;
+
+Type
+  sostats=record
+    count: integer;
+    socketdata: array[0..13*MAXSOCKETS-1] of integer;
+  end;
+
+}
+
+(***************************************************************************)
+(*                                                                         *)
+(*          SOCE* constants - socket errors from NERRNO.H                  *)
+(*  All OS/2 SOCKET API error constants are biased by SOCBASEERR from the  *)
+(*                                 "normal"                                *)
+(*                                                                         *)
+(***************************************************************************)
+
+const
+  SOCBASEERR         = 10000;
+
+  // Not owner
+  SOCEPERM           = (SOCBASEERR+1);
+  // No such file or directory
+  SOCENOENT          = (SOCBASEERR+2);
+  // No such process
+  SOCESRCH           = (SOCBASEERR+3);
+  // Interrupted system call
+  SOCEINTR           = (SOCBASEERR+4);
+  // Input/output error
+  SOCEIO             = (SOCBASEERR+5);
+  SOCENXIO           = (SOCBASEERR+6);      // No such device or address
+  SOCE2BIG           = (SOCBASEERR+7);      // Argument list too long
+  SOCENOEXEC         = (SOCBASEERR+8);      // Exec format error
+  SOCEBADF           = (SOCBASEERR+9);      // Bad file number
+  SOCECHILD          = (SOCBASEERR+10);     // No child processes
+  SOCEDEADLK         = (SOCBASEERR+11);     // Resource deadlock avoided
+  SOCENOMEM          = (SOCBASEERR+12);     // Cannot allocate memory
+  SOCEACCES          = (SOCBASEERR+13);     // Permission denied
+  SOCEFAULT          = (SOCBASEERR+14);     // Bad address
+  SOCENOTBLK         = (SOCBASEERR+15);     // Block device required
+  SOCEBUSY           = (SOCBASEERR+16);     // Device busy
+  SOCEEXIST          = (SOCBASEERR+17);     // File exists
+  SOCEXDEV           = (SOCBASEERR+18);     // Cross-device link
+  SOCENODEV          = (SOCBASEERR+19);     // Operation not supported by device
+  SOCENOTDIR         = (SOCBASEERR+20);     // Not a directory
+  SOCEISDIR          = (SOCBASEERR+21);     // Is a directory
+  SOCEINVAL          = (SOCBASEERR+22);     // Invalid argument
+  SOCENFILE          = (SOCBASEERR+23);     // Too many open files in system
+  SOCEMFILE          = (SOCBASEERR+24);     // Too many open files
+  SOCENOTTY          = (SOCBASEERR+25);     // Inappropriate ioctl for device
+  SOCETXTBSY         = (SOCBASEERR+26);     // Text file busy
+  SOCEFBIG           = (SOCBASEERR+27);     // File too large
+  SOCENOSPC          = (SOCBASEERR+28);     // No space left on device
+  SOCESPIPE          = (SOCBASEERR+29);     // Illegal seek
+  SOCEROFS           = (SOCBASEERR+30);     // Read-only file system
+  SOCEMLINK          = (SOCBASEERR+31);     // Too many links
+  SOCEPIPE           = (SOCBASEERR+32);     // Broken pipe
+
+// math software
+  SOCEDOM            = (SOCBASEERR+33);     // Numerical argument out of domain
+  SOCERANGE          = (SOCBASEERR+34);     // Result too large
+
+// non-blocking and interrupt i/o
+  SOCEAGAIN          = (SOCBASEERR+35);     // Resource temporarily unavailable
+  SOCEWOULDBLOCK     = SOCEAGAIN;           // Operation would block
+  SOCEINPROGRESS     = (SOCBASEERR+36);     // Operation now in progress
+  SOCEALREADY        = (SOCBASEERR+37);     // Operation already in progress
+
+// ipc/network software -- argument errors
+  SOCENOTSOCK        = (SOCBASEERR+38);     // Socket operation on non-socket
+  SOCEDESTADDRREQ    = (SOCBASEERR+39);     // Destination address required
+  SOCEMSGSIZE        = (SOCBASEERR+40);     // Message too long
+  SOCEPROTOTYPE      = (SOCBASEERR+41);     // Protocol wrong type for socket
+  SOCENOPROTOOPT     = (SOCBASEERR+42);     // Protocol not available
+  SOCEPROTONOSUPPORT = (SOCBASEERR+43);     // Protocol not supported
+  SOCESOCKTNOSUPPORT = (SOCBASEERR+44);     // Socket type not supported
+  SOCEOPNOTSUPP      = (SOCBASEERR+45);     // Operation not supported
+  SOCEPFNOSUPPORT    = (SOCBASEERR+46);     // Protocol family not supported
+  SOCEAFNOSUPPORT    = (SOCBASEERR+47);     // Address family not supported by protocol family
+  SOCEADDRINUSE      = (SOCBASEERR+48);     // Address already in use
+  SOCEADDRNOTAVAIL   = (SOCBASEERR+49);     // Can't assign requested address
+
+// ipc/network software -- operational errors
+  SOCENETDOWN        = (SOCBASEERR+50);     // Network is down
+  SOCENETUNREACH     = (SOCBASEERR+51);     // Network is unreachable
+  SOCENETRESET       = (SOCBASEERR+52);     // Network dropped connection on reset
+  SOCECONNABORTED    = (SOCBASEERR+53);     // Software caused connection abort
+  SOCECONNRESET      = (SOCBASEERR+54);     // Connection reset by peer
+  SOCENOBUFS         = (SOCBASEERR+55);     // No buffer space available
+  SOCEISCONN         = (SOCBASEERR+56);     // Socket is already connected
+  SOCENOTCONN        = (SOCBASEERR+57);     // Socket is not connected
+  SOCESHUTDOWN       = (SOCBASEERR+58);     // Can't send after socket shutdown
+  SOCETOOMANYREFS    = (SOCBASEERR+59);     // Too many references: can't splice
+  SOCETIMEDOUT       = (SOCBASEERR+60);     // Operation timed out
+  SOCECONNREFUSED    = (SOCBASEERR+61);     // Connection refused
+
+  SOCELOOP           = (SOCBASEERR+62);     // Too many levels of symbolic links
+  SOCENAMETOOLONG    = (SOCBASEERR+63);     // File name too long
+
+// should be rearranged
+  SOCEHOSTDOWN       = (SOCBASEERR+64);      // Host is down
+  SOCEHOSTUNREACH    = (SOCBASEERR+65);      // No route to host
+  SOCENOTEMPTY       = (SOCBASEERR+66);      // Directory not empty
+
+// quotas & mush
+  SOCEPROCLIM        = (SOCBASEERR+67);      // Too many processes
+  SOCEUSERS          = (SOCBASEERR+68);      // Too many users
+  SOCEDQUOT          = (SOCBASEERR+69);      // Disc quota exceeded
+
+// Network File System
+  SOCESTALE          = (SOCBASEERR+70);      // Stale NFS file handle
+  SOCEREMOTE         = (SOCBASEERR+71);      // Too many levels of remote in path
+  SOCEBADRPC         = (SOCBASEERR+72);      // RPC struct is bad
+  SOCERPCMISMATCH    = (SOCBASEERR+73);      // RPC version wrong
+  SOCEPROGUNAVAIL    = (SOCBASEERR+74);      // RPC prog. not avail
+  SOCEPROGMISMATCH   = (SOCBASEERR+75);      // Program version wrong
+  SOCEPROCUNAVAIL    = (SOCBASEERR+76);      // Bad procedure for program
+
+  SOCENOLCK          = (SOCBASEERR+77);      // No locks available
+  SOCENOSYS          = (SOCBASEERR+78);      // Function not implemented
+
+  SOCEFTYPE          = (SOCBASEERR+79);      // Inappropriate file type or format
+  SOCEAUTH           = (SOCBASEERR+80);      // Authentication error
+  SOCENEEDAUTH       = (SOCBASEERR+81);      // Need authenticator
+
+  SOCEOS2ERR         = (SOCBASEERR+100);     // OS/2 Error
+  SOCELAST           = (SOCBASEERR+100);     // Must be equal largest errno
+
+(* !!TODO Add this consts
+/*
+ * OS/2 SOCKET API errors redefined as regular BSD error constants
+ */
+
+#ifndef ENOENT
+#define ENOENT                  SOCENOENT
+#endif
+
+#ifndef EFAULT
+#define EFAULT                  SOCEFAULT
+#endif
+
+#ifndef EBUSY
+#define EBUSY                   SOCEBUSY
+#endif
+
+#ifndef ENXIO
+#define ENXIO                   SOCENXIO
+#endif
+
+#ifndef EACCES
+#define EACCES                  SOCEACCES
+#endif
+
+#ifndef ENOMEM
+#define ENOMEM                  SOCENOMEM
+#endif
+
+#ifndef ENOTDIR
+#define ENOTDIR                 SOCENOTDIR
+#endif
+
+#ifndef EPERM
+#define EPERM                   SOCEPERM
+#endif
+
+#ifndef ESRCH
+#define ESRCH                   SOCESRCH
+#endif
+
+#ifndef EDQUOT
+#define EDQUOT                  SOCEDQUOT
+#endif
+
+#ifndef EEXIST
+#define EEXIST                  SOCEEXIST
+#endif
+
+#ifndef EBUSY
+#define EBUSY                   SOCEBUSY
+#endif
+
+#ifndef EWOULDBLOCK
+#define EWOULDBLOCK             SOCEWOULDBLOCK
+#endif
+
+#ifndef EINPROGRESS
+#define EINPROGRESS             SOCEINPROGRESS
+#endif
+
+#ifndef EALREADY
+#define EALREADY                SOCEALREADY
+#endif
+
+#ifndef ENOTSOCK
+#define ENOTSOCK                SOCENOTSOCK
+#endif
+
+#ifndef EDESTADDRREQ
+#define EDESTADDRREQ            SOCEDESTADDRREQ
+#endif
+
+#ifndef EMSGSIZE
+#define EMSGSIZE                SOCEMSGSIZE
+#endif
+
+#ifndef EPROTOTYPE
+#define EPROTOTYPE              SOCEPROTOTYPE
+#endif
+
+#ifndef ENOPROTOOPT
+#define ENOPROTOOPT             SOCENOPROTOOPT
+#endif
+
+#ifndef EPROTONOSUPPORT
+#define EPROTONOSUPPORT         SOCEPROTONOSUPPORT
+#endif
+
+#ifndef ESOCKTNOSUPPORT
+#define ESOCKTNOSUPPORT         SOCESOCKTNOSUPPORT
+#endif
+
+#ifndef EOPNOTSUPP
+#define EOPNOTSUPP              SOCEOPNOTSUPP
+#endif
+
+#ifndef EPFNOSUPPORT
+#define EPFNOSUPPORT            SOCEPFNOSUPPORT
+#endif
+
+#ifndef EAFNOSUPPORT
+#define EAFNOSUPPORT            SOCEAFNOSUPPORT
+#endif
+
+#ifndef EADDRINUSE
+#define EADDRINUSE              SOCEADDRINUSE
+#endif
+
+#ifndef EADDRNOTAVAIL
+#define EADDRNOTAVAIL           SOCEADDRNOTAVAIL
+#endif
+
+#ifndef ENETDOWN
+#define ENETDOWN                SOCENETDOWN
+#endif
+
+#ifndef ENETUNREACH
+#define ENETUNREACH             SOCENETUNREACH
+#endif
+
+#ifndef ENETRESET
+#define ENETRESET               SOCENETRESET
+#endif
+
+#ifndef ECONNABORTED
+#define ECONNABORTED            SOCECONNABORTED
+#endif
+
+#ifndef ECONNRESET
+#define ECONNRESET              SOCECONNRESET
+#endif
+
+#ifndef ENOBUFS
+#define ENOBUFS                 SOCENOBUFS
+#endif
+
+#ifndef EISCONN
+#define EISCONN                 SOCEISCONN
+#endif
+
+#ifndef ENOTCONN
+#define ENOTCONN                SOCENOTCONN
+#endif
+
+#ifndef ESHUTDOWN
+#define ESHUTDOWN               SOCESHUTDOWN
+#endif
+
+#ifndef ETOOMANYREFS
+#define ETOOMANYREFS            SOCETOOMANYREFS
+#endif
+
+#ifndef ETIMEDOUT
+#define ETIMEDOUT               SOCETIMEDOUT
+#endif
+
+#ifndef ECONNREFUSED
+#define ECONNREFUSED            SOCECONNREFUSED
+#endif
+
+#ifndef ELOOP
+#define ELOOP                   SOCELOOP
+#endif
+
+#ifndef ENAMETOOLONG            /* Borland and Watcom define this */
+#define ENAMETOOLONG            SOCENAMETOOLONG
+#endif
+
+#ifndef EHOSTDOWN
+#define EHOSTDOWN               SOCEHOSTDOWN
+#endif
+
+#ifndef EHOSTUNREACH
+#define EHOSTUNREACH            SOCEHOSTUNREACH
+#endif
+
+#ifndef ENOTEMPTY               /* Watcom defines this */
+#define ENOTEMPTY               SOCENOTEMPTY
+#endif
+
+#ifndef EINVAL
+#define EINVAL                  SOCEINVAL
+#endif
+
+#ifndef EINTR
+#define EINTR                   SOCEINTR
+#endif
+
+#ifndef EMFILE
+#define EMFILE                  SOCEMFILE
+#endif
+
+#ifndef EPIPE
+#define EPIPE                   SOCEPIPE
+#endif
+*)
+
+// * bsd select definitions
+
+const
+{
+ * Select uses bit masks of file descriptors in longs.  These macros
+ * manipulate such bit fields (the filesystem macros use chars).
+ * FD_SETSIZE may be defined by the user, but the default here should
+ * be enough for most uses.
+}
+  FD_SETSIZE = 64;
+
+type
+
+  fd_set = record
+    fd_count  :  Word;                        // how many are SET?
+    fd_array  :  array[0..FD_SETSIZE-1] of Longint;   // an array of SOCKETs
+  end;
+
+  timeval = record
+    tv_sec   :  Longint; // Number of seconds
+    tv_usec  :  Longint; // Number of microseconds
+  end;
+
+
+
+
+(* !!TODO Check all macros from sys/itypes.h
+function  LSwap(a:Longint):Longint;
+function  WSwap(a:Word):Word;
+
+{ host -> network for long (4 bytes) }
+function  htonl(a:Longint):Longint;
+
+{ network -> host for long (4 bytes) }
+function  ntohl(a:Longint):Longint;
+
+{ host -> network for small (2 bytes) }
+function  htons(a:Word):Word;
+
+{ network -> host for small (2 bytes) }
+function  ntohs(a:Word):Word;
+
+*)
+
+{ * init / misc funcs }
+
+{ init sockets system }
+function  sock_init:Longint; cdecl;
+
+{ get inet version. version - buffer of ?? size for returned string. }
+function  getinetversion(var version):Longint; cdecl;
+
+
+{ * sockets errors reporting funcs }
+
+{ last err code for this thread }
+function  sock_errno:Longint; cdecl;
+
+{ print last err string + str if not NIL }
+procedure psock_errno(const str:PChar); cdecl;
+
+
+{ * sockets creation / close funcs }
+
+{ create new socket }
+function  socket(domain,stype,protocol:Longint):Longint; cdecl;
+
+{ close socket }
+function  soclose(sock:Longint):Longint; cdecl;
+
+{ cancel socket }
+function  so_cancel(sock:Longint):Longint; cdecl;
+
+{ shutdown socket. howto: 0/1/2 }
+function  shutdown(sock,howto:Longint):Longint; cdecl;
+
+{ abort socket. no docs found about it :( }
+function  soabort(sock:Longint):Longint; cdecl;
+
+(***************************************************************************)
+(*                                                                         *)
+(*                         sockets connection funcs                        *)
+(*                                                                         *)
+(***************************************************************************)
+
+{ accept a connection from remote host. returns s_addr & s_addr_len if not nil }
+function accept(sock:Longint; var s_addr:sockaddr; s_addr_len:Longint):Longint; cdecl;
+
+{ bind a local name to the socket }
+function bind(sock:Longint; const s_addr: sockaddr; s_addr_len:Longint):Longint; cdecl;
+
+{ connect socket to remote host }
+function connect(sock:Longint; const s_addr:sockaddr; s_addr_len:Longint):Longint; cdecl;
+
+{ listen on socket. max_conn - queue size of listen. }
+function listen(sock,max_conn:Longint):Longint; cdecl;
+
+(***************************************************************************)
+(*                                                                         *)
+(*                       sockets read/write funcs                          *)
+(*                                                                         *)
+(***************************************************************************)
+
+{ read data from socket. ! return N of readed bytes, or 0 (closed) or -1 }
+function recv(sock:Longint; var buf; buf_len,flags:Longint):Longint; cdecl;
+
+{ send data to socket. ! return N of sent bytes. -1 - err }
+function  send(sock:Longint; const buf; buf_len,flags:Longint):Longint; cdecl;
+
+{ read data from socket. ! return N of readed bytes, or 0 (closed) or -1 }
+function  recvfrom(sock:Longint; var buf; buf_len,flags:Longint; var s_addr:sockaddr; var s_addr_len:Longint):Longint; cdecl;
+
+{ send data to socket. ! return N of sent bytes. -1 - err }
+function  sendto(sock:Longint; const buf; buf_len,flags:Longint; var s_addr:sockaddr; s_addr_len:Longint):Longint; cdecl;
+
+{ read data into iov_count number of buffers iov.
+  ! return N of readed bytes, or 0 (closed) or -1 }
+function  readv(sock:Longint; var iov:iovec; iov_count:Longint):LONGINT; cdecl;
+
+{ write data from iov_count number of buffers iov.
+  ! return N of writed bytes, or -1 }
+function  writev(sock:Longint; var iov:iovec; iov_count:Longint):LONGINT; cdecl;
+
+{ read data + control info from socket
+  ! return N of readed bytes, or 0 (closed) or -1 }
+function  recvmsg(sock:Longint; var msgbuf:msghdr; flags:Longint):Longint; cdecl;
+
+{ send data + control info to socket
+  ! return N of sended bytes, or -1 }
+function  sendmsg(sock:Longint; var msgbuf:msghdr; flags:Longint):Longint; cdecl;
+
+(***************************************************************************)
+(*                                                                         *)
+(*                              select funcs                               *)
+(*                                                                         *)
+(***************************************************************************)
+
+{ OS/2 select. 0 - timeout. -1 - err. XX - N of sockets worked. }
+function  os2_select(var sockets; N_reads, N_writes, N_exepts, timeout:Longint):Longint; cdecl;
+
+{ bsd select here. heavy voodoo.. }
+function  select(nfds:Longint; const readfds,writefds,exceptfds:fd_set; const timeout:timeval):Longint; cdecl;
+
+(***************************************************************************)
+(*                                                                         *)
+(*                                misc info                                *)
+(*                                                                         *)
+(***************************************************************************)
+
+{ get host ip addr - addr of primary interface }
+function gethostid:Longint; cdecl;
+
+{ get connected to socket hostname }
+function getpeername(sock:Longint; var s_addr:sockaddr; var s_addr_len:Longint):Longint; cdecl;
+
+{ get local socket name }
+function getsockname(sock:Longint; var s_addr:sockaddr; var s_addr_len:Longint):Longint; cdecl;
+
+(***************************************************************************)
+(*                                                                         *)
+(*                             options & ioctls                            *)
+(*                                                                         *)
+(***************************************************************************)
+
+{ get socket options }
+function getsockopt(sock,level,optname:Longint; var buf; var buf_len:Longint):Longint; cdecl;
+
+{ set socket options }
+function  setsockopt(sock,level,optname:Longint; const buf; buf_len:Longint):Longint; cdecl;
+
+{ f@$king ioctl. use sys/ioctl.h }
+function os2_ioctl(sock,cmd:Longint; var data; data_len:Longint):Longint; cdecl;
+
+(***************************************************************************)
+(*                                                                         *)
+(*     functions only for 4.1+ ip stacks (but also found in 4.02w ;))      *)
+(*                                                                         *)
+(***************************************************************************)
+
+
+function  addsockettolist(sock:Longint):Longint; cdecl;
+
+function  removesocketfromlist(sock:Longint):Longint; cdecl;
+
+implementation
+
+function  LSwap(a:Longint):Longint; assembler;
+asm
+      mov   eax,a
+      xchg  ah,al
+      ror   eax,16
+      xchg  ah,al
+end;
+
+function  WSwap(a:Word):Word; assembler;
+asm
+      mov   ax,a
+      xchg  ah,al
+end;
+
+function accept(sock:Longint; var s_addr: sockaddr; s_addr_len:Longint):Longint; cdecl; external 'SO32DLL' index 1;
+function bind(sock:Longint; const s_addr: sockaddr; s_addr_len:Longint):Longint; cdecl; external 'SO32DLL' index 2;
+function connect(sock:Longint; const s_addr:sockaddr; s_addr_len:Longint):Longint; cdecl; external 'SO32DLL' index 3;
+function gethostid: Longint; cdecl; external 'SO32DLL' index 4;
+function getpeername(sock:Longint; var s_addr:sockaddr; var s_addr_len:Longint):Longint; cdecl; external 'SO32DLL' index 5;
+function getsockname(sock:Longint; var s_addr:sockaddr; var s_addr_len:Longint):Longint; cdecl; external 'SO32DLL' index 6;
+function getsockopt(sock,level,optname:Longint; var buf; var buf_len:Longint):Longint; cdecl; external 'SO32DLL' index 7;
+function os2_ioctl(sock,cmd:Longint; var data; data_len:Longint):Longint; cdecl; external 'SO32DLL' index 8;
+function listen(sock,max_conn:Longint):Longint; cdecl; external 'SO32DLL' index 9;
+function recv(sock:Longint; var buf; buf_len,flags:Longint):Longint; cdecl; external 'SO32DLL' index 10;
+function  recvfrom(sock:Longint; var buf; buf_len,flags:Longint;var s_addr:sockaddr; var s_addr_len:Longint):Longint; cdecl; external 'SO32DLL' index 11;
+function  os2_select(var sockets; N_reads, N_writes, N_exepts, timeout:Longint):Longint; cdecl; external 'SO32DLL' index 12;
+function  send(sock:Longint; const buf; buf_len,flags:Longint):Longint; cdecl; external 'SO32DLL' index 13;
+function  sendto(sock:Longint; const buf; buf_len,flags:Longint;var s_addr:sockaddr; s_addr_len:Longint):Longint; cdecl; external 'SO32DLL' index 14;
+function  setsockopt(sock,level,optname:Longint; const buf; buf_len:Longint):Longint; cdecl; external 'SO32DLL' index 15;
+function  socket(domain,stype,protocol:Longint):Longint; cdecl; external 'SO32DLL' index 16;
+function  soclose(sock:Longint):Longint; cdecl; external 'SO32DLL' index 17;
+function  so_cancel(sock:Longint):Longint; cdecl; external 'SO32DLL' index 18;
+function  soabort(sock:Longint):Longint; cdecl; external 'SO32DLL' index 19;
+function  sock_errno:Longint; cdecl; external 'SO32DLL' index 20;
+function  recvmsg(sock:Longint; var msgbuf:msghdr; flags:Longint):Longint; cdecl; external 'SO32DLL' index 21;
+function  sendmsg(sock:Longint; var msgbuf:msghdr; flags:Longint):Longint; cdecl; external 'SO32DLL' index 22;
+function  readv(sock:Longint; var iov:iovec; iov_count:Longint):LONGINT; cdecl; external 'SO32DLL' index 23;
+function  writev(sock:Longint; var iov:iovec; iov_count:Longint):LONGINT; cdecl; external 'SO32DLL' index 24;
+function  shutdown(sock,howto:Longint):Longint; cdecl; external 'SO32DLL' index 25;
+function  sock_init:Longint; cdecl; external 'SO32DLL' index 26;
+function  addsockettolist(sock:Longint):Longint; cdecl; external 'SO32DLL' index 27;
+function  removesocketfromlist(sock:Longint):Longint; cdecl; external 'SO32DLL' index 28;
+{ entry 29 not used }
+procedure psock_errno(const str:PChar); cdecl; external 'SO32DLL' index 30;
+function  getinetversion(var version):Longint; cdecl; external 'SO32DLL' index 31;
+function  select(nfds:Longint;
+                 const readfds,writefds,exceptfds:fd_set;
+                 const timeout:timeval):Longint; cdecl; external 'SO32DLL' index 32;
+
+
+function  htonl(a:Longint):Longint;
+begin   Result:=LSwap(a);   end;
+{ host -> network for long (4 bytes) }
+
+function  ntohl(a:Longint):Longint;
+begin   Result:=LSwap(a);   end;
+{ network -> host for long (4 bytes) }
+
+function  htons(a:Word):Word;
+begin   Result:=WSwap(a);   end;
+{ host -> network for small (2 bytes) }
+
+function  ntohs(a:Word):Word;
+begin   Result:=WSwap(a);   end;
+{ network -> host for small (2 bytes) }
+
+end.
+
+(* !!TODO   Following code not revised as yet
+
+{*
+ * User-settable options (used with setsockopt).
+ *}
+  TCP_NODELAY    = $01;    // don't delay send to coalesce packets
+  TCP_MAXSEG     = $02;    // set maximum segment size
+  TCP_MSL        = $03;    // MSL HACK
+  TCP_TIMESTMP   = $04;    // RFC 1323 (RTTM TimeStamp)
+  TCP_WINSCALE   = $05;    // RFC 1323 (Window Scale)
+  TCP_CC         = $06;    // RFC 1644 (Connection Count)
+
+
+
+
+
+
+{
+ * Structures returned by network data base library.  All addresses are
+ * supplied in host order, and returned in network order (suitable for
+ * use in system calls).
+}
+
+type
+
+  PLongint = ^Longint;
+
+  { struct for gethostbyname() and gethostbyaddr() }
+  hostent = record
+    h_name       :  PChar;       // official name of host
+    h_aliases    :  ^PChar;      // alias list
+    h_addrtype   :  Longint;     // host address type
+    h_length     :  Longint;     // length of address
+    h_addr_list  :  ^PLongint;   // list of addresses from name server
+  end;
+
+  phostent = ^hostent;
+
+{
+ * Error return codes from gethostbyname(), gethostbyaddr() and res_* funcs
+ * (left in extern int h_errno).
+}
+
+const
+
+  NETDB_INTERNAL  = -1;       // see errno
+  NETDB_SUCCESS   =  0;       // no problem
+  HOST_NOT_FOUND  =  1;       // Authoritative Answer Host not found
+  TRY_AGAIN       =  2;       // Non-Authoritive Host not found, or SERVERFAIL
+  NO_RECOVERY     =  3;       // Non recoverable errors, FORMERR, REFUSED, NOTIMP
+  NO_DATA         =  4;       // Valid name, no data record of requested type
+  NO_ADDRESS      =  NO_DATA; // no address, look for MX record
+
+type
+
+  { struct for getprotobyname() and getprotobynumber() }
+  protoent = record
+    p_name     :  PChar;         // official protocol name
+    p_aliases  :  ^PChar;        // alias list
+    p_proto    :  Longint;       // protocol #
+  end;
+
+  pprotoent = ^protoent;
+
+type
+
+  { struct for getservbyname() and getservbyport() }
+  servent = record
+    s_name     :  PChar;         // official service name
+    s_aliases  :  ^PChar;        // alias list
+    s_port     :  Longint;       // port # (need ntohl() !!)
+    s_proto    :  PChar;         // protocol to use
+  end;
+
+  pservent = ^servent;
+
+{
+ * ioctl & ip trace support
+}
+const
+  SIOCGIFFLAGS          =  $6900 + 17;  // get interface flags
+
+  { Interface Tracing Support }
+  SIOCGIFEFLAGS         =  $6900 + 150; // get interface enhanced flags
+  SIOCSIFEFLAGS         =  $6900 + 151; // set interface enhanced flags
+  SIOCGIFTRACE          =  $6900 + 152; // get interface trace data
+  SIOCSIFTRACE          =  $6900 + 153; // set interface trace data
+  { sorry, i skip other ioctl commands, see SYS\ioctl.h from toolkit for it.. }
+
+  IFF_UP                =  $1;          // interface is up
+  IFF_BROADCAST         =  $2;          // broadcast address valid
+  IFF_DEBUG             =  $4;          // turn on debugging
+  IFF_LOOPBACK          =  $8;          // is a loopback net
+  IFF_POINTOPOINT       =  $10;         // interface is point-to-point link
+  IFF_LINK2             =  $20;         // was trailers, not used
+  IFF_NOTRAILERS        =  IFF_LINK2;
+  IFF_RUNNING           =  $40;         // resources allocated
+  IFF_NOARP             =  $80;         // no address resolution protocol
+  IFF_PROMISC           =  $100;        // receive all packets
+  IFF_ALLMULTI          =  $200;        // receive all multicast packets
+  IFF_BRIDGE            =  $1000;       // support token ring routine field
+  IFF_SNAP              =  $2000;       // support extended SAP header
+  IFF_DEFMTU            =  $400;        // default mtu of 1500
+  IFF_RFC1469_BC        =  1;           // using broadcast
+  IFF_RFC1469_FA        =  2;           // using functional
+  IFF_RFC1469_MA        =  3;           // using multicast
+  IFF_ETHER             =  $4000;       // Ethernet interface
+  IFF_LOOPBRD           =  $8000;       // loop back broadcasts
+  IFF_MULTICAST         =  $800;        // supports multicast
+
+  IFF_SIMPLEX           =  $10000;      // can't hear own transmissions
+  IFF_OACTIVE           =  $20000;      // transmission in progress
+  IFF_802_3             =  $40000;
+  IFF_CANONICAL         =  $80000;
+  IFF_RUNNINGBLK        =  $100000;     // threads waited for intf running
+
+  { Interface enhanced flags }
+  IFFE_PKTTRACE         =  $00000001;   // trace datalink where possible
+  IFFE_IPTRACE          =  $00000002;   // trace ONLY IP packets
+
+type
+  { trace buffer struct }
+  pkt_trace_hdr = record
+     pt_htype           :  Word;        // header type
+     pt_len             :  Word;        // in: pt_buf len, out: packet len
+     pt_data            :  Pointer;     // packet
+     pt_tstamp          :  Longint;     // time stamp in milliseconds
+  end;
+
+const
+  { physical protocols IDs }
+  HT_IP                 =  $01;  // IP
+  HT_ETHER              =  $06;  // Ethernet
+  HT_ISO88023           =  $07;  // CSMA CD
+  HT_ISO88025           =  $09;  // Token Ring
+  HT_SLIP               =  $1c;  // Serial Line IP
+  HT_PPP                =  $18;  // PPP IP
+
+const
+  IFNAMSIZ              =  16;   // interface name length
+
+type
+{
+* Interface request structure used for socket
+* ioctl's.  All interface ioctl's must have parameter
+* definitions which begin with ifr_name.  The
+* remainder may be interface specific.
+}
+  ifreq = record
+     ifr_name           :  array[0..IFNAMSIZ-1] of Char;
+     case Byte of
+     0: (ifr_addr       :  sockaddr);  // address
+     1: (ifr_dstaddr    :  sockaddr);  // other end of p-to-p link
+     2: (ifr_broadaddr  :  sockaddr);  // broadcast address
+     3: (ifr_flags      :  Word); // flags
+     4: (ifr_metric     :  Longint);   // metric
+     5: (ifr_data       :  Pointer);   // for use by interface
+     6: (ifr_eflags     :  Longint);   // eflags
+  end;
+
+
+{
+ * Structure of an internet header, naked of options.
+}
+type
+   ip = record
+      hlen_ver                         :  Byte; { lo 4 bits = header len/4
+                                                  hi 4 bits = ip ver (4) }
+      ip_tos                           :  Byte;      { type of service }
+      ip_len                           :  Word; { total packet length }
+      ip_id                            :  Word; { identification }
+      ip_off                           :  Word; { fragment offset field }
+      ip_ttl                           :  Byte;      { time to live }
+      ip_p                             :  Byte;      { protocol (see IPPROTO_* ) }
+      ip_sum                           :  Word; { header checksum }
+      ip_src, ip_dst                   :  Longint;   { ip from / to addr }
+   end;
+
+
+{ in.h / inet.h const & func }
+
+{
+ * Protocols
+}
+const
+     IPPROTO_IP              = 0;               { dummy for IP }
+     IPPROTO_ICMP            = 1;               { control message protocol }
+     IPPROTO_GGP             = 3;               { gateway^2 (deprecated) }
+     IPPROTO_TCP             = 6;               { tcp }
+     IPPROTO_EGP             = 8;               { exterior gateway protocol }
+     IPPROTO_PUP             = 12;              { pup }
+     IPPROTO_UDP             = 17;              { user datagram protocol }
+     IPPROTO_IDP             = 22;              { xns idp }
+
+     IPPROTO_RAW             = 255;             { raw IP packet }
+     IPPROTO_MAX             = 256;
+
+{
+ * Ports < IPPORT_RESERVED are reserved for
+ * privileged processes (e.g. root).
+ * Ports > IPPORT_USERRESERVED are reserved
+ * for servers, not necessarily privileged.
+}
+const
+    IPPORT_RESERVED         = 1024;
+    IPPORT_USERRESERVED     = 5000;
+
+{
+ * Link numbers
+}
+const
+    IMPLINK_IP              = 155;
+    IMPLINK_LOWEXPER        = 156;
+    IMPLINK_HIGHEXPER       = 158;
+
+{
+ * Definitions of bits in internet address integers.
+ * On subnets, the decomposition of addresses to host and net parts
+ * is done according to subnet mask, not the masks here.
+}
+const
+     IN_CLASSA_NET           = $ff000000;
+     IN_CLASSA_NSHIFT        = 24;
+     IN_CLASSA_HOST          = $00ffffff;
+     IN_CLASSA_MAX           = 128;
+
+     IN_CLASSB_NET           = $ffff0000;
+     IN_CLASSB_NSHIFT        = 16;
+     IN_CLASSB_HOST          = $0000ffff;
+     IN_CLASSB_MAX           = 65536;
+
+     IN_CLASSC_NET           = $ffffff00;
+     IN_CLASSC_NSHIFT        = 8;
+     IN_CLASSC_HOST          = $000000ff;
+
+     INADDR_ANY              = $00000000;
+     INADDR_BROADCAST        = $ffffffff;     { must be masked }
+     INADDR_NONE             = $ffffffff;     { -1 return }
+
+     IN_LOOPBACKNET          = 127;           { official! }
+
+{
+ * Socket address, internet style.
+}
+type
+   sockaddr_in = record
+      sin_family                       :  Word;
+      sin_port                         :  Word; { htons first!! }
+      sin_addr                         :  Longint; {in_addr; hist reasons :)) }
+      sin_zero                         :  array[0..7] of Byte; {must be zero}
+   end;
+
+{ * Internet address (a structure for historical reasons) }
+type
+   in_addr = record
+      s_addr                           :  Longint;
+   end;
+
+{*
+ * Options for use with [gs]etsockopt at the IP level.
+ * }
+const
+
+  IP_OPTIONS            = 1;   // buf/ip_opts; set/get IP options
+  IP_MULTICAST_IF       = 2;   // u_char; set/get IP multicast i/f
+  IP_MULTICAST_TTL      = 3;   // u_char; set/get IP multicast ttl
+  IP_MULTICAST_LOOP     = 4;   // u_char; set/get IP multicast loopback
+  IP_ADD_MEMBERSHIP     = 5;   // ip_mreq; add an IP group membership
+  IP_DROP_MEMBERSHIP    = 6;   // ip_mreq; drop an IP group membership
+  IP_HDRINCL            = 7;   // int; header is included with data
+  IP_TOS                = 8;   // int; IP type of service and preced.
+  IP_TTL                = 9;   // int; IP time to live
+  IP_RECVOPTS           = 10;  // bool; receive all IP opts w/dgram
+  IP_RECVRETOPTS        = 11;  // bool; receive IP opts for response
+  IP_RECVDSTADDR        = 12;  // bool; receive IP dst addr w/dgram
+  IP_RETOPTS            = 13;  // ip_opts; set/get IP options
+  IP_RECVTRRI           = 14;  // bool; receive token ring routing inf
+
+{*
+ * Defaults and limits for options
+ * }
+  IP_DEFAULT_MULTICAST_TTL  = 1;    // normally limit m'casts to 1 hop
+  IP_DEFAULT_MULTICAST_LOOP = 1;    // normally hear sends if a member
+  IP_MAX_MEMBERSHIPS        = 20;   // per socket; must fit in one mbuf
+  MAX_IN_MULTI    = 16*IP_MAX_MEMBERSHIPS;     // 320 max per os2
+
+*)
+
+
+(* List of not checked functions from SO32DLL.DLL
+³ 00011 ³ RECVFROM
+³ 00012 ³ SELECT
+³ 00013 ³ SEND
+³ 00014 ³ SENDTO
+³ 00015 ³ SETSOCKOPT
+³ 00016 ³ SOCKET
+³ 00017 ³ SOCLOSE
+³ 00018 ³ SO_CANCEL
+³ 00019 ³ SOABORT
+³ 00020 ³ SOCK_ERRNO
+³ 00021 ³ RECVMSG
+³ 00022 ³ SENDMSG
+³ 00023 ³ READV
+³ 00024 ³ WRITEV
+³ 00025 ³ SHUTDOWN
+³ 00026 ³ SOCK_INIT
+³ 00027 ³ ADDSOCKETTOLIST
+³ 00028 ³ REMOVESOCKETFROMLIST
+³ 00030 ³ PSOCK_ERRNO
+³ 00031 ³ GETINETVERSION
+³ 00032 ³ BSDSELECT
+³ 00035 ³ SET_ERRNO
+³ 00038 ³ WINSOCKCLEANUPSOCKETS
+³ 00039 ³ GETSOCKETFROMLIST
+À´Done
+*)

+ 297 - 0
rtl/os2/sockets.pas

@@ -0,0 +1,297 @@
+{
+
+                   (C) 2002 Yuri Prokushev
+
+}
+
+{$MODE ObjFPC}
+unit Sockets;
+
+Interface
+
+Uses
+  so32dll;
+
+Const
+  AF_LOCAL       = so32dll.AF_LOCAL;
+  AF_OS2         = so32dll.AF_OS2;
+  AF_IMPLINK     = so32dll.AF_IMPLINK;     // arpanet imp addresses
+  AF_PUP         = so32dll.AF_PUP;         // pup protocols: e.g. BSP
+  AF_CHAOS       = so32dll.AF_CHAOS;       // mit CHAOS protocols
+  AF_NS          = so32dll.AF_NS;          // XEROX NS protocols
+  AF_ISO         = so32dll.AF_ISO;         // ISO protocols
+  AF_OSI         = so32dll.AF_OSI;
+  AF_ECMA        = so32dll.AF_ECMA;        // european computer manufacturers
+  AF_DATAKIT     = so32dll.AF_DATAKIT;     // datakit protocols
+  AF_CCITT       = so32dll.AF_CCITT;       // CCITT protocols, X.25 etc
+  AF_SNA         = so32dll.AF_SNA;         // IBM SNA
+  AF_DECnet      = so32dll.AF_DECnet;      // DECnet
+  AF_DLI         = so32dll.AF_DLI;         // DEC Direct data link interface
+  AF_LAT         = so32dll.AF_LAT;         // LAT
+  AF_HYLINK      = so32dll.AF_HYLINK;      // NSC Hyperchannel
+  AF_APPLETALK   = so32dll.AF_APPLETALK;   // Apple Talk
+  AF_NB          = so32dll.AF_NB;          // Netbios
+  AF_NETBIOS     = so32dll.AF_NETBIOS;     // Netbios
+  AF_LINK        = so32dll.AF_LINK;        // Link layer interface
+  pseudo_AF_XTP  = so32dll.pseudo_AF_XTP;  // eXpress Transfer Protocol (no AF)
+  AF_COIP        = so32dll.AF_COIP;        // connection-oriented IP, aka ST II
+  AF_CNT         = so32dll.AF_CNT;         // Computer Network Technology
+  pseudo_AF_RTIP = so32dll.pseudo_AF_RTIP; // Help Identify RTIP packets
+  AF_IPX         = so32dll.AF_IPX;         // Novell Internet Protocol
+  AF_SIP         = so32dll.AF_SIP;         // Simple Internet Protocol
+  AF_INET6       = so32dll.AF_INET6;
+  pseudo_AF_PIP  = so32dll.pseudo_AF_PIP;  // Help Identify PIP packets
+  AF_ROUTE       = so32dll.AF_ROUTE;       // Internal Routing Protocol
+  AF_FWIP        = so32dll.AF_FWIP;        // firewall support
+  AF_IPSEC       = so32dll.AF_IPSEC;       // IPSEC and encryption techniques
+  AF_DES         = so32dll.AF_DES;         // DES
+  AF_MD5         = so32dll.AF_MD5;
+  AF_CDMF        = so32dll.AF_CDMF;
+
+  AF_MAX         = so32dll.AF_MAX;
+
+  PF_LOCAL     = so32dll.PF_LOCAL;
+  PF_OS2       = so32dll.PF_OS2;
+  PF_IMPLINK   = so32dll.PF_IMPLINK;
+  PF_PUP       = so32dll.PF_PUP;
+  PF_CHAOS     = so32dll.PF_CHAOS;
+  PF_NS        = so32dll.PF_NS;
+  PF_ISO       = so32dll.PF_ISO;
+  PF_OSI       = so32dll.PF_OSI;
+  PF_ECMA      = so32dll.PF_ECMA;
+  PF_DATAKIT   = so32dll.PF_DATAKIT;
+  PF_CCITT     = so32dll.PF_CCITT;
+  PF_SNA       = so32dll.PF_SNA;
+  PF_DECnet    = so32dll.PF_DECnet;
+  PF_DLI       = so32dll.PF_DLI;
+  PF_LAT       = so32dll.PF_LAT;
+  PF_HYLINK    = so32dll.PF_HYLINK;
+  PF_APPLETALK = so32dll.PF_APPLETALK;
+  PF_NETBIOS   = so32dll.PF_NB;
+  PF_NB        = so32dll.PF_NB;
+  PF_ROUTE     = so32dll.PF_ROUTE;
+  PF_LINK      = so32dll.PF_LINK;
+  PF_XTP       = so32dll.PF_XTP;  // really just proto family, no AF
+  PF_COIP      = so32dll.PF_COIP;
+  PF_CNT       = so32dll.PF_CNT;
+  PF_SIP       = so32dll.PF_SIP;
+  PF_INET6     = so32dll.PF_INET6;
+  PF_IPX       = so32dll.PF_IPX;     // same format as AF_NS
+  PF_RTIP      = so32dll.PF_RTIP;    // same format as AF_INET
+  PF_PIP       = so32dll.PF_PIP;
+
+  PF_MAX       = so32dll.PF_MAX;
+
+
+// OS/2 stack based on BSD stack
+{$DEFINE BSD}
+{$I socketsh.inc}
+
+Implementation
+
+{Include filerec and textrec structures}
+{$I filerec.inc}
+{$I textrec.inc}
+
+{******************************************************************************
+                          Basic Socket Functions
+******************************************************************************}
+
+Function socket(Domain,SocketType,Protocol:Longint):Longint;
+begin
+  Socket:=so32dll.Socket(Domain,SocketType,ProtoCol);
+  if Socket<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function Send(Sock:Longint;Const Buf;BufLen,Flags:Longint):Longint;
+begin
+  Send:=so32dll.Send(Sock,Buf,BufLen,Flags);
+  if Send<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function SendTo(Sock:Longint;Const Buf;BufLen,Flags:Longint;Var Addr; AddrLen : Longint):Longint;
+begin
+  SendTo:=so32dll.SendTo(Sock,Buf,BufLen,Flags,so32dll.SockAddr(Addr),AddrLen);
+  if SendTo<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function Recv(Sock:Longint;Var Buf;BufLen,Flags:Longint):Longint;
+begin
+  Recv:=so32dll.Recv(Sock,Buf,BufLen,Flags);
+  if Recv<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+
+Function RecvFrom(Sock : Longint; Var Buf; Buflen,Flags : Longint; Var Addr; AddrLen : Integer) : longint;
+
+begin
+  RecvFrom:=so32dll.RecvFrom(Sock,Buf,BufLen,Flags,so32dll.SockAddr(Addr),AddrLen);
+  if RecvFrom<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function Bind(Sock:Longint;Const Addr;AddrLen:Longint):Boolean;
+var
+  l : longint;
+begin
+  l:=so32dll.Bind(Sock,so32dll.sockaddr(Addr),AddrLen);
+  if l<0 then
+    begin
+       SocketError:=so32dll.sock_errno;
+       Bind:=false;
+    end
+  else
+    begin
+       SocketError:=0;
+       Bind:=true;
+    end;
+end;
+
+Function Listen(Sock,MaxConnect:Longint):Boolean;
+var
+  l : longint;
+begin
+  l:=so32dll.Listen(Sock,MaxConnect);
+  if l<0 then
+    begin
+       SocketError:=so32dll.sock_errno;
+       Listen:=false;
+    end
+  else
+    begin
+       SocketError:=0;
+       Listen:=true;
+    end;
+end;
+
+Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;
+begin
+  Accept:=so32dll.Accept(Sock,so32dll.SockAddr(Addr), AddrLen);
+  if Accept<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function Connect(Sock:Longint;Const Addr;Addrlen:Longint):Boolean;
+begin
+  Connect:=so32dll.Connect(Sock,so32dll.SockAddr(Addr),AddrLen)=0;
+  if not Connect then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function Shutdown(Sock:Longint;How:Longint):Longint;
+begin
+  ShutDown:=so32dll.ShutDown(Sock,How);
+  if ShutDown<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;
+begin
+  GetSocketName:=so32dll.GetSockName(Sock, so32dll.SockAddr(Addr),AddrLen);
+  if GetSocketName<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;
+begin
+  GetPeerName:=so32dll.GetPeerName(Sock,so32dll.SockAddr(Addr),AddrLen);
+  if GetPeerName<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function SetSocketOptions(Sock,Level,OptName:Longint;Const OptVal;optlen:longint):Longint;
+begin
+  SetSocketOptions:=so32dll.SetSockOpt(Sock,Level,OptName,OptVal,OptLen);
+  if SetSocketOptions<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;Var optlen:longint):Longint;
+begin
+  GetSocketOptions:=so32dll.GetSockOpt(Sock,Level,OptName,OptVal,OptLen);
+  if GetSocketOptions<0 then
+    SocketError:=so32dll.sock_errno
+  else
+    SocketError:=0;
+end;
+
+Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint;
+begin
+
+{!!TODO!!
+  SocketPair:=so32dll.socketpair(Domain,SocketType,Protocol,Pair);}
+  //SocketCall(Socket_Sys_SocketPair,Domain,SocketType,Protocol,longint(@Pair),0,0);
+end;
+
+{ mimic the linux fdWrite/fdRead calls for the file/text socket wrapper }
+function fdWrite(handle : longint;Const bufptr;size : dword) : dword;
+begin
+  fdWrite := so32dll.send(handle, bufptr, size, 0);
+  if fdWrite = -1 then
+  begin
+    SocketError := so32dll.sock_errno;
+    fdWrite := 0;
+  end
+  else
+    SocketError := 0;
+end;
+
+function fdRead(handle : longint;var bufptr;size : dword) : dword;
+var
+  d : dword;
+begin
+{!!TODO!!
+  if so32dll.ioctlsocket(handle,FIONREAD,@d) = -1 then
+  begin
+    SocketError:=so32dll.sock_errno;
+    fdRead:=0;
+    exit;
+  end;
+}
+  if d>0 then
+  begin
+    if size>d then
+    size:=d;
+    fdRead := so32dll.recv(handle, bufptr, size, 0);
+    if fdRead = -1 then
+    begin
+      SocketError:= so32dll.sock_errno;
+      fdRead := 0;
+    end else
+      SocketError:=0;
+  end
+  else
+    SocketError:=0;
+end;
+
+{$i sockets.inc}
+
+Begin
+  so32dll.sock_init;
+End.