Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!emory!gatech!udel!haven.umd.edu!cs.wvu.wvnet.edu!cerc.wvu.wvnet.edu!cathedral!lcm From: lcm@cathedral.cerc.wvu.wvnet.edu (Local Concurrency Manager) Newsgroups: comp.protocols.iso Subject: Re: Transport Layer Interface (TLI) programming in UNIX SYS V Keywords: protocols TCP TLI transport Message-ID: <1920@babcock.cerc.wvu.wvnet.edu> Date: 26 Jun 91 20:19:12 GMT References: <1991Jun21.192632.14524@b17d.b17d.ingr.com> Sender: news@cerc.wvu.wvnet.edu Lines: 180 I can suggest Unix Network Programming by Richard Stevens, Prentice hall, 1990. It gives a number of of example programs also. I have included hurriedly gathered pieces of code I have written some time back. They may be useful to you. I tried to arrange the pieces so that they correspond roughly to server and client. In BSD socket library, when you say 'accept', another socket is automatically created by the system on which the connection is accepted. But in TLI, this is not so. You have to create another TEP, bind it and tell the system the connection is to be accepted on that TEP. That is the meaning of the function 'accept_call' on the server side. I haven't included the function but it is simple enough. Good Luck V.Narender Reddy vnr@cerc.wvu.wvnet.edu #include #include #include #include #ifdef SYSV #include #include #include #include #define DEV_TCP "/dev/tcp" #define T_LOOK 9 /* struct hostent application_host; */ #define FILL_TEP_ADDR(s,a,l,f,p) \ memcpy ((char *) &(s).sin_addr,(a),(l)); \ (s).sin_family = (f);\ (s).sin_port = htons((u_short)(p)); /*************************************************** Server side - tring to accept a connection ***************************************************/ fn_name(..............................) { int TEP_des ; int retries = RETRIES ; while (UN_SUCCESSFUL((TEP_des = t_open(DEV_TCP, O_RDWR, (struct t_info *) 0)))) exit(0); if (UN_SUCCESSFUL((t_bind(TEP_des, (struct t_bind *)0, (struct t_bind *)0))\ )) { strcpy (ERROR_MSG,"Trying to bind"); return (SYSTEM_CALL_ERROR); } if ((callptr = (struct t_call *) t_alloc(TEP_des, T_CALL, T_ADDR)) == NULL) { strcpy(ERROR_MSG,"In calling t_alloc"); return(SYSTEM_CALL_ERROR); } /* Filling the t_call structure in the required format */ callptr->addr.maxlen = sizeof(TEP_addr); callptr->addr.len = sizeof(TEP_addr); callptr->addr.buf = (char *) &TEP_addr; callptr->opt.len = 0; callptr->udata.len = 0; if ( POSITIVE(TLI_queue_len)) if( UN_SUCCESSFUL (t_listen (TEP, callptr))) { p close ( TEP ) ; strcpy (MODULE,"lcm_setup_TEP_to_read"); strcpy (ERROR_MSG,"listen"); return (-1); /* Hostname does not exist. */ /*PERR_RETURN_SYSERR("get_bound_TEP::listen");*/ } if (UN_SUCCESSFUL( (s = accept_call(TEP, callptr, DEV_TCP, 1)))){ if ( errno != EINTR ) { /* perror("setup_socket_to_read::accept"); exit(1);}*/ strcpy (MODULE,"lcm_setup_TEP_to_read"); strcpy (ERROR_MSG,"accept"); return (-1); } } /************************************************************ Client side - trying to connect pp*************************************************************/ fn_name(..................) { int TEP_des ; int retries = RETRIES ; while (UN_SUCCESSFUL((TEP_des = t_open(DEV_TCP, O_RDWR, (struct t_info *) 0)))) exit(0); if (UN_SUCCESSFUL((t_bind(TEP_des, (struct t_bind *)0, (struct t_bind *)0))\ )) { strcpy (ERROR_MSG,"Trying to bind"); return (SYSTEM_CALL_ERROR); } if ((callptr = (struct t_call *) t_alloc(TEP_des, T_CALL, T_ADDR)) == NULL) { strcpy(ERROR_MSG,"In calling t_alloc"); return(SYSTEM_CALL_ERROR); } /* Filling the t_call structure in the required format */ callptr->addr.maxlen = sizeof(TEP_addr); callptr->addr.len = sizeof(TEP_addr); callptr->addr.buf = (char *) &TEP_addr; callptr->opt.len = 0; callptr->udata.len = 0; while (UN_SUCCESSFUL( (t_connect(TEP_des, callptr, (struct t_call *) 0)))) { /* Nov 15, = to == */ if ( (retries--) && (errno == ETIMEDOUT )) { errno = 0 ; close (TEP_des) ; /* to reopen the socket */ if ( UN_SUCCESSFUL((TEP_des = lcm_open_TEP ()))) return (SYSTEM_CALL_ERROR); } else { close (TEP_des) ; /* close the socket we opened */ strcpy (ERROR_MSG,"Trying to connect"); /* let the caller handle the error */ return(SYSTEM_CALL_ERROR) ; } } /* connection established return the socket created */ return (TEP_des); }