IMPORTANT: Applications cannot directly use the net library to make wireless connections. Use the Internet library for wireless connections.
errno
. The net library API doesn't rely on any application global variables. This allows system code (which cannot have global variables) to use the net library API.
For... | The macros pass... |
---|---|
reference number | AppNetRefnum (application global variable). |
timeout |
AppNetTimeout (application global variable).
|
error code | Address of the application global errno. |
Int16 socket(Int16 domain, Int16 type, Int16 protocol);
NetLibSocketOpen
, which is declared as:
NetSocketRef NetLibSocketOpen(UInt16 libRefnum, NetSocketAddrEnum domain, NetSocketTypeEnum type, Int16 protocol, Int32 timeout, Err* errP)
socket
is:
#define socket(domain,type,protocol) \
NetLibSocketOpen(AppNetRefnum, domain, type, protocol, AppNetTimeout, &errno)
NetSample
in the Palm OS Examples
directory. It exercises many of the net library calls.
1. Obtain the net library's reference number.
Because the net library is a system library, all net library calls take the library's reference number as the first parameter. For this reason, your first step is to obtain the reference number and save it. See "Obtaining the Net Library's Reference Number."
2. Set up for using Berkeley sockets API.
You can either use the net library's native API or the Berkeley sockets API for the majority of what you do with the net library. If you're already familiar with Berkeley sockets API, you'll probably want to use it instead of the native API. If so, follow the steps in "Setting Up Berkeley Socket API."
3. If necessary, configure the net library the way you want it.
Typically, users set up their networking services by using the Network preferences panel. Most applications don't set up the networking services themselves; they simply access them through the net library preferences database. In rare instances, your application might need to perform some network configuration, and it usually should do so before the net library is open. See "Setup and Configuration Calls."
4. Open the net library right before the first network access.
5. Make calls to access the network.
6. Close the net library when you're finished with it.
Closing the net library frees up the resources. See "Closing the Net Library."
Net.lib
". In addition, if you intend to use Berkeley sockets API, save the reference number in the application global variable AppNetRefnum.
err = SysLibFind("Net.lib", &AppNetRefnum);
if (err) {/* error handling here */}
SysLibFind
call can't find the net library, it returns an error code.
NetSocket.c
, which declares and initializes three required global variables: AppNetTimeout, AppNetRefnum, and errno. NetLibSocket.c
also contains the glue code necessary for a few of the Berkeley sockets functions. AppNetRefnum
. AppNetTimeout
's value if necessary.     AppNetTimeout = SysTicksPerSecond() * 10;
SystemMgr.h
) that allow an application to present a list of possible service names to let the end user pick one. The preferences panel then makes the necessary net library setup and configuration calls to set up for that particular service.
NetLibIFAttach
attaches an interface to the library so that it will be used when and if the library is open.
NetLibIFDetach
detaches an interface from the library.
NetLibIFGet
returns an interface's creator and instance number. NetLibIFGet
to obtain this information. NetLibIFGet
takes four parameters: the net library's reference number, an index into the library's interface list, and addresses of two variables where the creator and instance number are returned.
If you know which interface you want to obtain information about, you can iterate through the network interface list, calling NetLibIFGet
with successive index values until the interface with the creator value you need is returned.
NetLibIFSettingGet
and
NetLibIFSettingSet
calls.
NetLibIFSettingGet
call takes a setting ID as a parameter along with a buffer pointer and buffer size for the return value of the setting. Some settings, like login script, are of variable size so the caller must be prepared to allocate a buffer large enough to retrieve the entire setting. (NetLibIFSettingGet
returns the required size if you pass NULL
for the buffer. See the NetLibIFSettingGet
description in the reference documentation for more information.)
NetLibIFSettingSet
call also takes a setting ID as a parameter along with a pointer to the new setting value and the size of the new setting. NetSample
example application in the Palm OS Examples
directory. The function CmdSettings
in the file CmdInfo.c
, for example, shows how to loop through and obtain information about all of the network interfaces.
netIFSettingLoginScript
setting is used to store the login script for an interface. The login script is generated either from the script that the user enters in the Network preferences panel or from a script file that is downloaded onto the device during a HotSync® operation. The format of the script is rigid; if a syntactically incorrect login script is presented to the net library, the results are unpredictable. The basic format is a series of null-terminated command lines followed by a null byte at the end of the script. Each command line has the format:
<command-byte> [<parameter>]
Function | Command | Parameter | Example |
---|---|---|---|
Send |
s
| string |
s go PPP
|
Wait for |
w
| string |
w password:
|
Delay |
d
| seconds |
d 1
|
Get IP |
g
|
g
| |
Prompt |
a
| string |
a Enter Name:
|
Wait for prompt |
f
| string |
f ID:
|
Send CR |
s
| string |
s ^N
|
Send UserID |
s
| string |
s jdoe
|
Send Password |
s
| string | s mypassword |
Plugin command1 |
sp
| string |
sp plugin: cmd: arg
|
1 |
s
) command can contain the escape sequences shown in Table 11.2.
Script.doc
in the Windows
folder. The Network preferences panel on Palm OS supports the following subset of commands:
set serviceName
set userName
set password
set phoneNumber
set primaryDNS
set secondaryDNS
set ipAddr
set closewait
set inactivityTimeout
set establishmentTimeout
set protocol
set dynamicIP
waitfor
transmit
getip
delay
prompt
waitforprompt
plugin "
pluginname:
cmd[:
arg]"
plugin
command is a Palm OS-specific extension used to perform a command defined in a plugin. See "Extending the Network Login Script Support" for more information on plugins.
.pnc
or .scp
and place it in the user's install directory. The network conduit will download it to the device during the next HotSync operation. Each script file should contain only one service definition.
NetLibSettingGet
and
NetLibSettingSet
calls. These calls take setting ID, buffer pointer, and buffer size parameters.
NetLibOpen
to open the net library, passing the reference number you retrieved through SysLibFind. Before the net library is opened, most calls issued to it fail with a netErrNotOpen error code.
err = NetLibOpen(AppNetRefnum, &ifErrs);
if (err || ifErrs) {/* error handling here */}
NetLibOpen
is called. If so, the function increments the library's open count, which keeps track of how many applications are accessing it, and returns immediately. (You can retrieve the open count with the function
NetLibOpenCount
.)
NetLibOpen
dials up the modem and establishes the connection before returning.
ifErrs
in the example above) contains the error number of the first interface that encountered a problem.
UInt16 index, ifInstance;
UInt32 ifCreator;
Err err;
UInt8 up;
Char ifName[32];
...
for (index = 0; 1; index++) {
    err = NetLibIFGet(AppNetRefnum, index,
    &ifCreator, &ifInstance);
    if (err) break;
    settingSize = sizeof(up);
    err = NetLibIFSettingGet(AppNetRefnum,
    ifCreator, ifInstance, netIFSettingUp, &up,
    &settingSize);
    if (err || up) continue;
    settingSize = 32;
    err = NetLibIFSettingGet(AppNetRefnum,
ifCreator, ifInstance, netIFSettingName,
ifName, &settingSize);
    if (err) continue;
    //display interface didn't come up message
}
NetLibClose(AppNetRefnum, true);
NetLibClose
.
err = NetLibClose(AppNetRefnum, false);
NetLibClose
simply decrements the open count. The false
parameter specifies that if the open count has reached 0, the net library should not immediately close. Instead, NetLibClose
schedules a timer to shut down the net library unless another
NetLibOpen
is issued before the timer expires. When the net library's open count is 0 but its timer hasn't yet expired, it's referred to as being in the close-wait state.
NetLibOpen
is called before the close timer expires, it simply cancels the timer and marks the library as fully open with an open count of 1 before returning. If the timer expires before another NetLibOpen is issued, all existing network connections are brought down, the net protocol stack task is terminated, and all memory allocated for internal use by the net library is freed.
UInt32* version;
err = FtrGet(netFtrCreator, netFtrNumVersion,
    &version);
