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 ***************************************************************************
25 * Abstract: Start a TCP/IP session with another process.
27 * addr - Pointer to a string containing the process' address
28 * The address is either ipv4 or ipv6 formmat with the
29 * port number separated with a semicolon (::1;4444,
30 * localhost;4444 climber;4444 129.168.0.4;4444).
31 * Returns: The session number if all goes well, SI_ERROR if not.
34 * Author: E. Scott Daniels
36 * Mod: 08 Mar 2007 - conversion of sorts to support ipv6
37 ******************************************************************************
40 #include "sitransport.h"
43 Accept a file descriptor and add it to the map.
45 extern void SImap_fd( struct ginfo_blk *gptr, int fd, struct tp_blk* tpptr ) {
47 gptr->tp_map[fd] = tpptr;
49 rmr_vlog( RMR_VL_WARN, "fd on connected session is out of range: %d\n", fd );
53 extern int SIconnect( struct ginfo_blk *gptr, char *abuf ) {
55 struct tp_blk *tpptr; // pointer to new block
56 struct sockaddr *taddr; // convenience pointer to addr of target
57 int alen = 0; // len of address struct
58 int fd = SI_ERROR; // file descriptor to return to caller
60 if( PARANOID_CHECKS ) {
65 if( gptr->magicnum != MAGICNUM ) { // no cookie -- no connection
70 tpptr = SIconn_prep( gptr, TCP_DEVICE, abuf, 0 ); // create tp struct, and socket. get peer address 0 == any family that suits the addr
74 if( connect( tpptr->fd, taddr, tpptr->palen ) != 0 ) {
75 close( tpptr->fd ); // clean up fd and tp_block
76 SItrash( TP_BLK, tpptr ); // free the trasnsport block
77 fd = SI_ERROR; // send bad session id num back
78 } else { // connect ok
79 tpptr->flags |= TPF_SESSION; // indicate we have a session here
80 tpptr->next = gptr->tplist; // add block to the list
81 if( tpptr->next != NULL ) {
82 tpptr->next->prev = tpptr; // if there - point back at new
85 gptr->tplist = tpptr; // point at new head
86 fd = tpptr->fd; // save for return value
87 SImap_fd( gptr, fd, tpptr );