netmgr.pp 80 KB

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