1 // vim: noet sw=4 ts=4:
3 ==================================================================================
4 Copyright (c) 2020 Nokia
5 Copyright (c) 2020 AT&T Intellectual Property.
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
11 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
22 ******************************************************************************
24 * Mnemonic: SIlistener
25 * Abstract: Open a port on which connection requests (TCP) or datagrams (UDP)
26 * can be received. SIlistener will open the ipv4/6 port based on
27 * the address buffer passed in. The listener() obsoletes SIopen()
28 * with regard to opening udp ports.
29 * Allows the user to open multiple secondary listening ports
30 * Parms: type - TCP_DEVICE or UDP_DEVICE
31 * abuf - buffer containing either 0.0.0.0;port or ::1;port
33 * Returns: The file descriptor of the port, <0 if error
34 * Date: 26 March 1995 -- revised 13 Mar 2007 to support both ipv4 and 6
35 * Author: E. Scott Daniels
37 * Modified: 10 May 1995 - To change SOCK_RAW to SOCK_DGRAM
38 * 14 Mar 2007 - To enhance for ipv6
39 ******************************************************************************
42 #include "sitransport.h"
44 extern int SIlistener( struct ginfo_blk *gptr, int type, char *abuf ) {
45 struct tp_blk *tpptr; // pointer into tp list
46 int status = SI_ERROR; // status of processing
48 if( PARINOID_CHECKS ) {
52 if( gptr->magicnum != MAGICNUM ) // good cookie at the gptr address?
56 tpptr = SIlisten_prep( gptr, type, abuf, 0 );
58 if( tpptr != NULL ) // established a fd bound to the port ok
59 { // enable connection reqs
60 if( type == TCP_DEVICE )
62 if( (status = LISTEN( tpptr->fd, 1 )) < SI_OK )
65 tpptr->flags |= TPF_LISTENFD; // flag it so we can search it out if needed
68 tpptr->next = gptr->tplist; // add to the list
69 if( tpptr->next != NULL )
70 tpptr->next->prev = tpptr;
72 status = tpptr->fd; // return the fd of the listener