netmgr.pp 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  1. {$MACRO ON}
  2. {$define Rsc := }
  3. (******************************************************************************
  4. *
  5. * Copyright (c) 1996-2000 Palm, Inc. or its subsidiaries.
  6. * All rights reserved.
  7. *
  8. * File: NetMgr.h
  9. *
  10. * Release: Palm OS SDK 4.0 (63220)
  11. *
  12. * Description:
  13. * This module contains the interface definition for the TCP/IP
  14. * library on Pilot.
  15. *
  16. * History:
  17. * 2/14/96 Created by Ron Marianetti
  18. * Name Date Description
  19. * ---- ---- -----------
  20. * jrb 3/13/98 Removed NetIFSettings that are Mobitex specific.
  21. * Added RadioStateEnum for the setting.
  22. * Added NetIFSettingSpecificMobitex
  23. * Added what are considered "generic" wirless settings.
  24. * jaq 10/1/98 added netMaxIPAddrStrLen constant
  25. * scl 3/ 5/99 integrated Eleven's changes into Main
  26. * jhl 7/14/00 added net notice
  27. *
  28. *****************************************************************************)
  29. unit netmgr;
  30. interface
  31. uses palmos, libtraps, errorbase, sysevent, event_;
  32. (********************************************************************
  33. * Type and creator of Net Library database
  34. ********************************************************************)
  35. // Creator. Used for both the database that contains the Net Library and
  36. // it's preferences database.
  37. const
  38. netCreator = Rsc('netl'); // Our Net Library creator
  39. // Feature Creators and numbers, for use with the FtrGet() call. This
  40. // feature can be obtained to get the current version of the Net Library
  41. netFtrCreator = netCreator;
  42. netFtrNumVersion = 0; // get version of Net Library
  43. // 0xMMmfsbbb, where MM is major version, m is minor version
  44. // f is bug fix, s is stage: 3-release,2-beta,1-alpha,0-development,
  45. // bbb is build number for non-releases
  46. // V1.12b3 would be: 0x01122003
  47. // V2.00a2 would be: 0x02001002
  48. // V1.01 would be: 0x01013000
  49. // Begin Change (BGT)
  50. // Feature for defining the number of command blocks to allocate
  51. netFtrCommandBlocks = 1; // get the number of command blocks
  52. // Types. Used to identify the Net Library from it's prefs.
  53. netLibType = Rsc('libr'); // Our Net Code Resources Database type
  54. netPrefsType = Rsc('rsrc'); // Our Net Preferences Database type
  55. // All Network interface's have the following type:
  56. netIFFileType = Rsc('neti'); // The filetype of all Network Interfaces
  57. // Each Network interface has a unique creator:
  58. netIFCreatorLoop = Rsc('loop'); // Loopback network interface creator.
  59. netIFCreatorSLIP = Rsc('slip'); // SLIP network interface creator.
  60. netIFCreatorPPP = Rsc('ppp_'); // PPP network interface creator.
  61. //<chg 1-28-98 RM>
  62. netIFCreatorRAM = Rsc('ram_'); // Mobitex network interface creator
  63. // Special value for configIndex parameter to NetLibOpenConfig that tells it
  64. // to use the current settings - even if they are not the defined default settings
  65. // This is provided for testing purposes
  66. netConfigIndexCurSettings = $FFFF;
  67. // <SCL 3/5/99> Commented out netMaxNetIFs since Tim says it should NOT be here!!
  68. // Still need to fix (Eleven) code that currently depends on it...
  69. // Max # of interfaces that can be installed
  70. // netMaxNetIFs = 4;
  71. //-----------------------------------------------------------------------------
  72. // Misc. constants
  73. //-----------------------------------------------------------------------------
  74. const
  75. netDrvrTypeNameLen = 8; // Maximum driver type length
  76. netDrvrHWNameLen = 16; // Maximum driver hardware name length
  77. netIFNameLen = 10; // Maximum interface name (driver type + instance num)
  78. netIFMaxHWAddrLen = 14; // Maximum size of a hardware address
  79. netMaxIPAddrStrLen = 16; // Max length of an IP address string with null terminator (255.255.255.255)
  80. //-----------------------------------------------------------------------------
  81. // Names of built-in configuration aliases available through the
  82. // NetLibConfigXXX calls
  83. //-----------------------------------------------------------------------------
  84. netCfgNameDefault = '.Default'; // The default configuration
  85. netCfgNameDefWireline = '.DefWireline'; // The default wireline configuration
  86. netCfgNameDefWireless = '.DefWireless'; // The default wireless configuration
  87. netCfgNameCTPWireline = '.CTPWireline'; // Wireline through the Jerry Proxy
  88. netCfgNameCTPWireless = '.CTPWireless'; // Wireless through the Jerry Proxy
  89. //-----------------------------------------------------------------------------
  90. //Flags for the NetUWirelessAppHandleEvent() utility routine
  91. //-----------------------------------------------------------------------------
  92. const
  93. netWLAppEventFlagCTPOnly = $00000001; // using wireless radio for CTP protocol only
  94. netWLAppEventFlagDisplayErrs = $00000002; // Show error alerts for any errors
  95. //-----------------------------------------------------------------------------
  96. // Option constants that can be passed to NetSocketOptionSet and NetSocketOptionGet
  97. // When an option is set or retrieved, both the level of the option and the
  98. // option number must be specified. The level refers to which layer the option
  99. // refers to, like the uppermost socket layer, for example.
  100. //-----------------------------------------------------------------------------
  101. // Socket level options
  102. type
  103. NetSocketOptEnum = WordEnum;
  104. const
  105. // IP Level options
  106. netSocketOptIPOptions = 1; // options in IP header (IP_OPTIONS)
  107. // TCP Level options
  108. netSocketOptTCPNoDelay = 1; // don't delay send to coalesce packets
  109. netSocketOptTCPMaxSeg = 2; // TCP maximum segment size (TCP_MAXSEG)
  110. // Socket level options
  111. netSocketOptSockDebug = $0001; // turn on debugging info recording
  112. netSocketOptSockAcceptConn = $0002; // socket has had listen
  113. netSocketOptSockReuseAddr = $0004; // allow local address reuse
  114. netSocketOptSockKeepAlive = $0008; // keep connections alive
  115. netSocketOptSockDontRoute = $0010; // just use interface addresses
  116. netSocketOptSockBroadcast = $0020; // permit sending of broadcast msgs
  117. netSocketOptSockUseLoopback = $0040; // bypass hardware when possible
  118. netSocketOptSockLinger = $0080; // linger on close if data present
  119. netSocketOptSockOOBInLine = $0100; // leave received OutOfBand data in line
  120. netSocketOptSockSndBufSize = $1001; // send buffer size
  121. netSocketOptSockRcvBufSize = $1002; // receive buffer size
  122. netSocketOptSockSndLowWater = $1003; // send low-water mark
  123. netSocketOptSockRcvLowWater = $1004; // receive low-water mark
  124. netSocketOptSockSndTimeout = $1005; // send timeout
  125. netSocketOptSockRcvTimeout = $1006; // receive timeout
  126. netSocketOptSockErrorStatus = $1007; // get error status and clear
  127. netSocketOptSockSocketType = $1008; // get socket type
  128. // The following are Pilot specific options
  129. netSocketOptSockNonBlocking = $2000; // set non-blocking mode on or off
  130. netSocketOptSockRequireErrClear = $2001; // return error from all further calls to socket
  131. // unless netSocketOptSockErrorStatus is cleared.
  132. netSocketOptSockMultiPktAddr = $2002; // for SOCK_RDM (RMP) sockets. This is the
  133. // fixed IP addr (i.e. Mobitex MAN #) to use
  134. // for multiple packet requests.
  135. // for socket notification
  136. // 05/20/00 jhl
  137. netSocketOptSockNotice = $2003; // prime socket for notification
  138. // Option levels for SocketOptionSet and SocketOptionGet
  139. type
  140. NetSocketOptLevelEnum = WordEnum;
  141. const
  142. netSocketOptLevelIP = 0; // IP level options (IPPROTO_IP)
  143. netSocketOptLevelTCP = 6; // TCP level options (IPPROTO_TCP)
  144. netSocketOptLevelSocket = $FFFF; // Socket level options (SOL_SOCKET)
  145. // Structure used for manipulating the linger option
  146. type
  147. NetSocketLingerType = record
  148. onOff: Int16; // option on/off
  149. time: Int16; // linger time in seconds
  150. end;
  151. //-----------------------------------------------------------------------------
  152. // Enumeration of Socket domains and types passed to NetSocketOpen
  153. //-----------------------------------------------------------------------------
  154. type
  155. NetSocketAddrEnum = Enum;
  156. const
  157. netSocketAddrRaw = 0; // (AF_UNSPEC, AF_RAW)
  158. netSocketAddrINET = 2; // (AF_INET)
  159. type
  160. NetSocketTypeEnum = Enum;
  161. const
  162. netSocketTypeStream = 1; // (SOCK_STREAM)
  163. netSocketTypeDatagram = 2; // (SOCK_DGRAM)
  164. netSocketTypeRaw = 3; // (SOCK_RAW)
  165. netSocketTypeReliableMsg = 4; // (SOCK_RDM)
  166. netSocketTypeLicensee = 8; // Socket entry reserved for licensees.
  167. // Protocols, passed in the protocol parameter to NetLibSocketOpen
  168. const
  169. netSocketProtoIPICMP = 1; // IPPROTO_ICMP
  170. netSocketProtoIPTCP = 6; // IPPROTO_TCP
  171. netSocketProtoIPUDP = 17; // IPPROTO_UDP
  172. netSocketProtoIPRAW = 255; // IPPROTO_RAW
  173. //-----------------------------------------------------------------------------
  174. // Enumeration of Socket direction, passed to NetSocketShutdown
  175. //-----------------------------------------------------------------------------
  176. type
  177. NetSocketDirEnum = Enum;
  178. const
  179. netSocketDirInput = 0;
  180. netSocketDirOutput = 1;
  181. netSocketDirBoth = 2;
  182. //-----------------------------------------------------------------------------
  183. // Basic Types
  184. //-----------------------------------------------------------------------------
  185. // Socket refnum
  186. type
  187. NetSocketRef = Int16;
  188. // Type used to hold internet addresses
  189. NetIPAddr = UInt32; // a 32-bit IP address.
  190. // IFMediaEvent notifications types
  191. type
  192. NetLibIFMediaEventNotificationTypeEnum = Enum;
  193. const
  194. netIFMediaUp = 1; // Usually sent by Network interfaces
  195. // after they have displayed the UI for displaying
  196. // connection establishment progress.
  197. netIFMediaDown = Succ(netIFMediaUp);
  198. // Sent by Network interface's when their inactivity timer
  199. // is ellapsed.
  200. // Notification structure sent in SysNotifyNetLibIFMedia.
  201. type
  202. SysNotifyNetLibIFMediaTag = record
  203. eType: NetLibIFMediaEventNotificationTypeEnum;
  204. ifCreator: UInt32; // interface creator
  205. ifInstance: UInt16; // interface instance
  206. end;
  207. SysNotifyNetLibIFMediaType = SysNotifyNetLibIFMediaTag;
  208. //-----------------------------------------------------------------------------
  209. // For socket notification
  210. // 05/20/00 jhl
  211. //-----------------------------------------------------------------------------
  212. // Notice types
  213. type
  214. NoticeTypeEnum = Enum;
  215. const
  216. netSocketNoticeNotify = 1;
  217. // ummmm...
  218. // shouldn't do this - must fix EventMgr before background/ISR events can be posted
  219. netSocketNoticeEvent = Succ(netSocketNoticeNotify);
  220. netSocketNoticeMailbox = Succ(netSocketNoticeEvent);
  221. netSocketNoticeCallback = Succ(netSocketNoticeMailbox);
  222. netSocketNoticeWake = Succ(netSocketNoticeCallback);
  223. // Notification structure sent for netSocketNoticeNotify.
  224. type
  225. SysNotifyNetSocketType = record
  226. socketRef: NetSocketRef; // Socket sending the notification
  227. condition: UInt32; // Bit field reporting trigger conditions
  228. end;
  229. // Event structure sent for netSocketNoticeEvent.
  230. // This should be defined via Event.h, so it stays in sync.
  231. type
  232. netSocketNotice = record
  233. socketRef: NetSocketRef; // Socket sending the notification
  234. condition: UInt32; // Bit field reporting trigger conditions
  235. end;
  236. type
  237. NetSocketNoticeEventType = record
  238. eType: eventsEnum; // User specified event type
  239. penDown: Boolean;
  240. tapCount: UInt8;
  241. screenX: Int16;
  242. screenY: Int16;
  243. case Integer of
  244. 1: (generic: _GenericEventType); // Establish size of union
  245. 2: (netSocketNotice: netSocketNotice);
  246. end;
  247. // Mailbox structure sent for netSocketNoticeMailbox.
  248. type
  249. NetSocketNoticeMailboxType = record
  250. message_: UInt32; // User specified message
  251. reserved: UInt16;
  252. socketRef: NetSocketRef; // Socket sending the notification
  253. condition: UInt32; // Bit field reporting trigger conditions
  254. end;
  255. // Callback definition for netSocketNoticeCallback.
  256. type
  257. NetSocketNoticeCallbackPtr = function(userDataP: Pointer; socketRef: UInt16; condition: UInt32): Err;
  258. type
  259. notify = record
  260. notifyType: UInt32; // Notification type
  261. // sends SysNotifyNetSocketType in notification
  262. end;
  263. type
  264. event = record
  265. eType: eventsEnum; // Event type
  266. // adds NetSocketNoticeEventType event to UI event queue
  267. end;
  268. type
  269. mailbox = record
  270. mailboxID: UInt32; // ID of mailbox for send
  271. message_: UInt32; // first element of mailbox message
  272. wAck: UInt32; // third argument to SysMailboxSend()
  273. // sends NetSocketNoticeMailboxType message to specified mailboxID
  274. end;
  275. type
  276. callback = record
  277. callbackP: NetSocketNoticeCallbackPtr; // Callback proc pointer
  278. userDataP: Pointer; // User specified ptr passed as callback parameter
  279. // (*callbackP)(userDataP,socketRef,condition)
  280. end;
  281. type
  282. wake = record
  283. taskID: UInt32; // ID of task to wake
  284. socketRefP: ^NetSocketRef; // address to receive socketRef
  285. conditionP: ^UInt32; // address to receive trigger condition
  286. end;
  287. // Structure used to register for a notice
  288. type
  289. NetSocketNoticeType = record
  290. condition: UInt32; // Bit field specifying trigger conditions
  291. type_: NoticeTypeEnum; // Notice type
  292. case Integer of
  293. 1: (notify: notify);
  294. // ummmm...
  295. // shouldn't do this - must fix EventMgr before background/ISR events can be posted
  296. 2: (event: event);
  297. 3: (mailbox: mailbox);
  298. 4: (callback: callback);
  299. 5: (wake: wake); // SysTaskWake(taskID)
  300. end;
  301. // Bit values for specifying and reporting trigger conditions
  302. const
  303. netSocketNoticeErr = $00000001;
  304. netSocketNoticeUDPReceive = $00000002;
  305. netSocketNoticeTCPReceive = $00000004;
  306. netSocketNoticeTCPTransmit = $00000008;
  307. netSocketNoticeTCPRemoteClosed = $00000010;
  308. netSocketNoticeTCPClosed = $00000020;
  309. netSocketNoticeConnectInbound = $00000040;
  310. netSocketNoticeConnectOutbound = $00000080;
  311. //-----------------------------------------------------------------------------
  312. // Structure used to hold an internet socket address. This includes the internet
  313. // address and the port number. This structure directly maps to the BSD unix
  314. // struct sockaddr_in.
  315. //-----------------------------------------------------------------------------
  316. type
  317. NetSocketAddrINType = record
  318. family: Int16; // Address family in HBO (Host UInt8 Order)
  319. port: UInt16; // the UDP port in NBO (Network UInt8 Order)
  320. addr: NetIPAddr; // IP address in NBO (Network UInt8 Order)
  321. end;
  322. // Constant that means "use the local machine's IP address"
  323. const
  324. netIPAddrLocal = 0; // Can be used in NetSockAddrINType.addr
  325. // Structure used to hold a generic socket address. This is a generic struct
  326. // designed to hold any type of address including internet addresses. This
  327. // structure directly maps to the BSD unix struct sockaddr.
  328. type
  329. NetSocketAddrType = record
  330. family: Int16; // Address family
  331. data: array [0..14-1] of UInt8; // 14 bytes of address
  332. end;
  333. NetSocketAddrPtr = ^NetSocketAddrType;
  334. // Structure used to hold a raw socket address. When using the netSocketAddrRaw
  335. // protocol family, the caller must bind() the socket to an interface and
  336. // specifies the interface using this structure. IMPORTANT: NUMEROUS
  337. // ROUTINES IN NETLIB RELY ON THE FACT THAT THIS STRUCTURE IS THE SAME
  338. // SIZE AS A NetSocketAddrINType STRUCTURE.
  339. type
  340. NetSocketAddrRawType = record
  341. family: Int16; // Address family in HBO (Host UInt8 Order)
  342. ifInstance: UInt16; // the interface instance number
  343. ifCreator: UInt32; // the interface creator
  344. end;
  345. //-----------------------------------------------------------------------------
  346. // Structure used to hold information about data to be sent. This structure
  347. // is passed to NetLibSendMsg and contains the optional address to send to,
  348. // a scatter-write array of data to be sent, and optional access rights
  349. //-----------------------------------------------------------------------------
  350. // Scatter/Gather array type. A pointer to an array of these structs is
  351. // passed to the NetLibSendPB and NetLibRecvPB calls. It specifies where
  352. // data should go to or come from as a list of buffer addresses and sizes.
  353. type
  354. NetIOVecType = record
  355. bufP: ^UInt8; // buffer address
  356. bufLen: UInt16; // buffer length
  357. end;
  358. NetIOVecPtr = ^NetIOVecType;
  359. const
  360. netIOVecMaxLen = 16; // max# of NetIOVecTypes in an array
  361. // Read/Write ParamBlock type. Passed directly to the SendPB and RecvPB calls.
  362. type
  363. NetIOParamType = record
  364. addrP: ^UInt8; // address - or 0 for default
  365. addrLen: UInt16; // length of address
  366. iov: NetIOVecPtr; // scatter/gather array
  367. iovLen: UInt16; // length of above array
  368. accessRights: ^UInt8; // access rights
  369. accessRightsLen: UInt16; // length of accessrights
  370. end;
  371. NetIOParamPtr = ^NetIOParamType;
  372. // Flags values for the NetLibSend, NetLibReceive calls
  373. const
  374. netIOFlagOutOfBand = $01; // process out-of-band data
  375. netIOFlagPeek = $02; // peek at incoming message
  376. netIOFlagDontRoute = $04; // send without using routing
  377. //-----------------------------------------------------------------------------
  378. // Structures used for looking up a host by name or address (NetLibGetHostByName)
  379. //-----------------------------------------------------------------------------
  380. // Equates for DNS names, from RFC-1035
  381. netDNSMaxDomainName = 255;
  382. netDNSMaxDomainLabel = 63;
  383. netDNSMaxAliases = 1; // max # of aliases for a host
  384. netDNSMaxAddresses = 4; // max # of addresses for a host
  385. // The actual results of NetLibGetHostByName() are returned in this structure.
  386. // This structure is designed to match the "struct hostent" structure in Unix.
  387. type
  388. NetHostInfoType = record
  389. nameP: PChar; // official name of host
  390. nameAliasesP: ^PChar; // array of alias's for the name
  391. addrType: UInt16; // address type of return addresses
  392. addrLen: UInt16; // the length, in bytes, of the addresses
  393. // Note this denotes length of a address, not # of addresses.
  394. addrListP: ^UInt8Ptr; // array of ptrs to addresses in HBO
  395. end;
  396. NetHostInfoPtr = ^NetHostInfoType;
  397. // "Buffer" passed to call as a place to store the results
  398. NetHostInfoBufType = record
  399. hostInfo: NetHostInfoType; // high level results of call are here
  400. // The following fields contain the variable length data that
  401. // hostInfo points to
  402. name: array [0..netDNSMaxDomainName] of Char; // hostInfo->name
  403. aliasList: array [0..netDNSMaxAliases] of PChar; // +1 for 0 termination.
  404. aliases: array [0..netDNSMaxAliases-1, 0..netDNSMaxDomainName] of Char;
  405. addressList: array [0..netDNSMaxAddresses-1] of ^NetIPAddr;
  406. address: array [0..netDNSMaxAddresses-1] of NetIPAddr;
  407. end;
  408. NetHostInfoBufPtr = ^NetHostInfoBufType;
  409. //-----------------------------------------------------------------------------
  410. // Structures used for looking up a service (NetLibGetServByName)
  411. //-----------------------------------------------------------------------------
  412. // Equates for service names
  413. const
  414. netServMaxName = 15; // max # characters in service name
  415. netProtoMaxName = 15; // max # characters in protocol name
  416. netServMaxAliases = 1; // max # of aliases for a service
  417. // The actual results of NetLibGetServByName() are returned in this structure.
  418. // This structure is designed to match the "struct servent" structure in Unix.
  419. type
  420. NetServInfoType = record
  421. nameP: PChar; // official name of service
  422. nameAliasesP: ^PChar; // array of alias's for the name
  423. port: UInt16; // port number for this service
  424. protoP: PChar; // name of protocol to use
  425. end;
  426. NetServInfoPtr = ^NetServInfoType;
  427. // "Buffer" passed to call as a place to store the results
  428. NetServInfoBufType = record
  429. servInfo: NetServInfoType; // high level results of call are here
  430. // The following fields contain the variable length data that
  431. // servInfo points to
  432. name: array [0..netServMaxName] of Char; // hostInfo->name
  433. aliasList: array [0..netServMaxAliases] of PChar; // +1 for 0 termination.
  434. aliases: array [0..netServMaxAliases-1, 0..netServMaxName-1] of Char;
  435. protoName: array [0..netProtoMaxName] of Char;
  436. reserved: UInt8;
  437. end;
  438. NetServInfoBufPtr = ^NetServInfoBufType;
  439. //--------------------------------------------------------------------
  440. // Structure of a configuration name. Used by NetLibConfigXXX calls
  441. // <chg 1-28-98 RM> added for the new Config calls.
  442. //---------------------------------------------------------------------
  443. const
  444. netConfigNameSize = 32;
  445. type
  446. NetConfigNameType = record
  447. name: array [0..netConfigNameSize-1] of Char; // name of configuration
  448. end;
  449. NetConfigNamePtr = ^NetConfigNameType;
  450. (********************************************************************
  451. * Tracing Flags. These flags are ORed together and passed as a UInt32
  452. * in the netSettingTraceFlags setting and netIFSettingTraceFlags to
  453. * enable/disable various trace options.
  454. ********************************************************************)
  455. const
  456. netTracingErrors = $00000001; // record errors
  457. netTracingMsgs = $00000002; // record messages
  458. netTracingPktIP = $00000004; // record packets sent/received
  459. // to/from interfaces at the IP layer
  460. // NOTE: netTracingPktData40 & netTracingPktData
  461. // will control how much data of each packet is
  462. // recorded.
  463. netTracingFuncs = $00000008; // record function flow
  464. netTracingAppMsgs = $00000010; // record application messages
  465. // (NetLibTracePrintF, NetLibTracePutS)
  466. netTracingPktData40 = $00000020; // record first 40 bytes of packets
  467. // when netTracingPktsXX is also on.
  468. // NOTE: Mutually exclusive with
  469. // netTracingPktData and only applicable if
  470. // one of the netTracingPktsXX bits is also set
  471. netTracingPktData = $00000040; // record all bytes of IP packets
  472. // sent/received to/from interfaces
  473. // NOTE: Mutually exclusive with
  474. // netTracingPkts & netTracingPktData64
  475. netTracingPktIFHi = $00000080; // record packets sent/received at highest layer
  476. // of interface (just below IP layer).
  477. // NOTE: netTracingPktData40 & netTracingPktData
  478. // will control how much data of each packet is
  479. // recorded.
  480. netTracingPktIFMid = $00000100; // record packets sent/received at mid layer
  481. // of interface (just below IFHi layer).
  482. // NOTE: netTracingPktData40 & netTracingPktData
  483. // will control how much data of each packet is
  484. // recorded.
  485. netTracingPktIFLow = $00000200; // record packets sent/received at low layer
  486. // of interface (just below IFMid layer).
  487. // NOTE: netTracingPktData40 & netTracingPktData
  488. // will control how much data of each packet is
  489. // recorded.
  490. // OBSOLETE tracing bit, still used by Network Panel
  491. netTracingPkts = netTracingPktIP;
  492. (********************************************************************
  493. * Command numbers and parameter blocks for the NetLibMaster() call.
  494. * This call is used to put the Net library into certain debugging modes
  495. * or for obtaining statistics from the Net Library.
  496. *
  497. ********************************************************************)
  498. type
  499. NetMasterEnum = Enum;
  500. const
  501. // These calls return info
  502. netMasterInterfaceInfo = 0;
  503. netMasterInterfaceStats = Succ(netMasterInterfaceInfo);
  504. netMasterIPStats = Succ(netMasterInterfaceStats);
  505. netMasterICMPStats = Succ(netMasterIPStats);
  506. netMasterUDPStats = Succ(netMasterICMPStats);
  507. netMasterTCPStats = Succ(netMasterUDPStats);
  508. // This call used to read the trace buffer.
  509. netMasterTraceEventGet = Succ(netMasterTCPStats); // get trace event by index
  510. type
  511. //.............................................................
  512. // InterfaceInfo command
  513. //.............................................................
  514. interfaceInfo = record
  515. index: UInt16; // -> index of interface
  516. creator: UInt32; // <- creator
  517. instance: UInt16; // <- instance
  518. netIFP: Pointer; // <- net_if pointer
  519. // driver level info
  520. drvrName: array [0..netDrvrTypeNameLen-1] of Char; // <- type of driver (SLIP,PPP, etc)
  521. hwName: array [0..netDrvrHWNameLen-1] of Char; // <- hardware name (Serial Library, etc)
  522. localNetHdrLen: UInt8; // <- local net header length
  523. localNetTrailerLen: UInt8; // <- local net trailer length
  524. localNetMaxFrame: UInt16; // <- local net maximum frame size
  525. // media layer info
  526. ifName: array [0..netIFNameLen-1] of Char; // <- interface name w/instance
  527. driverUp: Boolean; // <- true if interface driver up
  528. ifUp: Boolean; // <- true if interface is up
  529. hwAddrLen: UInt16; // <- length of hardware address
  530. hwAddr: array [0..netIFMaxHWAddrLen-1] of UInt8; // <- hardware address
  531. mtu: UInt16; // <- maximum transfer unit of interface
  532. speed: UInt32; // <- speed in bits/sec.
  533. lastStateChange: UInt32; // <- time in milliseconds of last state change
  534. // Address info
  535. ipAddr: NetIPAddr; // Address of this interface
  536. subnetMask: NetIPAddr; // subnet mask of local network
  537. broadcast: NetIPAddr; // broadcast address of local network
  538. end;
  539. //.............................................................
  540. // InterfaceStats command
  541. //.............................................................
  542. interfaceStats = record
  543. index: UInt16; // -> index of interface
  544. inOctets: UInt32; // <- ....
  545. inUcastPkts: UInt32;
  546. inNUcastPkts: UInt32;
  547. inDiscards: UInt32;
  548. inErrors: UInt32;
  549. inUnknownProtos: UInt32;
  550. outOctets: UInt32;
  551. outUcastPkts: UInt32;
  552. outNUcastPkts: UInt32;
  553. outDiscards: UInt32;
  554. outErrors: UInt32;
  555. end;
  556. //.............................................................
  557. // IPStats command
  558. //.............................................................
  559. ipStats = record
  560. ipInReceives: UInt32;
  561. ipInHdrErrors: UInt32;
  562. ipInAddrErrors: UInt32;
  563. ipForwDatagrams: UInt32;
  564. ipInUnknownProtos: UInt32;
  565. ipInDiscards: UInt32;
  566. ipInDelivers: UInt32;
  567. ipOutRequests: UInt32;
  568. ipOutDiscards: UInt32;
  569. ipOutNoRoutes: UInt32;
  570. ipReasmReqds: UInt32;
  571. ipReasmOKs: UInt32;
  572. ipReasmFails: UInt32;
  573. ipFragOKs: UInt32;
  574. ipFragFails: UInt32;
  575. ipFragCreates: UInt32;
  576. ipRoutingDiscards: UInt32;
  577. ipDefaultTTL: UInt32;
  578. ipReasmTimeout: UInt32;
  579. end;
  580. //.............................................................
  581. // ICMPStats command
  582. //.............................................................
  583. icmpStats = record
  584. icmpInMsgs: UInt32;
  585. icmpInErrors: UInt32;
  586. icmpInDestUnreachs: UInt32;
  587. icmpInTimeExcds: UInt32;
  588. icmpInParmProbs: UInt32;
  589. icmpInSrcQuenchs: UInt32;
  590. icmpInRedirects: UInt32;
  591. icmpInEchos: UInt32;
  592. icmpInEchoReps: UInt32;
  593. icmpInTimestamps: UInt32;
  594. icmpInTimestampReps: UInt32;
  595. icmpInAddrMasks: UInt32;
  596. icmpInAddrMaskReps: UInt32;
  597. icmpOutMsgs: UInt32;
  598. icmpOutErrors: UInt32;
  599. icmpOutDestUnreachs: UInt32;
  600. icmpOutTimeExcds: UInt32;
  601. icmpOutParmProbs: UInt32;
  602. icmpOutSrcQuenchs: UInt32;
  603. icmpOutRedirects: UInt32;
  604. icmpOutEchos: UInt32;
  605. icmpOutEchoReps: UInt32;
  606. icmpOutTimestamps: UInt32;
  607. icmpOutTimestampReps: UInt32;
  608. icmpOutAddrMasks: UInt32;
  609. icmpOutAddrMaskReps: UInt32;
  610. end;
  611. //.............................................................
  612. // UDPStats command
  613. //.............................................................
  614. udpStats = record
  615. udpInDatagrams: UInt32;
  616. udpNoPorts: UInt32;
  617. udpInErrors: UInt32;
  618. udpOutDatagrams: UInt32;
  619. end;
  620. //.............................................................
  621. // TCPStats command
  622. //.............................................................
  623. tcpStats = record
  624. tcpRtoAlgorithm: UInt32;
  625. tcpRtoMin: UInt32;
  626. tcpRtoMax: UInt32;
  627. tcpMaxConn: UInt32;
  628. tcpActiveOpens: UInt32;
  629. tcpPassiveOpens: UInt32;
  630. tcpAttemptFails: UInt32;
  631. tcpEstabResets: UInt32;
  632. tcpCurrEstab: UInt32;
  633. tcpInSegs: UInt32;
  634. tcpOutSegs: UInt32;
  635. tcpRetransSegs: UInt32;
  636. tcpInErrs: UInt32;
  637. tcpOutRsts: UInt32;
  638. end;
  639. //.............................................................
  640. // TraceEventGet command
  641. //.............................................................
  642. traceEventGet = record
  643. index: UInt16; // which event
  644. textP: PChar; // ptr to text string to return it in
  645. end;
  646. type
  647. NetMasterPBType = record
  648. // These fields are specific to each command
  649. case Integer of
  650. 0: (interfaceInfo: interfaceInfo);
  651. 1: (interfaceStats: interfaceStats);
  652. 2: (ipStats: ipStats);
  653. 3: (icmpStats: icmpStats);
  654. 4: (udpStats: udpStats);
  655. 5: (tcpStats: tcpStats);
  656. 6: (traceEventGet: traceEventGet);
  657. end;
  658. NetMasterPBPtr = ^NetMasterPBType;
  659. //-----------------------------------------------------------------------------
  660. // Enumeration of Net settings as passed to NetLibSettingGet/Set.
  661. //-----------------------------------------------------------------------------
  662. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  663. // Global environment settings common to all attached network interfaces,
  664. // passed to NetLibSettingGet/Set
  665. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  666. type
  667. NetSettingEnum = WordEnum;
  668. const
  669. netSettingResetAll = 0; // void, NetLibSettingSet only, resets all settings
  670. // to their defaults.
  671. netSettingPrimaryDNS = Succ(netSettingResetAll); // UInt32, IP address of Primary DN Server
  672. netSettingSecondaryDNS = Succ(netSettingPrimaryDNS); // UInt32, IP address of Secondary DN Server
  673. netSettingDefaultRouter = Succ(netSettingSecondaryDNS); // UInt32, IP address of Default router
  674. netSettingDefaultIFCreator = Succ(netSettingDefaultRouter); // UInt32, Creator type of default interface
  675. netSettingDefaultIFInstance = Succ(netSettingDefaultIFCreator); // UInt16, Instance# of default interface
  676. netSettingHostName = Succ(netSettingDefaultIFInstance); // Char[64], name of host (not including domain)
  677. netSettingDomainName = Succ(netSettingHostName); // Char[256], domain name of hosts's domain
  678. netSettingHostTbl = Succ(netSettingDomainName); // Char[], host table
  679. netSettingCloseWaitTime = Succ(netSettingHostTbl); // UInt32, time in milliseconds to stay in close-wait state
  680. netSettingInitialTCPResendTime = Succ(netSettingCloseWaitTime); // UInt32, time in milliseconds before TCP resends a packet.
  681. // This is just the initial value, the timeout is adjusted
  682. // from this initial value depending on history of ACK times.
  683. // This is sometimes referred to as the RTO (Roundtrip Time Out)
  684. // See RFC-1122 for additional information.
  685. // The following settings are not used for configuration, but rather put the
  686. // stack into various modes for debugging, etc.
  687. netSettingTraceBits = $1000; // UInt32, enable/disable various trace flags (netTraceBitXXXX)
  688. netSettingTraceSize = Succ(netSettingTraceBits); // UInt32, max trace buffer size in bytes. Default 0x800.
  689. // Setting this will also clear the trace buffer.
  690. netSettingTraceStart = Succ(netSettingTraceSize); // UInt32, for internal use ONLY!!
  691. netSettingTraceRoll = Succ(netSettingTraceStart); // UInt8, if true, trace buffer will rollover after it fills.
  692. // Default is true.
  693. netSettingRTPrimaryDNS = Succ(netSettingTraceRoll); // used internally by Network interfaces
  694. // that dynamically obtain the DNS address
  695. netSettingRTSecondaryDNS = Succ(netSettingRTPrimaryDNS); // used internally by Network interfaces
  696. // that dynamically obtain the DNS address
  697. netSettingConfigTable = Succ(netSettingRTSecondaryDNS); // used internally by NetLib - NOT FOR USE BY
  698. // APPLICATIONS!!
  699. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  700. // Settings for each Network Interface, passed to NetLibIFSettingGet/Set
  701. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  702. type
  703. NetIFSettingEnum = WordEnum;
  704. const
  705. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  706. // Reset all settings to defaults
  707. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  708. netIFSettingResetAll = 0; // void, NetLibIFSettingSet only, resets all settings
  709. // to their defaults.
  710. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  711. // Status - read only
  712. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  713. netIFSettingUp = Succ(netIFSettingResetAll); // UInt8, true if interface is UP.
  714. netIFSettingName = Succ(netIFSettingUp); // Char[32], name of interface
  715. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  716. // Addressing
  717. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  718. netIFSettingReqIPAddr = Succ(netIFSettingName); // UInt32, requested IP address of this interface
  719. netIFSettingSubnetMask = Succ(netIFSettingReqIPAddr); // UInt32, subnet mask of this interface
  720. netIFSettingBroadcast = Succ(netIFSettingSubnetMask); // UInt32, broadcast address for this interface
  721. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  722. // User Info
  723. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  724. netIFSettingUsername = Succ(netIFSettingBroadcast); // Char[], login script user name
  725. // If 0 length, then user will be prompted for it
  726. netIFSettingPassword = Succ(netIFSettingUsername); // Char[], login script user password
  727. // If 0 length, then user will be prompted for it
  728. netIFSettingDialbackUsername = Succ(netIFSettingPassword); // Char[], login script dialback user name.
  729. // If 0 length, then netIFSettingUsername is used
  730. netIFSettingDialbackPassword = Succ(netIFSettingDialbackUsername); // Char[], login script dialback user password.
  731. // If 0 length, then user will be prompted for it
  732. netIFSettingAuthUsername = Succ(netIFSettingDialbackPassword); // Char[], PAP/CHAP name.
  733. // If 0 length, then netIFSettingUsername is used
  734. netIFSettingAuthPassword = Succ(netIFSettingAuthUsername); // Char[], PAP/CHAP password.
  735. // If "$", then user will be prompted for it
  736. // else If 0 length, then netIFSettingPassword or result
  737. // of it's prompt (if it was empty) will be used
  738. // else it is used as-is.
  739. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  740. // Connect Settings
  741. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  742. netIFSettingServiceName = Succ(netIFSettingAuthPassword); // Char[], name of service
  743. netIFSettingLoginScript = Succ(netIFSettingServiceName); // Char[], login script
  744. netIFSettingConnectLog = Succ(netIFSettingLoginScript); // Char[], connect log
  745. netIFSettingInactivityTimeout = Succ(netIFSettingConnectLog); // UInt16, # of seconds of inactivity allowed before
  746. // interface is brought down. If 0 then
  747. // no inactivity timeout enforced.
  748. netIFSettingEstablishmentTimeout = Succ(netIFSettingInactivityTimeout); // UInt16, max delay in seconds between connection
  749. // establishment stages
  750. // Serial based protocol options
  751. netIFSettingDynamicIP = Succ(netIFSettingEstablishmentTimeout); // UInt8, if true, get IP address from server
  752. // N/A for SLIP
  753. netIFSettingVJCompEnable = Succ(netIFSettingDynamicIP); // UInt8, if true enable VJ Header compression
  754. // Default is on for PPP, off for SLIP
  755. netIFSettingVJCompSlots = Succ(netIFSettingVJCompEnable); // UInt8, # of slots to use for VJ compression.
  756. // Default is 4 for PPP, 16 for SLIP
  757. // (each slot uses 256 bytes of RAM).
  758. netIFSettingMTU = Succ(netIFSettingVJCompSlots); // UInt16, maximum transmission unit in bytes
  759. // ignored in current PPP and SLIP interfaces
  760. netIFSettingAsyncCtlMap = Succ(netIFSettingMTU); // UInt32, bitmask of characters to escape
  761. // ignored in current PPP interfaces
  762. // Serial settings, used by serial based network interfaces
  763. netIFSettingPortNum = Succ(netIFSettingAsyncCtlMap); // UInt16, port number to use
  764. netIFSettingBaudRate = Succ(netIFSettingPortNum); // UInt32, baud rate in bits/sec.
  765. netIFSettingFlowControl = Succ(netIFSettingBaudRate); // UInt8, flow control setting bits. Set to 0x01 for
  766. // hardware flow control, else set to 0x00.
  767. netIFSettingStopBits = Succ(netIFSettingFlowControl); // UInt8, # of stop bits
  768. netIFSettingParityOn = Succ(netIFSettingStopBits); // UInt8, true if parity on
  769. netIFSettingParityEven = Succ(netIFSettingParityOn); // UInt8, true if parity even
  770. // Modem settings, optionally used by serial based network interfaces
  771. netIFSettingUseModem = Succ(netIFSettingParityEven); // UInt8, if true dial-up through modem
  772. netIFSettingPulseDial = Succ(netIFSettingUseModem); // UInt8, if true use pulse dial, else tone
  773. netIFSettingModemInit = Succ(netIFSettingPulseDial); // Char[], modem initialization string
  774. netIFSettingModemPhone = Succ(netIFSettingModemInit); // Char[], modem phone number string
  775. netIFSettingRedialCount = Succ(netIFSettingModemPhone); // UInt16, # of times to redial
  776. //---------------------------------------------------------------------------------
  777. // New Settings as of PalmOS 3.0
  778. // Power control, usually only implemented by wireless interfaces
  779. //---------------------------------------------------------------------------------
  780. netIFSettingPowerUp = Succ(netIFSettingRedialCount); // UInt8, true if this interface is powered up
  781. // false if this interface is in power-down mode
  782. // interfaces that don't support power modes should
  783. // quietly ignore this setting.
  784. // Wireless or Wireline, read-only, returns true for wireless interfaces. this
  785. // setting is used by application level functions to determine which interface(s)
  786. // to attach/detach given user preference and/or state of the antenna.
  787. netIFSettingWireless = Succ(netIFSettingPowerUp); // UInt8, true if this interface is wireless
  788. // Option to query server for address of DNS servers
  789. netIFSettingDNSQuery = Succ(netIFSettingWireless); // UInt8, if true PPP queries for DNS address. Default true
  790. //---------------------------------------------------------------------------------
  791. // New Settings as of PalmOS 3.2
  792. // Power control, usually only implemented by wireless interfaces
  793. //---------------------------------------------------------------------------------
  794. netIFSettingQuitOnTxFail = Succ(netIFSettingDNSQuery); // BYTE W-only. Power down RF on tx fail
  795. netIFSettingQueueSize = Succ(netIFSettingQuitOnTxFail); // UInt8 R-only. The size of the Tx queue in the RF interface
  796. netIFSettingTxInQueue = Succ(netIFSettingQueueSize); // BYTE R-only. Packets remaining to be sent
  797. netIFSettingTxSent = Succ(netIFSettingTxInQueue); // BYTE R-only. Packets sent since SocketOpen
  798. netIFSettingTxDiscard = Succ(netIFSettingTxSent); // BYTE R-only. Packets discarded on SocketClose
  799. netIFSettingRssi = Succ(netIFSettingTxDiscard); // char R-only. signed value in dBm.
  800. netIFSettingRssiAsPercent = Succ(netIFSettingRssi); // char R-only. signed value in percent, with 0 being no coverage and 100 being excellent.
  801. netIFSettingRadioState = Succ(netIFSettingRssiAsPercent); // enum R-only. current state of the radio
  802. netIFSettingBase = Succ(netIFSettingRadioState); // UInt32 R-only. Interface specific
  803. netIFSettingRadioID = Succ(netIFSettingBase); // UInt32[2] R-only, two 32-bit. interface specific
  804. netIFSettingBattery = Succ(netIFSettingRadioID); // UInt8, R-only. percentage of battery left
  805. netIFSettingNetworkLoad = Succ(netIFSettingBattery); // UInt8, R-only. percent estimate of network loading
  806. //---------------------------------------------------------------------------------
  807. // New Settings as of PalmOS 3.3
  808. //---------------------------------------------------------------------------------
  809. netIFSettingConnectionName = Succ(netIFSettingNetworkLoad); // Char [] Connection Profile Name
  810. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  811. // The following settings are not used for configuration, but rather put the
  812. // stack into various modes for debugging, etc.
  813. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  814. netIFSettingTraceBits = $1000; // UInt32, enable/disable various trace flags (netTraceBitXXXX)
  815. netIFSettingGlobalsPtr = Succ(netIFSettingTraceBits); // UInt32, (Read-Only) sinterface's globals ptr
  816. netIFSettingActualIPAddr = Succ(netIFSettingGlobalsPtr); // UInt32, (Read-Only) the actual IP address that the interface
  817. // ends up using. The login script executor stores
  818. // the result of the "g" script command here as does
  819. // the PPP negotiations.
  820. netIFSettingServerIPAddr = Succ(netIFSettingActualIPAddr); // UInt32, (Read-Only) the IP address of the PPP server
  821. // we're connected to
  822. // The following setting should be true if this network interface should be
  823. // brought down when the Pilot is turned off.
  824. netIFSettingBringDownOnPowerDown = Succ(netIFSettingServerIPAddr); // UInt8, if true interface will be brought down when
  825. // Pilot is turned off.
  826. // The following setting is used by the TCP/IP stack ONLY!! It tells the interface
  827. // to pass all received packets as-is to the NetIFCallbacksPtr->raw_rcv() routine.
  828. // This setting gets setup when an application creates a raw socket in the raw domain
  829. netIFSettingRawMode = Succ(netIFSettingBringDownOnPowerDown); // UInt32, parameter to pass to raw_rcv() along with
  830. // packet pointer.
  831. //---------------------------------------------------------------------------------
  832. // New Settings as of PalmOS 4.0
  833. //---------------------------------------------------------------------------------
  834. // The following setting is a new interface in PalmOS 4.0 that allow INetlib
  835. // or other NetLib clients to get raw location information as described in
  836. // PalmLocRawData.h.
  837. // NetLib will return a pointer to a newly allocated memory buffer containing
  838. // the raw location information to send to Elaine (Web Clipping proxy server).
  839. // Elaine will then use a Windows DLL to analyse the raw location information
  840. // in order to transform it into something useful like zipcode, cityname, etc.
  841. // See PalmLocRawData.h for more details...
  842. netIFSettingLocRawInfo = Succ(netIFSettingRawMode); // void* R-only: Allocated memory buffer - must be free by caller
  843. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  844. // 3rd party settings start here...
  845. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  846. netIFSettingCustom = $8000;
  847. //=========================================================================================
  848. // Enums for the netIFSettingRadioState setting
  849. //
  850. // JB added for the radio state setting.
  851. // <chg 3-17-98 RM> fixed naming conventions.
  852. //=========================================================================================
  853. type
  854. NetRadioStateEnum = Enum;
  855. const
  856. netRadioStateOffNotConnected = 0;
  857. netRadioStateOnNotConnected = Succ(netRadioStateOffNotConnected); // scanning
  858. netRadioStateOnConnected = Succ(netRadioStateOnNotConnected); // have channel
  859. netRadioStateOffConnected = Succ(netRadioStateOnConnected);
  860. (************************************************************
  861. * Net Library Macros
  862. *************************************************************)
  863. // Return current time in milliseconds.
  864. function NetNow: UInt32;
  865. // File Descriptor macros used for the NetLibSelect() call
  866. type
  867. NetFDSetType = UInt32;
  868. NetFDSetPtr = ^NetFDSetType;
  869. const
  870. netFDSetSize = 32;
  871. procedure netFDSet(n: UInt8; var p: NetFDSetType);
  872. procedure nnetFDClr(n: UInt8; var p: NetFDSetType);
  873. function nnetFDIsSet(n: UInt8; var p: NetFDSetType): Boolean;
  874. procedure nnetFDZero(var p: NetFDSetType);
  875. //-----------------------------------------------------------------------------
  876. // Net error codes
  877. //-----------------------------------------------------------------------------
  878. const
  879. netErrAlreadyOpen = netErrorClass or 1;
  880. netErrNotOpen = netErrorClass or 2;
  881. netErrStillOpen = netErrorClass or 3;
  882. netErrParamErr = netErrorClass or 4;
  883. netErrNoMoreSockets = netErrorClass or 5;
  884. netErrOutOfResources = netErrorClass or 6;
  885. netErrOutOfMemory = netErrorClass or 7; // Might be because free heap space is <32K probably because handheld's RAM <2MB
  886. netErrSocketNotOpen = netErrorClass or 8;
  887. netErrSocketBusy = netErrorClass or 9; //EINPROGRESS
  888. netErrMessageTooBig = netErrorClass or 10;
  889. netErrSocketNotConnected = netErrorClass or 11;
  890. netErrNoInterfaces = netErrorClass or 12; //ENETUNREACH
  891. netErrBufTooSmall = netErrorClass or 13;
  892. netErrUnimplemented = netErrorClass or 14;
  893. netErrPortInUse = netErrorClass or 15; //EADDRINUSE
  894. netErrQuietTimeNotElapsed = netErrorClass or 16; //EADDRINUSE
  895. netErrInternal = netErrorClass or 17;
  896. netErrTimeout = netErrorClass or 18; //ETIMEDOUT
  897. netErrSocketAlreadyConnected = netErrorClass or 19; //EISCONN
  898. netErrSocketClosedByRemote = netErrorClass or 20;
  899. netErrOutOfCmdBlocks = netErrorClass or 21;
  900. netErrWrongSocketType = netErrorClass or 22;
  901. netErrSocketNotListening = netErrorClass or 23;
  902. netErrUnknownSetting = netErrorClass or 24;
  903. netErrInvalidSettingSize = netErrorClass or 25;
  904. netErrPrefNotFound = netErrorClass or 26;
  905. netErrInvalidInterface = netErrorClass or 27;
  906. netErrInterfaceNotFound = netErrorClass or 28;
  907. netErrTooManyInterfaces = netErrorClass or 29;
  908. netErrBufWrongSize = netErrorClass or 30;
  909. netErrUserCancel = netErrorClass or 31;
  910. netErrBadScript = netErrorClass or 32;
  911. netErrNoSocket = netErrorClass or 33;
  912. netErrSocketRcvBufFull = netErrorClass or 34;
  913. netErrNoPendingConnect = netErrorClass or 35;
  914. netErrUnexpectedCmd = netErrorClass or 36;
  915. netErrNoTCB = netErrorClass or 37;
  916. netErrNilRemoteWindowSize = netErrorClass or 38;
  917. netErrNoTimerProc = netErrorClass or 39;
  918. netErrSocketInputShutdown = netErrorClass or 40; // EOF to sockets API
  919. netErrCmdBlockNotCheckedOut = netErrorClass or 41;
  920. netErrCmdNotDone = netErrorClass or 42;
  921. netErrUnknownProtocol = netErrorClass or 43;
  922. netErrUnknownService = netErrorClass or 44;
  923. netErrUnreachableDest = netErrorClass or 45;
  924. netErrReadOnlySetting = netErrorClass or 46;
  925. netErrWouldBlock = netErrorClass or 47; //EWOULDBLOCK
  926. netErrAlreadyInProgress = netErrorClass or 48; //EALREADY
  927. netErrPPPTimeout = netErrorClass or 49;
  928. netErrPPPBroughtDown = netErrorClass or 50;
  929. netErrAuthFailure = netErrorClass or 51;
  930. netErrPPPAddressRefused = netErrorClass or 52;
  931. // The following map into the Epilogue DNS errors declared in DNS.ep.h:
  932. // and MUST be kept in this order!!
  933. netErrDNSNameTooLong = netErrorClass or 53;
  934. netErrDNSBadName = netErrorClass or 54;
  935. netErrDNSBadArgs = netErrorClass or 55;
  936. netErrDNSLabelTooLong = netErrorClass or 56;
  937. netErrDNSAllocationFailure = netErrorClass or 57;
  938. netErrDNSTimeout = netErrorClass or 58;
  939. netErrDNSUnreachable = netErrorClass or 59;
  940. netErrDNSFormat = netErrorClass or 60;
  941. netErrDNSServerFailure = netErrorClass or 61;
  942. netErrDNSNonexistantName = netErrorClass or 62;
  943. netErrDNSNIY = netErrorClass or 63;
  944. netErrDNSRefused = netErrorClass or 64;
  945. netErrDNSImpossible = netErrorClass or 65;
  946. netErrDNSNoRRS = netErrorClass or 66;
  947. netErrDNSAborted = netErrorClass or 67;
  948. netErrDNSBadProtocol = netErrorClass or 68;
  949. netErrDNSTruncated = netErrorClass or 69;
  950. netErrDNSNoRecursion = netErrorClass or 70;
  951. netErrDNSIrrelevant = netErrorClass or 71;
  952. netErrDNSNotInLocalCache = netErrorClass or 72;
  953. netErrDNSNoPort = netErrorClass or 73;
  954. // The following map into the Epilogue IP errors declared in IP.ep.h:
  955. // and MUST be kept in this order!!
  956. netErrIPCantFragment = netErrorClass or 74;
  957. netErrIPNoRoute = netErrorClass or 75;
  958. netErrIPNoSrc = netErrorClass or 76;
  959. netErrIPNoDst = netErrorClass or 77;
  960. netErrIPktOverflow = netErrorClass or 78;
  961. // End of Epilogue IP errors
  962. netErrTooManyTCPConnections = netErrorClass or 79;
  963. netErrNoDNSServers = netErrorClass or 80;
  964. netErrInterfaceDown = netErrorClass or 81;
  965. // Mobitex network radio interface error code returns
  966. netErrNoChannel = netErrorClass or 82; // The datalink layer cannot acquire a channel
  967. netErrDieState = netErrorClass or 83; // Mobitex network has issued a DIE command.
  968. netErrReturnedInMail = netErrorClass or 84; // The addressed of the transmitted packet was not available, and the message was placed in the network's mailbox.
  969. netErrReturnedNoTransfer = netErrorClass or 85; // This message cannot be transferred or put in the network mailbox.
  970. netErrReturnedIllegal = netErrorClass or 86; // The message could not be switched to the network
  971. netErrReturnedCongest = netErrorClass or 87; // Line, radio channels, or network nodes are congested.
  972. netErrReturnedError = netErrorClass or 88; // Technical error in the network.
  973. netErrReturnedBusy = netErrorClass or 89; // The B-party is busy.
  974. netErrGMANState = netErrorClass or 90; // The modem has not registered with the network.
  975. netErrQuitOnTxFail = netErrorClass or 91; // Couldn't get packet through, shutdown.
  976. netErrFlexListFull = netErrorClass or 92; // raw IF error message: see Mobitex spec.
  977. netErrSenderMAN = netErrorClass or 93; // ditto
  978. netErrIllegalType = netErrorClass or 94; // ditto
  979. netErrIllegalState = netErrorClass or 95; // ditto
  980. netErrIllegalFlags = netErrorClass or 96; // ditto
  981. netErrIllegalSendlist = netErrorClass or 97; // ditto
  982. netErrIllegalMPAKLength = netErrorClass or 98; // ditto
  983. netErrIllegalAddressee = netErrorClass or 99; // ditto
  984. netErrIllegalPacketClass = netErrorClass or 100; // ditto
  985. netErrBufferLength = netErrorClass or 101; // any
  986. netErrNiCdLowBattery = netErrorClass or 102; // any
  987. netErrRFinterfaceFatal = netErrorClass or 103; // any
  988. netErrIllegalLogout = netErrorClass or 104; // raw IF error message
  989. netErrAAARadioLoad = netErrorClass or 105; // 7/20/98 JB. If there is insufficient AAA
  990. netErrAntennaDown = netErrorClass or 106;
  991. netErrNiCdCharging = netErrorClass or 107; // just for charging
  992. netErrAntennaWentDown = netErrorClass or 108;
  993. netErrNotActivated = netErrorClass or 109; // The unit has not been FULLY activated. George and Morty completed.
  994. netErrRadioTemp = netErrorClass or 110; // Radio's temp is too high for FCC compliant TX
  995. netErrNiCdChargeError = netErrorClass or 111; // Charging stopped due to NiCd charging characteristic
  996. netErrNiCdSag = netErrorClass or 112; // the computed sag or actual sag indicates a NiCd with diminished capacity.
  997. netErrNiCdChargeSuspend = netErrorClass or 113; // Charging has been suspended due to low AAA batteries.
  998. // Left room for more Mobitex errors
  999. // Configuration errors
  1000. netErrConfigNotFound = netErrorClass or 115;
  1001. netErrConfigCantDelete = netErrorClass or 116;
  1002. netErrConfigTooMany = netErrorClass or 117;
  1003. netErrConfigBadName = netErrorClass or 118;
  1004. netErrConfigNotAlias = netErrorClass or 119;
  1005. netErrConfigCantPointToAlias = netErrorClass or 120;
  1006. netErrConfigEmpty = netErrorClass or 121;
  1007. netErrAlreadyOpenWithOtherConfig = netErrorClass or 122;
  1008. netErrConfigAliasErr = netErrorClass or 123;
  1009. netErrNoMultiPktAddr = netErrorClass or 124;
  1010. netErrOutOfPackets = netErrorClass or 125;
  1011. netErrMultiPktAddrReset = netErrorClass or 126;
  1012. netErrStaleMultiPktAddr = netErrorClass or 127;
  1013. // Login scripting plugin errors
  1014. netErrScptPluginMissing = netErrorClass or 128;
  1015. netErrScptPluginLaunchFail = netErrorClass or 129;
  1016. netErrScptPluginCmdFail = netErrorClass or 130;
  1017. netErrScptPluginInvalidCmd = netErrorClass or 131;
  1018. // Telephony errors
  1019. netErrTelMissingComponent = netErrorClass or 132;
  1020. netErrTelErrorNotHandled = netErrorClass or 133;
  1021. netErrMobitexStart = netErrNoChannel;
  1022. netErrMobitexEnd = netErrNiCdChargeSuspend;
  1023. //-----------------------------------------------------------------------------
  1024. // Net library call ID's. Each library call gets the trap number:
  1025. // netTrapXXXX which serves as an index into the library's dispatch table.
  1026. // The constant sysLibTrapCustom is the first available trap number after
  1027. // the system predefined library traps Open,Close,Sleep & Wake.
  1028. //
  1029. // WARNING!!! This order of these traps MUST match the order of the dispatch
  1030. // table in NetDispatch.c!!!
  1031. //-----------------------------------------------------------------------------
  1032. type
  1033. NetLibTrapNumberEnum = Enum;
  1034. const
  1035. netLibTrapAddrINToA = sysLibTrapCustom;
  1036. netLibTrapAddrAToIN = Succ(netLibTrapAddrINToA);
  1037. netLibTrapSocketOpen = Succ(netLibTrapAddrAToIN);
  1038. netLibTrapSocketClose = Succ(netLibTrapSocketOpen);
  1039. netLibTrapSocketOptionSet = Succ(netLibTrapSocketClose);
  1040. netLibTrapSocketOptionGet = Succ(netLibTrapSocketOptionSet);
  1041. netLibTrapSocketBind = Succ(netLibTrapSocketOptionGet);
  1042. netLibTrapSocketConnect = Succ(netLibTrapSocketBind);
  1043. netLibTrapSocketListen = Succ(netLibTrapSocketConnect);
  1044. netLibTrapSocketAccept = Succ(netLibTrapSocketListen);
  1045. netLibTrapSocketShutdown = Succ(netLibTrapSocketAccept);
  1046. netLibTrapSendPB = Succ(netLibTrapSocketShutdown);
  1047. netLibTrapSend = Succ(netLibTrapSendPB);
  1048. netLibTrapReceivePB = Succ(netLibTrapSend);
  1049. netLibTrapReceive = Succ(netLibTrapReceivePB);
  1050. netLibTrapDmReceive = Succ(netLibTrapReceive);
  1051. netLibTrapSelect = Succ(netLibTrapDmReceive);
  1052. netLibTrapPrefsGet = Succ(netLibTrapSelect);
  1053. netLibTrapPrefsSet = Succ(netLibTrapPrefsGet);
  1054. // The following traps are for internal and Network interface
  1055. // use only.
  1056. netLibTrapDrvrWake = Succ(netLibTrapPrefsSet);
  1057. netLibTrapInterfacePtr = Succ(netLibTrapDrvrWake);
  1058. netLibTrapMaster = Succ(netLibTrapInterfacePtr);
  1059. // New Traps
  1060. netLibTrapGetHostByName = Succ(netLibTrapMaster);
  1061. netLibTrapSettingGet = Succ(netLibTrapGetHostByName);
  1062. netLibTrapSettingSet = Succ(netLibTrapSettingGet);
  1063. netLibTrapIFAttach = Succ(netLibTrapSettingSet);
  1064. netLibTrapIFDetach = Succ(netLibTrapIFAttach);
  1065. netLibTrapIFGet = Succ(netLibTrapIFDetach);
  1066. netLibTrapIFSettingGet = Succ(netLibTrapIFGet);
  1067. netLibTrapIFSettingSet = Succ(netLibTrapIFSettingGet);
  1068. netLibTrapIFUp = Succ(netLibTrapIFSettingSet);
  1069. netLibTrapIFDown = Succ(netLibTrapIFUp);
  1070. netLibTrapIFMediaUp = Succ(netLibTrapIFDown);
  1071. netLibTrapScriptExecuteV32 = Succ(netLibTrapIFMediaUp);
  1072. netLibTrapGetHostByAddr = Succ(netLibTrapScriptExecuteV32);
  1073. netLibTrapGetServByName = Succ(netLibTrapGetHostByAddr);
  1074. netLibTrapSocketAddr = Succ(netLibTrapGetServByName);
  1075. netLibTrapFinishCloseWait = Succ(netLibTrapSocketAddr);
  1076. netLibTrapGetMailExchangeByName = Succ(netLibTrapFinishCloseWait);
  1077. netLibTrapPrefsAppend = Succ(netLibTrapGetMailExchangeByName);
  1078. netLibTrapIFMediaDown = Succ(netLibTrapPrefsAppend);
  1079. netLibTrapOpenCount = Succ(netLibTrapIFMediaDown);
  1080. netLibTrapTracePrintF = Succ(netLibTrapOpenCount);
  1081. netLibTrapTracePutS = Succ(netLibTrapTracePrintF);
  1082. netLibTrapOpenIfCloseWait = Succ(netLibTrapTracePutS);
  1083. netLibTrapHandlePowerOff = Succ(netLibTrapOpenIfCloseWait);
  1084. netLibTrapConnectionRefresh = Succ(netLibTrapHandlePowerOff);
  1085. // Traps added after 1.0 release of NetLib
  1086. netLibTrapBitMove = Succ(netLibTrapConnectionRefresh);
  1087. netLibTrapBitPutFixed = Succ(netLibTrapBitMove);
  1088. netLibTrapBitGetFixed = Succ(netLibTrapBitPutFixed);
  1089. netLibTrapBitPutUIntV = Succ(netLibTrapBitGetFixed);
  1090. netLibTrapBitGetUIntV = Succ(netLibTrapBitPutUIntV);
  1091. netLibTrapBitPutIntV = Succ(netLibTrapBitGetUIntV);
  1092. netLibTrapBitGetIntV = Succ(netLibTrapBitPutIntV);
  1093. // Traps added after 2.0 release of NetLib
  1094. netLibOpenConfig_ = Succ(netLibTrapBitGetIntV);
  1095. netLibConfigMakeActive_ = Succ(netLibOpenConfig_);
  1096. netLibConfigList_ = Succ(netLibConfigMakeActive_);
  1097. netLibConfigIndexFromName_ = Succ(netLibConfigList_);
  1098. netLibConfigDelete_ = Succ(netLibConfigIndexFromName_);
  1099. netLibConfigSaveAs_ = Succ(netLibConfigDelete_);
  1100. netLibConfigRename_ = Succ(netLibConfigSaveAs_);
  1101. netLibConfigAliasSet_ = Succ(netLibConfigRename_);
  1102. netLibConfigAliasGet_ = Succ(netLibConfigAliasSet_);
  1103. // Traps added after 3.2 release of NetLib
  1104. netLibTrapScriptExecute = Succ(netLibConfigAliasGet_);
  1105. netLibTrapLast = Succ(netLibTrapScriptExecute);
  1106. (************************************************************
  1107. * Net Library procedures.
  1108. *************************************************************)
  1109. //--------------------------------------------------
  1110. // Library initialization, shutdown, sleep and wake
  1111. //--------------------------------------------------
  1112. function NetLibOpen(libRefnum: UInt16; var netIFErrsP: UInt16): Err; syscall sysLibTrapOpen;
  1113. function NetLibClose(libRefnum: UInt16; immediate: UInt16): Err; syscall sysLibTrapClose;
  1114. function NetLibSleep(libRefnum: UInt16): Err; syscall sysLibTrapSleep;
  1115. function NetLibWake(libRefnum: UInt16): Err; syscall sysLibTrapWake;
  1116. // This call forces the library to complete a close if it's
  1117. // currently in the close-wait state. Returns 0 if library is closed,
  1118. // Returns netErrFullyOpen if library is still open by some other task.
  1119. function NetLibFinishCloseWait(libRefnum: UInt16): Err; syscall netLibTrapFinishCloseWait;
  1120. // This call is for use by the Network preference panel only. It
  1121. // causes the NetLib to fully open if it's currently in the close-wait
  1122. // state. If it's not in the close wait state, it returns an error code
  1123. function NetLibOpenIfCloseWait(libRefnum: UInt16): Err; syscall netLibTrapOpenIfCloseWait;
  1124. // Get the open Count of the NetLib
  1125. function NetLibOpenCount(refNum: UInt16; var countP: UInt16): Err; syscall netLibTrapOpenCount;
  1126. // Give NetLib a chance to close the connection down in response
  1127. // to a power off event. Returns non-zero if power should not be
  1128. // turned off. EventP points to the event that initiated the power off
  1129. // which is either a keyDownEvent of the hardPowerChr or the autoOffChr.
  1130. // Don't include unless building for Viewer
  1131. function NetLibHandlePowerOff(refNum: UInt16; var eventP: SysEventType): Err; syscall netLibTrapHandlePowerOff;
  1132. // Check status or try and reconnect any interfaces which have come down.
  1133. // This call can be made by applications when they suspect that an interface
  1134. // has come down (like PPP or SLIP). NOTE: This call can display UI
  1135. // (if 'refresh' is true) so it MUST be called from the UI task.
  1136. function NetLibConnectionRefresh(refNum: UInt16; refresh: Boolean;
  1137. var allInterfacesUpP: UInt8; var netIFErrP: UInt16): Err; syscall netLibTrapConnectionRefresh;
  1138. //--------------------------------------------------
  1139. // Net address translation and conversion routines.
  1140. //--------------------------------------------------
  1141. // (The NetHToNS, NetHToNL, NetNToHS, and NetNToHL macros which used to be
  1142. // defined here are now defined in NetBitUtils.h. They can still be used
  1143. // by #including <NetMgr.h> (this file), because <NetBitUtils.h> is
  1144. // unconditionally included below.)
  1145. // convert host Int16 to network Int16
  1146. function NetHToNS(x: Int16): Int16;
  1147. // convert host long to network long
  1148. function NetHToNL(x: Int32): Int32;
  1149. // convert network Int16 to host Int16
  1150. function NetNToHS(x: Int16): Int16;
  1151. // convert network long to host long
  1152. function NetNToHL(x: Int32): Int32;
  1153. // Convert 32-bit IP address to ascii dotted decimal form. The Sockets glue
  1154. // macro inet_ntoa will pass the address of an application global string in
  1155. // spaceP.
  1156. function NetLibAddrINToA(libRefnum: UInt16; inet: NetIPAddr; spaceP: PChar): PChar; syscall netLibTrapAddrINToA;
  1157. // Convert a dotted decimal ascii string format of an IP address into
  1158. // a 32-bit value.
  1159. function NetLibAddrAToIN(libRefnum: UInt16; const a: PChar): NetIPAddr; syscall netLibTrapAddrAToIN;
  1160. //--------------------------------------------------
  1161. // Socket creation and option setting
  1162. //--------------------------------------------------
  1163. // Create a socket and return a refnum to it. Protocol is normally 0.
  1164. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1165. function NetLibSocketOpen(libRefnum: UInt16; domain: NetSocketAddrEnum;
  1166. type_: NetSocketTypeEnum; protocol: Int16; timeout: Int32;
  1167. var errP: Err): NetSocketRef; syscall netLibTrapSocketOpen;
  1168. // Close a socket.
  1169. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1170. function NetLibSocketClose(libRefnum: UInt16; socket: NetSocketRef; timeout: Int32;
  1171. var errP: Err): Int16; syscall netLibTrapSocketClose;
  1172. // Set a socket option. Level is usually netSocketOptLevelSocket. Option is one of
  1173. // netSocketOptXXXXX. OptValueP is a pointer to the new value and optValueLen is
  1174. // the length of the option value.
  1175. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1176. function NetLibSocketOptionSet(libRefnum: UInt16; socket: NetSocketRef;
  1177. level: UInt16 {NetSocketOptLevelEnum}; option: UInt16 {NetSocketOptEnum};
  1178. optValueP: Pointer; optValueLen: UInt16;
  1179. timeout: Int32; var errP: Err): Int16; syscall netLibTrapSocketOptionSet;
  1180. // Get a socket option.
  1181. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1182. function NetLibSocketOptionGet(libRefnum: UInt16; socket: NetSocketRef;
  1183. level: UInt16 {NetSocketOptLevelEnum}; option: UInt16 {NetSocketOptEnum};
  1184. optValueP: Pointer; var optValueLenP: UInt16;
  1185. timeout: Int32; var errP: Err): Int16; syscall netLibTrapSocketOptionGet;
  1186. //--------------------------------------------------
  1187. // Socket Control
  1188. //--------------------------------------------------
  1189. // Bind a source address and port number to a socket. This makes the
  1190. // socket accept incoming packets destined for the given socket address.
  1191. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1192. function NetLibSocketBind(libRefnum: UInt16; socket: NetSocketRef;
  1193. sockAddrP: NetSocketAddrPtr; addrLen: Int16; timeout: Int32;
  1194. var errP: Err): Int16; syscall netLibTrapSocketBind;
  1195. // Connect to a remote socket. For a stream based socket (i.e. TCP), this initiates
  1196. // a 3-way handshake with the remote machine to establish a connection. For
  1197. // non-stream based socket, this merely specifies a destination address and port
  1198. // number for future outgoing packets from this socket.
  1199. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1200. function NetLibSocketConnect(libRefnum: UInt16; socket: NetSocketRef;
  1201. sockAddrP: NetSocketAddrPtr; addrLen: Int16; timeout: Int32;
  1202. var errP: Err): Int16; syscall netLibTrapSocketConnect;
  1203. // Makes a socket ready to accept incoming connection requests. The queueLen
  1204. // specifies the max number of pending connection requests that will be enqueued
  1205. // while the server is busy handling other requests.
  1206. // Only applies to stream based (i.e. TCP) sockets.
  1207. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1208. function NetLibSocketListen(libRefnum: UInt16; socket: NetSocketRef;
  1209. queueLen: UInt16; timeout: Int32; var errP: Err): Int16; syscall netLibTrapSocketListen;
  1210. // Blocks the current process waiting for an incoming connection request. The socket
  1211. // must have previously be put into listen mode through the NetLibSocketListen call.
  1212. // On return, *sockAddrP will have the remote machines address and port number.
  1213. // Only applies to stream based (i.e. TCP) sockets.
  1214. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1215. function NetLibSocketAccept(libRefnum: UInt16; socket: NetSocketRef;
  1216. sockAddrP: NetSocketAddrPtr; var addrLenP: Int16; timeout: Int32;
  1217. var errP: Err): Int16; syscall netLibTrapSocketAccept;
  1218. // Shutdown a connection in one or both directions.
  1219. // Only applies to stream based (i.e. TCP) sockets.
  1220. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1221. function NetLibSocketShutdown(libRefnum: UInt16; socket: NetSocketRef;
  1222. direction: Int16 {NetSocketDirEnum}; timeout: Int32; var errP: Err): Int16; syscall netLibTrapSocketShutdown;
  1223. // Gets the local and remote addresses of a socket. Useful for TCP sockets that
  1224. // get dynamically bound at connect time.
  1225. // Returns 0 on success, -1 on error. If error, *errP gets filled in with error code.
  1226. function NetLibSocketAddr(libRefnum: UInt16; socketRef: NetSocketRef;
  1227. locAddrP: NetSocketAddrPtr; var locAddrLenP: Int16;
  1228. remAddrP: NetSocketAddrPtr; var remAddrLenP: Int16;
  1229. timeout: Int32; var errP: Err): Int16; syscall netLibTrapSocketAddr;
  1230. //--------------------------------------------------
  1231. // Sending and Receiving
  1232. //--------------------------------------------------
  1233. // Send data through a socket. The data is specified through the NetIOParamType
  1234. // structure.
  1235. // Flags is one or more of netMsgFlagXXX.
  1236. // Returns # of bytes sent on success, or -1 on error. If error, *errP gets filled
  1237. // in with error code.
  1238. function NetLibSendPB(libRefNum: UInt16; socket: NetSocketRef;
  1239. pbP: NetIOParamPtr; flags: UInt16; timeout: Int32; var errP: Err): Int16; syscall netLibTrapSendPB;
  1240. // Send data through a socket. The data to send is passed in a single buffer,
  1241. // unlike NetLibSendPB. If toAddrP is not nil, the data will be sent to
  1242. // address *toAddrP.
  1243. // Flags is one or more of netMsgFlagXXX.
  1244. // Returns # of bytes sent on success, or -1 on error. If error, *errP gets filled
  1245. // in with error code.
  1246. function NetLibSend(libRefNum: UInt16; socket: NetSocketRef;
  1247. bufP: Pointer; bufLen, flags: UInt16;
  1248. toAddrP: Pointer; toLen: UInt16; timeout: Int32; var errP: Err): Int16; syscall netLibTrapSend;
  1249. // Receive data from a socket. The data is gatthered into buffers specified in the
  1250. // NetIOParamType structure.
  1251. // Flags is one or more of netMsgFlagXXX.
  1252. // Timeout is max # of ticks to wait, or -1 for infinite, or 0 for none.
  1253. // Returns # of bytes received, or -1 on error. If error, *errP gets filled in
  1254. // with error code.
  1255. function NetLibReceivePB(libRefNum: UInt16; socket: NetSocketRef;
  1256. pbP: NetIOParamPtr; flags: UInt16; timeout: Int32; var errP: Err): Int16; syscall netLibTrapReceivePB;
  1257. // Receive data from a socket. The data is read into a single buffer, unlike
  1258. // NetLibReceivePB. If fromAddrP is not nil, *fromLenP must be initialized to
  1259. // the size of the buffer that fromAddrP points to and on exit *fromAddrP will
  1260. // have the address of the sender in it.
  1261. // Flags is one or more of netMsgFlagXXX.
  1262. // Timeout is max # of ticks to wait, or -1 for infinite, or 0 for none.
  1263. // Returns # of bytes received, or -1 on error. If error, *errP gets filled in
  1264. // with error code.
  1265. function NetLibReceive(libRefNum: UInt16; socket: NetSocketRef;
  1266. bufP: Pointer; bufLen, flags: UInt16;
  1267. fromAddrP: Pointer; var fromLenP: UInt16; timeout: Int32; var errP: Err): Int16; syscall netLibTrapReceive;
  1268. // Receive data from a socket directly into a (write-protected) Data Manager
  1269. // record.
  1270. // If fromAddrP is not nil, *fromLenP must be initialized to
  1271. // the size of the buffer that fromAddrP points to and on exit *fromAddrP will
  1272. // have the address of the sender in it.
  1273. // Flags is one or more of netMsgFlagXXX.
  1274. // Timeout is max # of ticks to wait, or -1 for infinite, or 0 for none.
  1275. // Returns # of bytes received, or -1 on error. If error, *errP gets filled in
  1276. // with error code.
  1277. function NetLibDmReceive(libRefNum: UInt16; socket: NetSocketRef;
  1278. recordP: Pointer; recordOffset: UInt32; rcvLen, flags: UInt16;
  1279. fromAddrP: Pointer; var fromLenP: UInt16; timeout: Int32; var errP: Err): Int16; syscall netLibTrapDmReceive;
  1280. //--------------------------------------------------
  1281. // Name Lookups
  1282. //--------------------------------------------------
  1283. function NetLibGetHostByName(libRefNum: UInt16; const nameP: PChar; bufP: NetHostInfoBufPtr; timeout: Int32; var errP: Err): NetHostInfoPtr; syscall netLibTrapGetHostByName;
  1284. function NetLibGetHostByAddr(libRefNum: UInt16; var addrP: UInt8; len, type_: UInt16;
  1285. bufP: NetHostInfoBufPtr; timeout: Int32; var errP: Err): NetHostInfoPtr; syscall netLibTrapGetHostByAddr;
  1286. function NetLibGetServByName(libRefNum: UInt16; const servNameP: PChar;
  1287. const protoNameP: PChar; bufP: NetServInfoBufPtr;
  1288. timeout: Int32; var errP: Err): NetServInfoPtr; syscall netLibTrapGetServByName;
  1289. // Looks up a mail exchange name and returns a list of hostnames for it. Caller
  1290. // must pass space for list of return names (hostNames), space for
  1291. // list of priorities for those hosts (priorities) and max # of names to
  1292. // return (maxEntries).
  1293. // Returns # of entries found, or -1 on error. If error, *errP gets filled in
  1294. // with error code.
  1295. function NetLibGetMailExchangeByName(libRefNum: UInt16; mailNameP: PChar;
  1296. maxEntries: UInt16; hostNames: Pointer{Char hostNames[][netDNSMaxDomainName+1]};
  1297. priorities: Pointer{UInt16 priorities[]};
  1298. timeout: Int32; var errP: Err): Int16; syscall netLibTrapGetMailExchangeByName;
  1299. //--------------------------------------------------
  1300. // Interface setup
  1301. //--------------------------------------------------
  1302. function NetLibIFGet(libRefNum: UInt16; index: UInt16; var ifCreatorP: UInt32; var ifInstanceP: UInt16): Err; syscall netLibTrapIFGet;
  1303. function NetLibIFAttach(libRefNum: UInt16; ifCreator: UInt32; ifInstance: UInt16; timeout: Int32): Err; syscall netLibTrapIFAttach;
  1304. function NetLibIFDetach(libRefNum: UInt16; ifCreator: UInt32; ifInstance: UInt16; timeout: Int32): Err; syscall netLibTrapIFDetach;
  1305. function NetLibIFUp(libRefNum: UInt16; ifCreator: UInt32; ifInstance: UInt16): Err; syscall netLibTrapIFUp;
  1306. function NetLibIFDown(libRefNum: UInt16; ifCreator: UInt32; ifInstance: UInt16; timeout: Int32): Err; syscall netLibTrapIFDown;
  1307. //--------------------------------------------------
  1308. // Settings
  1309. //--------------------------------------------------
  1310. // General settings
  1311. function NetLibSettingGet(libRefNum: UInt16; setting: UInt16 {NetSettingEnum}; valueP: Pointer; var valueLenP: UInt16): Err; syscall netLibTrapSettingGet;
  1312. function NetLibSettingSet(libRefNum: UInt16; setting: UInt16 {NetSettingEnum}; valueP: Pointer; valueLen: UInt16): Err; syscall netLibTrapSettingSet;
  1313. // Network interface specific settings.
  1314. function NetLibIFSettingGet(libRefNum: UInt16; ifCreator: UInt32; ifInstance: UInt16;
  1315. setting: UInt16 {NetIFSettingEnum}; valueP: Pointer; var valueLenP: UInt16): Err; syscall netLibTrapIFSettingGet;
  1316. function NetLibIFSettingSet(libRefNum: UInt16; ifCreator: UInt32; ifInstance: UInt16;
  1317. setting: UInt16 {NetIFSettingEnum}; valueP: Pointer; valueLen: UInt16): Err; syscall netLibTrapIFSettingSet;
  1318. //--------------------------------------------------
  1319. // System level
  1320. //--------------------------------------------------
  1321. function NetLibSelect(libRefNum: UInt16; width: UInt16; readFDs, writeFDs, exceptFDs: NetFDSetPtr;
  1322. timeout: Int32; var errP: Err): Int16; syscall netLibTrapSelect;
  1323. //--------------------------------------------------
  1324. // Debugging support
  1325. //--------------------------------------------------
  1326. function NetLibMaster(libRefNum: UInt16; cmd: UInt16; pbP: NetMasterPBPtr;
  1327. timeout: Int32): Err; syscall netLibTrapMaster;
  1328. {!!!
  1329. function NetLibTracePrintF(libRefNum: UInt16; const formatStr: PChar; ...): Err; syscall netLibTrapTracePrintF;
  1330. !!!}
  1331. function NetLibTracePutS(libRefNum: UInt16; strP: PChar): Err; syscall netLibTrapTracePutS;
  1332. //--------------------------------------------------
  1333. // Configuration Calls
  1334. //--------------------------------------------------
  1335. function NetLibOpenConfig(refNum: UInt16; configIndex: UInt16; openFlags: UInt32;
  1336. var netIFErrP: UInt16): Err; syscall netLibOpenConfig_;
  1337. function NetLibConfigMakeActive(refNum: UInt16; configIndex: UInt16): Err; syscall netLibConfigMakeActive_;
  1338. function NetLibConfigList(refNum: UInt16; nameArray: Pointer {NetConfigNameType nameArray[]};
  1339. var arrayEntriesP: UInt16): Err; syscall netLibConfigList_;
  1340. function NetLibConfigIndexFromName(refNum: UInt16; nameP: NetConfigNamePtr;
  1341. var indexP: UInt16): Err; syscall netLibConfigIndexFromName_;
  1342. function NetLibConfigDelete(refNum: UInt16; index: UInt16): Err; syscall netLibConfigDelete_;
  1343. function NetLibConfigSaveAs(refNum: UInt16; nameP: NetConfigNamePtr): Err; syscall netLibConfigSaveAs_;
  1344. function NetLibConfigRename(refNum: UInt16; index: UInt16; newNameP: NetConfigNamePtr): Err; syscall netLibConfigRename_;
  1345. function NetLibConfigAliasSet(refNum: UInt16; configIndex, aliasToIndex: UInt16): Err; syscall netLibConfigAliasSet_;
  1346. function NetLibConfigAliasGet(refNum: UInt16; aliasIndex: UInt16; var indexP: UInt16; var isAnotherAliasP: Boolean): Err; syscall netLibConfigAliasGet_;
  1347. implementation
  1348. uses SystemMgr, TimeMgr;
  1349. function NetNow: UInt32;
  1350. begin
  1351. NetNow := TimGetTicks * 1000 div sysTicksPerSecond;
  1352. end;
  1353. procedure netFDSet(n: UInt8; var p: NetFDSetType);
  1354. begin
  1355. p := p or (1 shl n);
  1356. end;
  1357. procedure nnetFDClr(n: UInt8; var p: NetFDSetType);
  1358. begin
  1359. p := p and not (1 shl n);
  1360. end;
  1361. function nnetFDIsSet(n: UInt8; var p: NetFDSetType): Boolean;
  1362. begin
  1363. nnetFDIsSet := (p and (1 shl n)) <> 0;
  1364. end;
  1365. procedure nnetFDZero(var p: NetFDSetType);
  1366. begin
  1367. p := 0;
  1368. end;
  1369. // convert host Int16 to network Int16
  1370. function NetHToNS(x: Int16): Int16;
  1371. begin
  1372. NetHToNS := x;
  1373. end;
  1374. // convert host long to network long
  1375. function NetHToNL(x: Int32): Int32;
  1376. begin
  1377. NetHToNL := x;
  1378. end;
  1379. // convert network Int16 to host Int16
  1380. function NetNToHS(x: Int16): Int16;
  1381. begin
  1382. NetNToHS := x;
  1383. end;
  1384. // convert network long to host long
  1385. function NetNToHL(x: Int32): Int32;
  1386. begin
  1387. NetNToHL := x;
  1388. end;
  1389. end.