1*5bbd2a12SchristosGETNETENT(3) FreeBSD Library Functions Manual GETNETENT(3) 2b5677b36Schristos 3b5677b36SchristosNNAAMMEE 4*5bbd2a12Schristos ggeettnneetteenntt, ggeettnneettbbyyaaddddrr, ggeettnneettbbyynnaammee, sseettnneetteenntt, eennddnneetteenntt -- get net- 5b5677b36Schristos works entry 6b5677b36Schristos 7b5677b36SchristosSSYYNNOOPPSSIISS 8b5677b36Schristos ##iinncclluuddee <<nneettddbb..hh>> 9b5677b36Schristos 10b5677b36Schristos _s_t_r_u_c_t _n_e_t_e_n_t _* 11b5677b36Schristos ggeettnneetteenntt(); 12b5677b36Schristos 13b5677b36Schristos _s_t_r_u_c_t _n_e_t_e_n_t _* 14b5677b36Schristos ggeettnneettbbyynnaammee(_c_h_a_r _n_a_m_e); 15b5677b36Schristos 16b5677b36Schristos _s_t_r_u_c_t _n_e_t_e_n_t _* 17b5677b36Schristos ggeettnneettbbyyaaddddrr(_u_n_s_i_g_n_e_d _l_o_n_g _n_e_t, _i_n_t _t_y_p_e); 18b5677b36Schristos 19b5677b36Schristos _v_o_i_d 20b5677b36Schristos sseettnneetteenntt(_i_n_t _s_t_a_y_o_p_e_n); 21b5677b36Schristos 22b5677b36Schristos _v_o_i_d 23b5677b36Schristos eennddnneetteenntt(); 24b5677b36Schristos 25b5677b36SchristosDDEESSCCRRIIPPTTIIOONN 26b5677b36Schristos The ggeettnneetteenntt(), ggeettnneettbbyynnaammee(), and ggeettnneettbbyyaaddddrr() subroutines each 27b5677b36Schristos return a pointer to an object with the following structure containing the 28b5677b36Schristos broken-out fields of a line in the _n_e_t_w_o_r_k_s database. 29b5677b36Schristos 30b5677b36Schristos struct netent { 31b5677b36Schristos char *n_name; /* official name of net */ 32b5677b36Schristos char **n_aliases; /* alias list */ 33b5677b36Schristos int n_addrtype; /* net number type */ 34b5677b36Schristos long n_net; /* net number */ 35b5677b36Schristos }; 36b5677b36Schristos 37b5677b36Schristos The members of this structure are: 38b5677b36Schristos 39b5677b36Schristos n_name The official name of the network. 40b5677b36Schristos 41b5677b36Schristos n_aliases A zero-terminated list of alternate names for the network. 42b5677b36Schristos 43b5677b36Schristos n_addrtype The type of the network number returned: AF_INET. 44b5677b36Schristos 45b5677b36Schristos n_net The network number. Network numbers are returned in machine 46b5677b36Schristos byte order. 47b5677b36Schristos 48b5677b36Schristos 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 49*5bbd2a12Schristos database is opened. Otherwise, the sseettnneetteenntt() has the effect of rewind- 50b5677b36Schristos ing the _n_e_t_w_o_r_k_s database. The eennddnneetteenntt() subroutine may be called to 51b5677b36Schristos close the _n_e_t_w_o_r_k_s database when processing is complete. 52b5677b36Schristos 53b5677b36Schristos The ggeettnneetteenntt() subroutine simply reads the next line while 54b5677b36Schristos ggeettnneettbbyynnaammee() and ggeettnneettbbyyaaddddrr() search until a matching _n_a_m_e or _n_e_t 55b5677b36Schristos number is found (or until EOF is encountered). The _t_y_p_e _m_u_s_t _b_e AF_INET. 56*5bbd2a12Schristos The ggeettnneetteenntt() subroutine keeps a pointer in the database, allowing suc- 57b5677b36Schristos cessive calls to be used to search the entire file. 58b5677b36Schristos 59b5677b36Schristos Before a wwhhiillee loop using ggeettnneetteenntt(), a call to sseettnneetteenntt() must be made 60b5677b36Schristos in order to perform initialization; a call to eennddnneetteenntt() must be used 61b5677b36Schristos after the loop. Both ggeettnneettbbyynnaammee() and ggeettnneettbbyyaaddddrr() make calls to 62b5677b36Schristos sseettnneetteenntt() and eennddnneetteenntt(). 63b5677b36Schristos 64b5677b36SchristosFFIILLEESS 65b5677b36Schristos _/_e_t_c_/_n_e_t_w_o_r_k_s 66b5677b36Schristos 67b5677b36SchristosDDIIAAGGNNOOSSTTIICCSS 68b5677b36Schristos Null pointer (0) returned on EOF or error. 69b5677b36Schristos 70b5677b36SchristosSSEEEE AALLSSOO 71b5677b36Schristos networks(5), RFC 1101. 72b5677b36Schristos 73b5677b36SchristosHHIISSTTOORRYY 74b5677b36Schristos The ggeettnneetteenntt(), ggeettnneettbbyyaaddddrr(), ggeettnneettbbyynnaammee(), sseettnneetteenntt(), and 75b5677b36Schristos eennddnneetteenntt() functions appeared in 4.2BSD. 76b5677b36Schristos 77b5677b36SchristosBBUUGGSS 78b5677b36Schristos The data space used by these functions is static; if future use requires 79*5bbd2a12Schristos the data, it should be copied before any subsequent calls to these func- 80*5bbd2a12Schristos tions overwrite it. Only Internet network numbers are currently under- 81*5bbd2a12Schristos stood. Expecting network numbers to fit in no more than 32 bits is prob- 82b5677b36Schristos ably naive. 83b5677b36Schristos 84b5677b36Schristos4th Berkeley Distribution May 20, 1996 4th Berkeley Distribution 85