United States-English |
|
|
HP-UX Reference > Ggetbootpent(3X)HP-UX 11i Version 3: February 2007 |
|
NAMEgetbootpent(), putbootpent(), setbootpent(), endbootpent(), parse_bp_htype(), parse_bp_haddr(), parse_bp_iaddr() — get or put bootptab entry SYNOPSIS#include <bootpent.h> int getbootpent (struct bootpent **bootpent); int setbootpent (const char *path); int endbootpent (void); int putbootpent ( struct bootpent *bootpent, int numfields, FILE * bootpfile ); int parse_bp_htype (const char *source); int parse_bp_haddr ( char **source, int htype, unsigned char *result, unsigned int *bytes ); int parse_bp_iaddr ( char **source, unsigned long *result );
DESCRIPTIONThese functions help a program read or modify a bootptab (bootpd control) file one entry at a time. getbootpent() locates an entry in the /etc/bootptab file, or an alternate file specified to setbootpent(), and returns a pointer to an array of objects of type struct bootpent that breaks the entry into separate data fields with preceding, or embedded, comment (text) lines. The bootpent structure is defined in <bootpent.h> and includes the following members: int bp_type; /* BP_DATA, BP_COMMENT, BP_BLANK */ char *bp_text; /* one field or one comment line */ The file also defines the following data type and constants: typedef struct bootpent *bpp_t; #define BP_NULLP ((bpp_t) 0) #define BP_SIZE (sizeof (struct bootpent)) #define MAXHADDRLEN 6 #define HTYPE_UNKNOWN 0 /* 0 bytes */ #define HTYPE_ETHERNET 1 /* 6 bytes */ #define HTYPE_EXP_ETHERNET 2 /* 1 byte */ #define HTYPE_AX25 3 /* 0 bytes */ #define HTYPE_PRONET 4 /* 1 byte */ #define HTYPE_CHAOS 5 /* 0 bytes */ #define HTYPE_IEEE802 6 /* 6 bytes */ #define HTYPE_ARCNET 7 /* 0 bytes */ #define MAXHTYPES 7 The fields are described in the Field Definitions section below. The purpose of each function is as follows.
Field DefinitionsIf bootpent.bp_type is BP_DATA, the associated text is one field from the current entry, either the name field or one of the tag fields. Null tag fields (two colons in a row) are ignored, not returned. If bootpent.bp_type is BP_COMMENT or BP_BLANK, the associated text is one comment line or blank line from the file, either preceding the current entry or embedded in it following a data line that was continued with a backslash. The text is exactly as it appears in the file, including any whitespace appearing on a blank line, and there is no trailing newline. The returned array elements are in the same order as data fields and comment lines appear in the file. 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 VALUEgetbootpent() 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). EXAMPLESThe 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; } } if (putbootpent (bp, fields, newfilep)) { (handle error) } } if (fields < 0) /* error reading file */ { (handle error) } if (endbootpent()) { (handle error) } if (fclose (newfilep)) { (handle error) } The following code fragment saves a copy of a bootptab entry returned by getbootpent(). #include <malloc.h> #include <string.h> #include <bootpent.h> bpp_t bpnew; unsigned size; size = fields *BP_SIZE; if ((bpnew = (bpp_t) malloc (size)) == BP_NULLP) { (handle error) } (void) memcpy ((void *)bpnew, (void *)bp, size);
|
Printable version | ||
|