| 1 | GETSERVENT(3) BSD Programmer's Manual GETSERVENT(3) |
| 2 | |
| 3 | N\bNA\bAM\bME\bE |
| 4 | g\bge\bet\bts\bse\ber\brv\bve\ben\bnt\bt, g\bge\bet\bts\bse\ber\brv\bvb\bby\byp\bpo\bor\brt\bt, g\bge\bet\bts\bse\ber\brv\bvb\bby\byn\bna\bam\bme\be, s\bse\bet\bts\bse\ber\brv\bve\ben\bnt\bt, e\ben\bnd\bds\bse\ber\brv\bve\ben\bnt\bt - get |
| 5 | service entry |
| 6 | |
| 7 | S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS |
| 8 | #\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<n\bne\bet\btd\bdb\bb.\b.h\bh>\b> |
| 9 | |
| 10 | _\bs_\bt_\br_\bu_\bc_\bt _\bs_\be_\br_\bv_\be_\bn_\bt _\b* |
| 11 | g\bge\bet\bts\bse\ber\brv\bve\ben\bnt\bt(); |
| 12 | |
| 13 | _\bs_\bt_\br_\bu_\bc_\bt _\bs_\be_\br_\bv_\be_\bn_\bt _\b* |
| 14 | g\bge\bet\bts\bse\ber\brv\bvb\bby\byn\bna\bam\bme\be(_\bc_\bh_\ba_\br _\b*_\bn_\ba_\bm_\be, _\bc_\bh_\ba_\br _\b*_\bp_\br_\bo_\bt_\bo); |
| 15 | |
| 16 | _\bs_\bt_\br_\bu_\bc_\bt _\bs_\be_\br_\bv_\be_\bn_\bt _\b* |
| 17 | g\bge\bet\bts\bse\ber\brv\bvb\bby\byp\bpo\bor\brt\bt(_\bi_\bn_\bt _\bp_\bo_\br_\bt, _\bp_\br_\bo_\bt_\bo); |
| 18 | |
| 19 | _\bv_\bo_\bi_\bd |
| 20 | s\bse\bet\bts\bse\ber\brv\bve\ben\bnt\bt(_\bi_\bn_\bt _\bs_\bt_\ba_\by_\bo_\bp_\be_\bn); |
| 21 | |
| 22 | _\bv_\bo_\bi_\bd |
| 23 | e\ben\bnd\bds\bse\ber\brv\bve\ben\bnt\bt(_\bv_\bo_\bi_\bd); |
| 24 | |
| 25 | D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN |
| 26 | The g\bge\bet\bts\bse\ber\brv\bve\ben\bnt\bt(), g\bge\bet\bts\bse\ber\brv\bvb\bby\byn\bna\bam\bme\be(), and g\bge\bet\bts\bse\ber\brv\bvb\bby\byp\bpo\bor\brt\bt() functions each re- |
| 27 | turn a pointer to an object with the following structure containing the |
| 28 | broken-out fields of a line in the network services data base, |
| 29 | _\b/_\be_\bt_\bc_\b/_\bs_\be_\br_\bv_\bi_\bc_\be_\bs. |
| 30 | |
| 31 | struct servent { |
| 32 | char *s_name; /* official name of service */ |
| 33 | char **s_aliases; /* alias list */ |
| 34 | int s_port; /* port service resides at */ |
| 35 | char *s_proto; /* protocol to use */ |
| 36 | }; |
| 37 | |
| 38 | The members of this structure are: |
| 39 | |
| 40 | _\bs_\b__\bn_\ba_\bm_\be The official name of the service. |
| 41 | |
| 42 | _\bs_\b__\ba_\bl_\bi_\ba_\bs_\be_\bs A zero terminated list of alternate names for the service. |
| 43 | |
| 44 | _\bs_\b__\bp_\bo_\br_\bt The port number at which the service resides. Port numbers |
| 45 | are returned in network byte order. |
| 46 | |
| 47 | _\bs_\b__\bp_\br_\bo_\bt_\bo The name of the protocol to use when contacting the service. |
| 48 | |
| 49 | The g\bge\bet\bts\bse\ber\brv\bve\ben\bnt\bt() function reads the next line of the file, opening the |
| 50 | file if necessary. |
| 51 | |
| 52 | The s\bse\bet\bts\bse\ber\brv\bve\ben\bnt\bt() function opens and rewinds the file. If the _\bs_\bt_\ba_\by_\bo_\bp_\be_\bn |
| 53 | flag is non-zero, the net data base will not be closed after each call to |
| 54 | g\bge\bet\bts\bse\ber\brv\bvb\bby\byn\bna\bam\bme\be() or g\bge\bet\bts\bse\ber\brv\bvb\bby\byp\bpo\bor\brt\bt(). |
| 55 | |
| 56 | The e\ben\bnd\bds\bse\ber\brv\bve\ben\bnt\bt() function closes the file. |
| 57 | |
| 58 | The g\bge\bet\bts\bse\ber\brv\bvb\bby\byn\bna\bam\bme\be() and g\bge\bet\bts\bse\ber\brv\bvb\bby\byp\bpo\bor\brt\bt() functions sequentially search |
| 59 | from the beginning of the file until a matching protocol name or port |
| 60 | number is found, or until EOF is encountered. If a protocol name is also |
| 61 | supplied (non- NULL), searches must also match the protocol. |
| 62 | |
| 63 | F\bFI\bIL\bLE\bES\bS |
| 64 | |
| 65 | |
| 66 | /etc/services |
| 67 | |
| 68 | D\bDI\bIA\bAG\bGN\bNO\bOS\bST\bTI\bIC\bCS\bS |
| 69 | Null pointer (0) returned on EOF or error. |
| 70 | |
| 71 | S\bSE\bEE\bE A\bAL\bLS\bSO\bO |
| 72 | getprotoent(3), services(5) |
| 73 | |
| 74 | H\bHI\bIS\bST\bTO\bOR\bRY\bY |
| 75 | The g\bge\bet\bts\bse\ber\brv\bve\ben\bnt\bt(), g\bge\bet\bts\bse\ber\brv\bvb\bby\byp\bpo\bor\brt\bt(), g\bge\bet\bts\bse\ber\brv\bvb\bby\byn\bna\bam\bme\be(), s\bse\bet\bts\bse\ber\brv\bve\ben\bnt\bt(), and |
| 76 | e\ben\bnd\bds\bse\ber\brv\bve\ben\bnt\bt() functions appeared in 4.2BSD. |
| 77 | |
| 78 | B\bBU\bUG\bGS\bS |
| 79 | These functions use static data storage; if the data is needed for future |
| 80 | use, it should be copied before any subsequent calls overwrite it. Ex- |
| 81 | pecting port numbers to fit in a 32 bit quantity is probably naive. |
| 82 | |
| 83 | 4.2 Berkeley Distribution June 4, 1993 2 |