Fix rmr_rpobe command line bug; add test coverage
[ric-plt/lib/rmr.git] / src / rmr / si / src / si95 / sigetadd.c
1 // vim: noet sw=4 ts=4:
2 /*
3 ==================================================================================
4     Copyright (c) 2020 Nokia
5     Copyright (c) 2020 AT&T Intellectual Property.
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18 ==================================================================================
19 */
20
21 /*
22 ******************************************************************************
23 *
24 *  Mnemonic: SIgetaddr
25 *  Abstract: This routine will get the address of the first listening
26 *            block on the tp list and return it in ASCII format to the
27 *            caller. The dest buffer is assumed to be at least 256 bytes
28 *                        long.
29 *  Parms:    gptr - Pointer to the global information block
30 *            buf  - Pointer to the buffer to hold the ascii string
31 *  Returns:  NI_OK if block found, NI_ERROR if no listen block exists
32 *  Date:     18 April 1995
33 *  Author:   E. Scott Daniels
34 *
35 ******************************************************************************
36 */
37 #include "sisetup.h"        //  get the standard include stuff
38
39 extern int SIgetaddr( struct ginfo_blk *gptr, char *buf ) {
40         struct tp_blk *tpptr;       //  Pointer into tp list
41         int status = SI_ERROR;       //  return status
42         char    *ibuf;          //  SIaddr now points us at a string, rather than filling ours
43
44         for( tpptr = gptr->tplist; tpptr != NULL && !(tpptr->flags & TPF_LISTENFD); tpptr = tpptr->next );
45
46         if( tpptr != NULL )
47         {
48                 SIaddress( tpptr->addr, (void *) &ibuf, AC_TODOT );   //  convert to dot fmt
49                 strncpy( buf, ibuf, 256 );                              //  copy into caller's buffer
50                 free( ibuf );
51                 status = SI_OK;                               //  ok status for return
52         }
53
54         return status;
55 }