0xMMmfsbbb
, where:
MM | major version |
m | minor version |
f | bug fix level |
s | stage: 3-release, 2-beta, 1-alpha, 0-development |
bbb | build number for non-releases |
NetSample
example application in the Palm OS Examples
directory shows how to use the Berkeley sockets API in Palm OS applications.
<unix/arpa_inet.h>
header file. They convert a network address from one format to another, or manipulate parts of a network address.
Network.prc
along with a PRC file for the network interface you use (i.e., PPP or SLIP). These files provide the new Network preferences panel, which contains support for some new commands and support for the ability to write script plugins.
'scpt'
as the database type instead of 'appl'
. (If you're using Metrowerks CodeWarrior, you specify the database type in the PalmRez post linker panel.)
PilotMain
function, the plugin should respond to two launch codes:
scptLaunchCmdListCmds
launch code when it is constructing the pull-down list of available commands that it displays in its script view. The panel sends this launch code to all PRCs of type 'scpt'
. It passes an empty structure of type
PluginInfoType
as its parameter block. Your plugin should respond by filling in the structure with the following information:
pluginMaxNumOfCmds
is allowed.
scptLaunchCmdExecuteCmd
launch code is sent when the login script is being executed. That is, the user has attempted to connect to the network service specified in the Network preferences panel, and the panel is executing the script to perform authentication.
scptLaunchCmdExecuteCmd
parameter block is a structure of type
PluginExecCmdType
. It contains:
ScriptPluginSelectorProc
. It takes as arguments the handle to the connection-specific data passed in with the launch code, the task that the network interface should perform (specified as a pluginNetLib
... constant), followed by a series of parameters whose interpretations depend on which task is to be performed.
#define pluginSecondCmd "Send Uname"
UInt32 PilotMain(UInt16 cmd, void *cmdPBP, UInt16 launchFlags) {
PluginExecCmdPtr execPtr;
UInt32 error = success;
Int16 dataSize = 0;
Char* dataBuffer = NULL;
ScriptPluginSelectorProcPtr selectorTypeP;
if (cmd == scptLaunchCmdExecuteCmd) {
    execPtr = (PluginExecCmdPtr)cmdPBP;
    selectorTypeP = execPtr->procP->selectorProcP;
    dataBuffer = MemPtrNew(pluginMaxLenTxtStringArg+1);
    if (!dataBuffer) {
    return failure;
    }
    MemSet(dataBuffer,pluginMaxLenTxtStringArg+1,0);
    if (!StrCompare(execPtr->commandName, pluginSecondCmd)) {
    /* get the user name from the network interface */
    error = (selectorTypeP)(execPtr->handle,
    pluginNetLibGetUserName, (void*)dataBufferP, &dataSize, 0,
    NULL);
    if (error) goto Exit;
    dataSize = StrLen((Char*)dataBufferP);
/* have the network interface send the user name to the host */
    error = (selectorTypeP)(execPtr->handle,
    pluginNetLibWriteBytes, (void*)dataBufferP, &dataSize, 0,
    NULL);
    return error;
    }
}
pluginNetLibCallUIProc
to display a form and call your own user interface routine. pluginNetLibCallUIProc
, you must do the following:
pluginNetLibCallUIProc
command, the structure with the form's handle and other pertinent information, and the address of a function in your plugin that will perform the user interface routine. This function should take one argument--the struct you've passed to the network interface--and return void
.
When the call to the network interface returns, close the form.
pluginNetLibCallUIProc
, see the functions WaitForData
and promptUser
in the example code ScriptPlugin.c
.
INetLibURLOpen
,
INetLibSockRead
, and
INetLibSockClose
). The Internet library also provides a more advanced API for those applications that need finer control.
NOTE:  The information in this section applies only to version 3.2 or later of the Palm OS on Palm VII devices. These features are implemented only if the Wireless Internet Feature Set is present.
WARNING!In future OS versions, Palm Computing does not intend to support or provide backward compatibility for the Internet library API.
FtrGet
call:
err = FtrGet(inetLibFtrCreator, inetFtrNumVersion, &value);
value
parameter will be non-zero and the returned error will be zero (for no error).
SysLibFind
to obtain a library reference number, as follows:
err = SysLibFind("INet.lib", &libRefNum)
INetLibOpen
to allocate an inetH
handle. The inetH
handle holds all application specific environment settings and each application that uses the Internet library gets its own private inetH
handle. Any calls that change the default behavior of the Internet library affect environment settings stored in the application's own inetH
structure, so these changes will not affect other applications that might be using the Internet library at the same time.
INetLibOpen
also opens the net library for the application. In addition, the application can tell INetLibOpen
the type of network service it prefers: wireline or wireless. INetLibOpen
queries the available network interfaces and attaches the appropriate one(s) for the desired type of service. When the application calls
INetLibClose
, the previous interface configuration is restored. For more information on configurations, see the section "Internet Library Network Configurations" .
INetLibSettingGet
and
INetLibSettingSet
calls. However, any changes made by an application are not stored into the system preferences, but only take effect while that inetH
handle is open.
INetLibURLOpen
routine, which creates a socket handle to access that web page. This routine returns immediately before performing any required network I/O. Then the application calls
INetLibSockRead
to read the data, followed by
INetLibSockClose
to close down the socket.
INetLibSockRead
blocks until at least one byte of data is available to be read. To implement asynchronous operation using events, see the next section, Asynchronous Operation.
INetLibURLOpen
with other lower-level Internet library calls (
INetLibSockOpen
,
INetLibSockSettingSet
, etc.) that are described in the section "Using the Low Level Calls" .
INetLibGetEvent
call. This call is designed to replace the EvtGetEvent
call that all traditional, non-network Palm applications use. The INetLibGetEvent
call fetches the next event that needs to be processed, whether that event is a user-interface event like a tap on the screen, or a network event like some data arriving from the remote host that needs to be read. If no events are ready, INetLibGetEvent
automatically puts the Palm device into low-power mode and blocks until the next event occurs.
INetLibGetEvent
is the preferred way of performing network I/O since it maximizes battery life and user-interface responsiveness.
INetLibGetEvent
, the process of accessing a web page becomes only slightly more complicated. Instead of calling INetLibSockRead
immediately after INetLibURLOpen
, the application should instead return to its event loop and wait for the next event. When it gets a network event that says data is ready at the socket, then it should call INetLibSockRead
.
INetLibGetEvent
can return in addition to the standard user-interface events. The first event is a status change event (
inetSockStatusChangeEvent
). This event indicates that the status of a socket has changed and the application may want to update its user interface. For example, when calling INetLibURLOpen
to access an HTTP server, the status on the socket goes from "finding host," to "connecting with host," to "waiting for data," to "reading data," etc. The event structure associated with an event of this type contains both the socket handle and the new status so that the application can update the user interface accordingly.
INetLibGetEvent
can return is a data-ready event (
inetSockReadyEvent
). This event is returned when data is ready at the socket for reading. This event tells the application that it can call INetLibSockRead
and be assured that it will not block while waiting for data to arrive.
INetLibURLOpen
, in response to a user command. Then it repeatedly calls INetLibGetEvent
to process events from both the user interface and the newly created socket returned by INetLibURLOpen
. In response to inetSockStatusChangeEvent
events, the application should update the user interface to show the user the current status, such as finding host, connecting to host, reading data, etc. In response to inetSockReadyEvent
events, the application should read data from the socket using INetLibSockRead
. Finally, when all available data has been read (INetLibSockRead
returns 0 bytes read), the application should close the socket using INetLibSockClose
.
INetLibSockStatus
is provided so that an application can query the status of a socket handle. This call never blocks on network I/O so it is safe to call at any time. It not only returns the current status of the socket but also whether or not it is ready for reading and/or writing. It essentially returns the same information as conveyed via the events inetSockReadyEvent
and inetSockStatusChangeEvent
. Applications that don't use INetLibGetEvent
could repeatedly poll INetLibSockStatus
to check for status changes and readiness for I/O, though polling is not recommended.
INetLibURLOpen
provides can use the lower level calls of the Internet library. These include
INetLibSockOpen
,
INetLibSockConnect
,
INetLibSockSettingSet
,
INetLibSockHTTPReqCreate
,
INetLibSockHTTPAttrGet
,
INetLibSockHTTPAttrSet
, and
INetLibSockHTTPReqSend
.
INetLibURLOpen
for an HTTP resource is essentially equivalent to this sequence: INetLibSockOpen
, INetLibSockConnect
, INetLibSockHTTPReqCreate
, and INetLibSockHTTPReqSend
. These four calls provide the capability for the application to access non-standard ports on the server (if allowed), to modify the default HTTP request headers, and to perform HTTP PUT and POST operations. The only calls here that actually perform network I/O are INetLibSockConnect
, which establishes a TCP connection with the remote host, and INetLibSockHTTPReqSend
, which sends the HTTP request to the server.
INetLibSockHTTPAttrSet
is provided so that the application can add or modify the default HTTP request headers that INetLibSockHTTPReqCreate
creates.
INetLibSockSettingSet
allows an application finer control over the socket settings.
INetLibURLCrack
is provided as a convenient utility for breaking a URL into its component parts.
inetOpenURLFlagKeepInCache
) set in the socket or by INetLibURLOpen
. Another flag (inetOpenURLFlagLookInCache
) determines if the Internet library should check the cache first when retrieving a URL.
INetLibOpen
call.
INetLibCacheList
. You can retrieve a cached document directly by using
INetLibCacheGetObject
.
INetLibURLGetInfo
.
INetSettingEnum
type).
INetLibConfigAliasSet
and can retrieve an alias by using
INetLibConfigAliasGet
.
INetLibOpen
. The Internet library also contains an API to allow you to manipulate configurations in your application, but doing so is rare. You can list the available configurations (
INetLibConfigList
), get a configuration index (
INetLibConfigIndexFromName
), select (
INetLibConfigMakeActive
) the Internet library network configuration you would prefer to use (wireless, wireline, etc.), rename existing configurations (
INetLibConfigRename
), and delete configurations (
INetLibConfigDelete
).
INetLibConfigSaveAs
. Note that configuration changes are not saved after the Internet library is closed, unless you call INetLibConfigSaveAs
.
Network Utilities | |
---|---|
NetUReadN |
NetUTCPOpen NetUWriteN |
Internet Library Functions | |
---|---|
Library Open and Close | |
INetLibClose | INetLibOpen |
Settings | |
INetLibSettingGet | INetLibSettingSet |
Event Management | |
INetLibGetEvent | |
High-Level Socket Calls | |
INetLibSockClose INetLibSockRead | INetLibURLOpen |
Low-Level Socket Calls | |
INetLibSockConnect INetLibSockOpen INetLibSockSettingGet |
INetLibSockSettingSet INetLibSockStatus |
HTTP Interface | |
INetLibSockHTTPAttrGet INetLibSockHTTPAttrSet |
INetLibSockHTTPReqCreate INetLibSockHTTPReqSend |
Utilities | |
INetLibCheckAntennaState INetLibURLCrack INetLibURLGetInfo |
INetLibURLsAdd INetLibWiCmd |
Cache Interface | |
INetLibCacheGetObject | INetLibCacheList |
Configuration | |
INetLibConfigAliasGet INetLibConfigAliasSet INetLibConfigDelete INetLibConfigIndexFromName |
INetLibConfigList INetLibConfigMakeActive INetLibConfigRename INetLibConfigSaveAs |
  |   |