17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*462be471Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include "uucp.h" 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef X_PROTOCOL 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #define XBUFSIZ 512 387c478bd9Sstevel@tonic-gate static jmp_buf Xfailbuf; 397c478bd9Sstevel@tonic-gate extern int xrdblk(); 407c478bd9Sstevel@tonic-gate extern unsigned msgtime; 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * x.25 protocol 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate /* ARGSUSED */ 467c478bd9Sstevel@tonic-gate static void 477c478bd9Sstevel@tonic-gate xalarm(sig) 487c478bd9Sstevel@tonic-gate int sig; 497c478bd9Sstevel@tonic-gate { 507c478bd9Sstevel@tonic-gate longjmp(Xfailbuf, 1); 517c478bd9Sstevel@tonic-gate } 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate static void (*xsig)(); 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * turn on protocol timer 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate int 597c478bd9Sstevel@tonic-gate xturnon() 607c478bd9Sstevel@tonic-gate { 617c478bd9Sstevel@tonic-gate xsig=signal(SIGALRM, xalarm); 627c478bd9Sstevel@tonic-gate return(0); 637c478bd9Sstevel@tonic-gate } 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate int 667c478bd9Sstevel@tonic-gate xturnoff() 677c478bd9Sstevel@tonic-gate { 687c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, xsig); 697c478bd9Sstevel@tonic-gate return(0); 707c478bd9Sstevel@tonic-gate } 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * write message across x.25 link 747c478bd9Sstevel@tonic-gate * type -> message type 757c478bd9Sstevel@tonic-gate * str -> message body (ascii string) 767c478bd9Sstevel@tonic-gate * fn -> x.25 file descriptor 777c478bd9Sstevel@tonic-gate * return 787c478bd9Sstevel@tonic-gate * 0 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate int 817c478bd9Sstevel@tonic-gate xwrmsg(type, str, fn) 82*462be471Sceastha char *str; 837c478bd9Sstevel@tonic-gate int fn; 847c478bd9Sstevel@tonic-gate char type; 857c478bd9Sstevel@tonic-gate { 86*462be471Sceastha char *s; 877c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ]; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate bufr[0] = type; 907c478bd9Sstevel@tonic-gate s = &bufr[1]; 917c478bd9Sstevel@tonic-gate while (*str) 927c478bd9Sstevel@tonic-gate *s++ = *str++; 937c478bd9Sstevel@tonic-gate *s = '\0'; 947c478bd9Sstevel@tonic-gate if (*(--s) == '\n') 957c478bd9Sstevel@tonic-gate *s = '\0'; 967c478bd9Sstevel@tonic-gate (void) (*Write)(fn, bufr, strlen(bufr) + 1); 977c478bd9Sstevel@tonic-gate return(0); 987c478bd9Sstevel@tonic-gate } 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* 1017c478bd9Sstevel@tonic-gate * read message from x.25 link 1027c478bd9Sstevel@tonic-gate * str -> message buffer 1037c478bd9Sstevel@tonic-gate * fn -> x.25 file descriptor 1047c478bd9Sstevel@tonic-gate * return 1057c478bd9Sstevel@tonic-gate * FAIL -> send timed out 1067c478bd9Sstevel@tonic-gate * 0 -> ok message in str 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate int 1097c478bd9Sstevel@tonic-gate xrdmsg(str, fn) 110*462be471Sceastha char *str; 1117c478bd9Sstevel@tonic-gate { 112*462be471Sceastha int len; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate if(setjmp(Xfailbuf)) 1157c478bd9Sstevel@tonic-gate return(FAIL); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate (void) alarm(msgtime); 1187c478bd9Sstevel@tonic-gate for (;;) { 1197c478bd9Sstevel@tonic-gate if( (len = (*Read)(fn, str, XBUFSIZ)) == 0) 1207c478bd9Sstevel@tonic-gate continue; 1217c478bd9Sstevel@tonic-gate if (len < 0) { 1227c478bd9Sstevel@tonic-gate (void) alarm(0); 1237c478bd9Sstevel@tonic-gate return(FAIL); 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate str += len; 1267c478bd9Sstevel@tonic-gate if (*(str - 1) == '\0') 1277c478bd9Sstevel@tonic-gate break; 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate (void) alarm(0); 1307c478bd9Sstevel@tonic-gate return(0); 1317c478bd9Sstevel@tonic-gate } 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * read data from file fp1 and write 1357c478bd9Sstevel@tonic-gate * on x.25 link 1367c478bd9Sstevel@tonic-gate * fp1 -> file descriptor 1377c478bd9Sstevel@tonic-gate * fn -> x.25 descriptor 1387c478bd9Sstevel@tonic-gate * returns: 1397c478bd9Sstevel@tonic-gate * FAIL ->failure in x.25 link 1407c478bd9Sstevel@tonic-gate * 0 -> ok 1417c478bd9Sstevel@tonic-gate */ 1427c478bd9Sstevel@tonic-gate int 1437c478bd9Sstevel@tonic-gate xwrdata(fp1, fn) 1447c478bd9Sstevel@tonic-gate FILE *fp1; 1457c478bd9Sstevel@tonic-gate { 146*462be471Sceastha int fd1; 147*462be471Sceastha int len, ret; 1487c478bd9Sstevel@tonic-gate unsigned long bytes; 1497c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ]; 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate bytes = 0L; 1527c478bd9Sstevel@tonic-gate fd1 = fileno( fp1 ); 1537c478bd9Sstevel@tonic-gate while ((len = read( fd1, bufr, XBUFSIZ )) > 0) { 1547c478bd9Sstevel@tonic-gate bytes += len; 1557c478bd9Sstevel@tonic-gate putfilesize(bytes); 1567c478bd9Sstevel@tonic-gate ret = (*Write)(fn, bufr, len); 1577c478bd9Sstevel@tonic-gate if (ret != len) { 1587c478bd9Sstevel@tonic-gate return(FAIL); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate if (len != XBUFSIZ) 1617c478bd9Sstevel@tonic-gate break; 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate ret = (*Write)(fn, bufr, 0); 1647c478bd9Sstevel@tonic-gate return(0); 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * read data from x.25 link and 1697c478bd9Sstevel@tonic-gate * write into file 1707c478bd9Sstevel@tonic-gate * fp2 -> file descriptor 1717c478bd9Sstevel@tonic-gate * fn -> x.25 descriptor 1727c478bd9Sstevel@tonic-gate * returns: 1737c478bd9Sstevel@tonic-gate * 0 -> ok 1747c478bd9Sstevel@tonic-gate * FAIL -> failure on x.25 link 1757c478bd9Sstevel@tonic-gate */ 1767c478bd9Sstevel@tonic-gate int 1777c478bd9Sstevel@tonic-gate xrddata(fn, fp2) 1787c478bd9Sstevel@tonic-gate FILE *fp2; 1797c478bd9Sstevel@tonic-gate { 180*462be471Sceastha int fd2; 181*462be471Sceastha int len; 182*462be471Sceastha int ret = SUCCESS; 1837c478bd9Sstevel@tonic-gate unsigned long bytes; 1847c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ]; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate bytes = 0L; 1877c478bd9Sstevel@tonic-gate fd2 = fileno( fp2 ); 1887c478bd9Sstevel@tonic-gate for (;;) { 1897c478bd9Sstevel@tonic-gate len = xrdblk(bufr, XBUFSIZ, fn); 1907c478bd9Sstevel@tonic-gate if (len < 0) { 1917c478bd9Sstevel@tonic-gate return(FAIL); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate bytes += len; 1947c478bd9Sstevel@tonic-gate putfilesize(bytes); 1957c478bd9Sstevel@tonic-gate if( ret == SUCCESS && write( fd2, bufr, len ) != len ) 1967c478bd9Sstevel@tonic-gate ret = errno; 1977c478bd9Sstevel@tonic-gate if (len < XBUFSIZ) 1987c478bd9Sstevel@tonic-gate break; 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate return(ret); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate /* 2047c478bd9Sstevel@tonic-gate * read blank from x.25 link 2057c478bd9Sstevel@tonic-gate * reads are timed 2067c478bd9Sstevel@tonic-gate * blk -> address of buffer 2077c478bd9Sstevel@tonic-gate * len -> size to read 2087c478bd9Sstevel@tonic-gate * fn -> x.25 descriptor 2097c478bd9Sstevel@tonic-gate * returns: 2107c478bd9Sstevel@tonic-gate * FAIL -> link error timeout on link 2117c478bd9Sstevel@tonic-gate * i -> # of bytes read 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate int 2147c478bd9Sstevel@tonic-gate xrdblk(blk, len, fn) 215*462be471Sceastha char *blk; 2167c478bd9Sstevel@tonic-gate { 217*462be471Sceastha int i, ret; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate if(setjmp(Xfailbuf)) 2207c478bd9Sstevel@tonic-gate return(FAIL); 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate (void) alarm(msgtime); 2237c478bd9Sstevel@tonic-gate for (i = 0; i < len; i += ret) { 2247c478bd9Sstevel@tonic-gate if ((ret = (*Read)(fn, blk, len - i)) < 0) { 2257c478bd9Sstevel@tonic-gate (void) alarm(0); 2267c478bd9Sstevel@tonic-gate return(FAIL); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate blk += ret; 2297c478bd9Sstevel@tonic-gate if (ret == 0) 2307c478bd9Sstevel@tonic-gate break; 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate (void) alarm(0); 2337c478bd9Sstevel@tonic-gate return(i); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate #endif /* X_PROTOCOL */ 236