HP-UX Reference (11i v2 07/12) - 3 Library Functions A-M (vol 6)
g
getbootpent(3X) getbootpent(3X)
Entry field strings are of the form:
tag [@ ][="value" ]
with surrounding whitespace, if any, removed (see bootpd(1M) for the full description). Double quotes, and
backslashes, can appear anywhere in the field strings.
Template entries (those referred to by other entries using
tc fields) are not special. They can be managed
like other entries. It is the calling program’s responsibility to correctly manage the order of fields,
tc
fields, and ‘‘@’’ fields that override earlier field values.
RETURN VALUE
getbootpent()
returns the number of valid array elements (one or more) upon successful completion.
At the end of the input file it returns zero. If it cannot open or close the file it returns -1. If it encounters a
memory allocation or map error, or a read error, it returns -2.
setbootpent()
returns zero if successful opening and reading the specified or default file. If it cannot
open or close the file it returns -1. If it encounters a memory allocation or map error or a read error it
returns -2.
endbootpent() returns zero if successful freeing the memory for the current open file. If there is no
current file it returns -1. If it cannot free the memory for the current file it returns -2.
putbootpent() returns zero if successful writing an entry to the specified file, with the
ferror()
indication clear (see ferror(3S)). Otherwise it returns non-zero with ferror() set.
In all cases above, if a failure is due to a failed system call, the errno value from the system is valid on
return from the called function.
parse_bp_htype() returns
HTYPE_UNKNOWN if the hardware type string is unrecognized.
parse_bp_haddr() returns zero if successful, otherwise non-zero in case of parsing error, invalid
htype, or a host address type for which the address length is unknown; source is modified to point to the
first illegal char (a NUL if the string is too short). The caller’s bytes value is unmodified, but result might
be changed.
parse_bp_iaddr() returns zero if successful, otherwise non-zero, and source is modified to point to the
first illegal char (a NUL if the string is null).
EXAMPLES
The following code fragment copies all data and comments from
/etc/bootptab
to a temporary copy of
the file. It converts data entries to canonical form as a side effect, and prints to standard output the first
field of each entry copied (should be the field name, assuming the entry doesn’t start with a continuation
line).
#include <bootpent.h>
FILE *newfilep; /* to write temp file */
bpp_t bp; /* read from file */
int field; /* current field number */
int fields; /* total in array for one entry */
if ((newfilep = fopen ("/tmp/bootptab", "w")) == (FILE *) NULL)
{
(handle error)
}
while ((fields = getbootpent (&bp)) > 0)
{
for (field = 0; field < fields; ++field)
{
if ((bp[field].bp_type) == BP_DATA)
{
(void) puts (bp[field].bp_text);
break;
}
}
472 Hewlett-Packard Company − 3 − HP-UX 11i Version 2: December 2007 Update