GETNETENT(3) FreeBSD Library Functions Manual GETNETENT(3) NNAAMMEE ggeettnneetteenntt, ggeettnneettbbyyaaddddrr, ggeettnneettbbyynnaammee, sseettnneetteenntt, eennddnneetteenntt -- get net- works entry SSYYNNOOPPSSIISS ##iinncclluuddee <> _s_t_r_u_c_t _n_e_t_e_n_t _* ggeettnneetteenntt(); _s_t_r_u_c_t _n_e_t_e_n_t _* ggeettnneettbbyynnaammee(_c_h_a_r _n_a_m_e); _s_t_r_u_c_t _n_e_t_e_n_t _* ggeettnneettbbyyaaddddrr(_u_n_s_i_g_n_e_d _l_o_n_g _n_e_t, _i_n_t _t_y_p_e); _v_o_i_d sseettnneetteenntt(_i_n_t _s_t_a_y_o_p_e_n); _v_o_i_d eennddnneetteenntt(); DDEESSCCRRIIPPTTIIOONN The ggeettnneetteenntt(), ggeettnneettbbyynnaammee(), and ggeettnneettbbyyaaddddrr() subroutines each return a pointer to an object with the following structure containing the broken-out fields of a line in the _n_e_t_w_o_r_k_s database. struct netent { char *n_name; /* official name of net */ char **n_aliases; /* alias list */ int n_addrtype; /* net number type */ long n_net; /* net number */ }; The members of this structure are: n_name The official name of the network. n_aliases A zero-terminated list of alternate names for the network. n_addrtype The type of the network number returned: AF_INET. n_net The network number. Network numbers are returned in machine byte order. If the _s_t_a_y_o_p_e_n flag on a sseettnneetteenntt() subroutine is NULL, the _n_e_t_w_o_r_k_s database is opened. Otherwise, the sseettnneetteenntt() has the effect of rewind- ing the _n_e_t_w_o_r_k_s database. The eennddnneetteenntt() subroutine may be called to close the _n_e_t_w_o_r_k_s database when processing is complete. The ggeettnneetteenntt() subroutine simply reads the next line while ggeettnneettbbyynnaammee() and ggeettnneettbbyyaaddddrr() search until a matching _n_a_m_e or _n_e_t number is found (or until EOF is encountered). The _t_y_p_e _m_u_s_t _b_e AF_INET. The ggeettnneetteenntt() subroutine keeps a pointer in the database, allowing suc- cessive calls to be used to search the entire file. Before a wwhhiillee loop using ggeettnneetteenntt(), a call to sseettnneetteenntt() must be made in order to perform initialization; a call to eennddnneetteenntt() must be used after the loop. Both ggeettnneettbbyynnaammee() and ggeettnneettbbyyaaddddrr() make calls to sseettnneetteenntt() and eennddnneetteenntt(). FFIILLEESS _/_e_t_c_/_n_e_t_w_o_r_k_s DDIIAAGGNNOOSSTTIICCSS Null pointer (0) returned on EOF or error. SSEEEE AALLSSOO networks(5), RFC 1101. HHIISSTTOORRYY The ggeettnneetteenntt(), ggeettnneettbbyyaaddddrr(), ggeettnneettbbyynnaammee(), sseettnneetteenntt(), and eennddnneetteenntt() functions appeared in 4.2BSD. BBUUGGSS The data space used by these functions is static; if future use requires the data, it should be copied before any subsequent calls to these func- tions overwrite it. Only Internet network numbers are currently under- stood. Expecting network numbers to fit in no more than 32 bits is prob- ably naive. 4th Berkeley Distribution May 20, 1996 4th Berkeley Distribution