makarand@b17d.b17d.ingr.com (Makarand Gokhale) (06/22/91)
Hi I recently read about Transport Layer Interface (TLI) available in UNIX System V. It is expected to offer medium as well as protocol independence. The UNIX System Transport Interface was modeled after the industry standard ISO Transport Service Definition (ISO 8072). After reading thru the Network Programmer's Guide I tried to write a simple client server program based on TLI. I was unsuccessful in running it. The UNIX System V Network Programmer's Guide explains TLI very well, but unfortunately does not provide enough information on how to write programs, what are the requirements, what information is necessary to write a network application. Could someone suggest some good reading material, or papers which give details on how to write programs using TLI functions that work. I would appreciate it if someone could send me a simple client server program that I can write and execute. Also answers to following questions will be very helpful. 1. What are the preparations necessary before I can use TLI. 2. Do I need special device files . 3. What are the address format for using these device files. 4. Are there any restrictions ? Does this TLI stuff really work? please post or E-mail me. Thanks in advance. Makarand Gokhale makarand@makarand.b17d.ingr.com "The views expressed herein are my own and do not in anyway represent company policies, procedures or anything" --
lcm@cathedral.cerc.wvu.wvnet.edu (Local Concurrency Manager) (06/27/91)
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 <ctype.h> #include <tiuser.h> #include <stropts.h> #include <poll.h> #ifdef SYSV #include <bsd/sys/types.h> #include <bsd/sys/socket.h> #include <bsd/netinet/in.h> #include <bsd/netdb.h> #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); }