aspp_unix/0040755000000000000000000000000007553547060011601 5ustar rootrootaspp_unix/readme.txt0100644000000000000000000001075707363553216013605 0ustar rootroot This directory includes the example program that shows you how to control Async Server's ports with 'ASPP' mode - Async Server Proprietory Protocol. To test the program, you should first set the Async Server testing port to 'ASPP' mode. Otherwise, the example program may not function as expected. Please check the Async Server User's Manual for configuration instructions. Be aware that you need to have TCP/IP development tools/libraries installed on the system you are using. The example program is developed under SCO v3.2.4. In your environment, the include files and network library names might be different. Tailor the as.mak or as.c files to suit your environment requirements. For example, SCO must link to a TCP/IP library called libnls.a whereas Solaris must link to libnsl.a, and Venix must link to libnsl_s.a. ================================= ASPP Library function description ================================= 1. sio_init() Initial data table using of ASPP functions. This function must be called once before calling any other sio_open, sio_close.., etc. Arg: none Return: == 0 : O.K. -1 : init fail. 2. sio_open(unsigned long server_ip, int port) open Async Server serial port. Args: unsigned long ipaddr - IP address of Async Server e.g. 0x0102A8C0 -> 192.168.2.1 int portno - serial port number of Async Server number range from 1 to 16. Return: >= 0 : file handle ID (open success). -1 : open fail. 3. sio_close(int fd) close Async Server serial port Arg: int fd - file handle ID return from sio_open() Return: 0 4. sio_ioctl(int fd, int baud, int mode) Set Async port baud rate and character mode. Args: int fd - file handle ID return from sio_open() int baud - 0: 300 1: 600 2: 1200 3: 2400 4: 4800 5: 7200 6: 9600 7: 19200 8: 38400 9: 57600 10: 115200 11: 230400 12: 460800 13: 921600 14: 150 15: 134 16: 110 17: 75 18: 50 int mode - (bit 0,1) 0x00 - 5 data bits 0x01 - 6 data bits 0x10 - 7 data bits 0x11 - 8 data bits (bit 2) 0x00 - 1 stop bit 0x04 - 1.5/2 stop bits (bit 3,4,5) 0x00 - none parity 0x08 - odd parity 0x18 - even parity 0x28 - mark parity 0x38 - space parity Return: 0 : O.K. -1 : error 5. sio_baud(int fd, long baud) Set Async Port baud rate. Args: int fd - file handle ID return from sio_open() long baud - desired baud rate Return: 0 : O.K. -1 : error 6. sio_flowctrl(int fd, int mode) Set Async Port flow control. Args: int fd - file handle ID return from sio_open() int mode - bit 0: CTS flow control bit 1: RTS flow control bit 2: Tx XON/XOFF flow control bit 3: Rx XON/XOFF flow control (0 = OFF, 1 = ON) Return: 0 : O.K. -1 : error 7. sio_lctrl(int fd, int mode) Set Async Port line control. Args: int fd - file handle ID return from sio_open() int mode - bit 0: DTR output state bit 1: RTS output state (0 = OFF, 1 = ON) Return: 0 : O.K. -1 : error 8. sio_lstatus(int fd) Get Async Port line status. Args: int fd - file handle ID return from sio_open() Return: >=0 : line status: bit 0: DSR, bit 1: CTS, bit 2: DCD (1 - ON, 0 - OFF) -1 : error 9. sio_flush(int fd, int func) Flush input/output buffer data. Args: int fd - file handle ID return from sio_open() int func - 0 : flush input buffer 1 : flush output buffer 2 : flush input/output buffer Return: >= 0 : O.K. -1 : error 10. sio_write(int fd, char *buf, int len) write data to Async Server serial port. Args: int fd - file handle ID return from sio_open() char * buf - write out data buffer pointer int len - write out data length Return: >= 0 : write out data length -1 : write error 11. sio_read(int fd, char *buf, int len) read data from Async Server serial port. Args: int fd - file handle ID return from sio_open() char * buf - read data buffer pointer int len - read data buffer length Return: >= 0 : read data length -1 : read error 12. sio_break(int fd, int time) Send out a break signal. Args: int fd - file handle ID return from sio_open() int time - break time in mini-second Return: 0 : O.K. -1 : error 13. sio_oqueue(int fd) Get output buffer data queue size. Args: int fd - file handle ID return from sio_open() Return: >= 0 : output buffer data queue size -1 : error 14. sio_iqueue(int fd) Get input buffer data queue size. Args: int fd - file handle ID return from sio_open() Return: >= 0 : input buffer data queue size -1 : erroraspp_unix/example.c000644 000000116260777046534600103210ustar /************************************************************************/ /* MOXA-CN2000 'ASPP' Port Control Program Example */ /* Program: */ /* example.c */ /* Purpose: */ /* This program will continueosly send '1234567890' */ /* string out from CN2000 RS-232 port, whose port Mode */ /* should be set as 'ASPP', and read back any */ /* incoming data until program interrupted. */ /* Setting: */ /* The target port will be configured as: */ /* no parity, */ /* 8 data bits, */ /* 1 stop bit, */ /* with software(XON/XOFF) flow control, */ /* but no hardware(RTS/CTS). */ /* 1st port and 9600bps is default, however you may change */ /* it in command line. */ /* The target port Mode should be set as 'ASPP' */ /* via [Configure] [OP_mode] from Async Server */ /* CONSOLE utility. */ /* Syntax: */ /* # ./aspp AsyncServerName [port(1) [Baud(9600)]] */ /* */ /* For example: */ /* # ./aspp cn2000 1 19200 */ /* The program will send '1234567890' to port 1 on Async */ /* Server at 19200 bps baud and read back any data on it. */ /* */ /* Environment: */ /* This program is originally developed under SCO UNIX. */ /* Your environment may be different, if so, the include file */ /* name and other variable may need to be modified to suit */ /* your environment. */ /************************************************************************/ #include #include #include #include #include #include #include #include "aspp.h" main(argc, argv) int argc; char * argv[]; { int fd, port, i, baud; unsigned long ipaddr; struct hostent * name; struct sockaddr_in des; unsigned char buf[100]; port = 1; /* target port = 1st port on cn2000 */ if ( argc == 1 ) { printf("\nNo Async Server name specified.\n"); printf("\nSyntax: # ./%s ServerName [port_no [Speed]]\n", argv[0]); printf("For example: # ./%s CN2000 1 9600\n\n", argv[0]); exit(0); } memset(&des, 0, sizeof(des)); printf("Hook up a terminal to the first port to test.\n"); name = gethostbyname(argv[1]); if ( !name ) { printf("\n%s must appear in '/etc/hosts'.\n",argv[1]); printf("Please add CN2000 IP addr and name into /etc/hosts.\n"); exit(0); } strncpy((char *)&des.sin_addr, name->h_addr, name->h_length); printf("CN2000 IP addr = 0x%X(%s) \n", des.sin_addr.s_addr, inet_ntoa(des.sin_addr.s_addr) ); if ( argc > 2 ) port = atoi(argv[2]); if ( argc > 3 ) { baud = atoi(argv[3]); switch( baud ){ case 300: baud = D_IOCTL_B300; break; case 600: baud = D_IOCTL_B600; break; case 1200: baud = D_IOCTL_B1200; break; case 2400: baud = D_IOCTL_B2400; break; case 4800: baud = D_IOCTL_B4800; break; case 9600: baud = D_IOCTL_B9600; break; case 19200: baud = D_IOCTL_B19200; break; case 38400: baud = D_IOCTL_B38400; break; case 57600: baud = D_IOCTL_B57600; break; case 115200: baud = D_IOCTL_B115200; break; case 230400: baud = D_IOCTL_B230400; break; case 460800: baud = D_IOCTL_B460800; break; default: printf("invalide baud rate %d \n", baud); exit(0); } printf("\nport %d : %s,n,8,1,no RTS/CTS flow control.\n\n", port, argv[3]); } else { baud = D_IOCTL_B9600; printf("\nport %d : 9600,n,8,1,no RTS/CTS flow control.\n\n", port); } printf("Press any key to continue...\n"); i = getchar(); sio_init(); if ( (fd = sio_open(des.sin_addr.s_addr, port)) < 0 ) { printf("\nPort %d open fail.\n", port); printf("\nRe-examine the port Mode from cn2000 CONSOLE.\n"); exit(0); } printf("Port %2d opened OK.\n", port); if ( sio_ioctl(fd,baud,D_IOCTL_BIT8+D_IOCTL_STOP1+D_IOCTL_NONE) < 0 ) { printf("Port ioctl error.\n"); sio_close(fd); exit(0); } printf("Port ioctl OK. \n"); if ( sio_flowctrl(fd, 0) < 0 ) { printf("Port flow control error.\n"); sio_close(fd); exit(0); } printf("Port flow control OK.\n"); if ( sio_flush(fd, 2) < 0 ) { printf("Port flush error.\n"); sio_close(fd); exit(0); } printf("Port flush OK.\n"); i = sio_lstatus(fd); if ( i < 0 ) { printf("Port lstatus error!\n"); sio_close(fd); exit(0); } printf("\n"); if ( i & 1 ) printf("DSR ON "); if ( i & 2 ) printf("CTS ON "); if ( i & 4 ) printf("DCD ON "); if ( (i & 7) == 0 ) printf("LINE OFF "); printf("\n"); if (sio_break(fd, 1000) < 0) { printf("send a break message failed.\n"); } else { printf("send a break message OK.\n"); } if ( sio_write(fd, "1234567890", 10) != 10 ) { printf("write data [1234567890] fail!\n"); sio_close(fd); exit(0); } printf("Waiting data [1234567890] from port %d .....\n", port); i = sio_read(fd, buf, 100); if ( i > 0 ) { buf[i] = 0; printf("Read: [%s]\n", buf); } else printf("read return %d !!!\n", i); sio_close(fd); } aspp_unix/linux.mak0100644000000000000000000000005707363553226013431 0ustar rootrootexample: example.o cc -O -o example example.c aspp_unix/rs6000.mak0100644000000000000000000000013207363553210013207 0ustar rootrootexample: example.o cc example.o -o example example.o: example.c cc -c example.c aspp_unix/sco_unix.mak0100644000000000000000000000016107363550220014104 0ustar rootrootexample: example.o cc example.o -lsocket -lnls -o example example.o: example.c cc -c -I/usr/include example.c aspp_unix/sola_x86.mak0100644000000000000000000000016107363550134013724 0ustar rootrootexample: example.o cc example.o -lsocket -lnsl -o example example.o: example.c cc -c -I/usr/include example.c aspp_unix/sun.mak0100644000000000000000000000012307363550230013061 0ustar rootrootexample: example.o cc example.o -o example example.o: example.c cc -c example.c aspp_unix/venix.mak0100644000000000000000000000017407363550164013421 0ustar rootrootexample: example.o cc example.o -lsocket -lnet -lnsl_s -o example example.o: example.c cc -c -I/usr/netinclude example.c aspp_unix/aspp.h0100644000000000000000000004144207553265146012721 0ustar rootroot /********************************************************/ /* File name: aspp.h */ /* Version: 2.0 */ /********************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #define DFD_TABLE_SIZE 128 /* Max. async ports to be control */ #define DCMD_IOCTL 16 /* IOCTL command */ #define DCMD_IOCTL_EX 64 /* IOCTL command */ #define DCMD_FLOWCTRL 17 /* Flow control command */ #define DCMD_LINECTRL 18 /* Line status control command */ #define DCMD_LSTATUS 19 /* Line status read command */ #define DCMD_FLUSH 20 /* Buffer flush command */ #define DCMD_IQUEUE 21 /* Input queue command */ #define DCMD_OQUEUE 22 /* Output queue command */ #define DCMD_BAUDRATE 23 /* Set port's baud rate command */ #define DCMD_BREAK 35 /* Send break in mini-seconds */ /* parameters for D_COMMAND_IOCTL ioctl command */ #define D_IOCTL_B300 0 /* IOCTL : baud rate = 300 bps */ #define D_IOCTL_B600 1 /* IOCTL : baud rate = 600 bps */ #define D_IOCTL_B1200 2 /* IOCTL : baud rate = 1200 bps */ #define D_IOCTL_B2400 3 /* IOCTL : baud rate = 2400 bps */ #define D_IOCTL_B4800 4 /* IOCTL : baud rate = 4800 bps */ #define D_IOCTL_B7200 5 /* IOCTL : baud rate = 7200 bps */ #define D_IOCTL_B9600 6 /* IOCTL : baud rate = 9600 bps */ #define D_IOCTL_B19200 7 /* IOCTL : baud rate = 19200 bps */ #define D_IOCTL_B38400 8 /* IOCTL : baud rate = 38400 bps */ #define D_IOCTL_B57600 9 /* IOCTL : baud rate = 57600 bps */ #define D_IOCTL_B115200 10 /* IOCTL : baud rate = 115200 bps */ #define D_IOCTL_B230400 11 /* IOCTL : baud rate = 230400 bps */ #define D_IOCTL_B460800 12 /* IOCTL : baud rate = 460800 bps */ #define D_IOCTL_B921600 13 /* IOCTL : baud rate = 921600 bps */ #define D_IOCTL_150 14 /* IOCTL : baud rate = 150 bps */ #define D_IOCTL_134 15 /* IOCTL : baud rate = 134.5 bps */ #define D_IOCTL_110 16 /* IOCTL : baud rate = 110 bps */ #define D_IOCTL_75 17 /* IOCTL : baud rate = 75 bps */ #define D_IOCTL_50 18 /* IOCTL : baud rate = 50 bps */ #define D_IOCTL_BIT8 3 /* IOCTL : 8 data bits */ #define D_IOCTL_BIT7 2 /* IOCTL : 7 data bits */ #define D_IOCTL_BIT6 1 /* IOCTL : 6 data bits */ #define D_IOCTL_BIT5 0 /* IOCTL : 5 data bits */ #define D_IOCTL_STOP1 0 /* IOCTL : 1 stop bit */ #define D_IOCTL_STOP2 4 /* IOCTL : 2 stop bits */ #define D_IOCTL_EVEN 8 /* IOCTL : even parity */ #define D_IOCTL_ODD 16 /* IOCTL : odd parity */ #define D_IOCTL_NONE 0 /* IOCTL : none parity */ /* * Global functions: */ int sio_init(); int sio_open(unsigned long server_ip, int port); int sio_close(int fd); int sio_ioctl(int fd, int baud, int mode); int sio_baud(int fd, long baud); int sio_flowctrl(int fd, int mode); int sio_lctrl(int fd, int mode); int sio_lstatus(int fd); int sio_flush(int fd, int func); int sio_write(int fd, char *buf, int len); int sio_read(int fd, char *buf, int len); int sio_break(int fd, int time); int sio_oqueue(int fd); int sio_iqueue(int fd); /* * Local static functions: */ static int SioOpen(unsigned long ipaddr, int tcpport); static int SioWaitAck(int fd, char cmd); static int SioCmdportFd(int fd); static int SioAddFdtbl(int fd, int cmdfd); static int SioDelFdtbl(int fd); struct aspp_fds { int fd_data; int fd_cmd; }; static struct aspp_fds asfds[DFD_TABLE_SIZE]; /****************************************************************************** * Initial data table using of ASPP functions * * This function must be called once before calling any other sio_open, * * sio_close.., etc. * * * * Arg: none * ******************************************************************************/ int sio_init() { int i; for ( i=0; i 192.168.2.1 * * int portno - serial port number of Async Server * * number range from 1 to 16. * * Return: >= 0 : file handle ID (open success). * * -1 : open fail. * ******************************************************************************/ int sio_open(unsigned long ipaddr, int portno) { int fd, fd2; if ( portno < 1 || portno > 16 ) return(-1); portno--; if ( (fd = SioOpen(ipaddr, portno + 950)) < 0 ) return(-1); if ( (fd2 = SioOpen(ipaddr, portno + 966)) < 0 ) { close(fd); return(-1); } if ( SioAddFdtbl(fd, fd2) != fd2 ) { close(fd2); close(fd); return(-1); } return(fd); } /****************************************************************************** * close Async Server serial port * * * * Arg: int fd - file handle ID return from sio_open() * ******************************************************************************/ int sio_close(int fd) { close(SioCmdportFd(fd)); close(fd); SioDelFdtbl(fd); return(0); } /****************************************************************************** * Set Async port baud rate and character mode * * * * Args: int fd - file handle ID return from sio_open() * * int baud - 0: 300 1: 600 2: 1200 * * 3: 2400 4: 4800 5: 7200 * * 6: 9600 7: 19200 8: 38400 * * 9: 57600 10: 115200 11: 230400 * * 12: 460800 13: 921600 14: 150 * * 15: 134 16: 110 17: 75 * * 18: 50 * * int mode - (bit 0,1) 0x00 - 5 data bits * * 0x01 - 6 data bits * * 0x10 - 7 data bits * * 0x11 - 8 data bits * * (bit 2) 0x00 - 1 stop bit * * 0x04 - 1.5/2 stop bits * * (bit 3,4,5) 0x00 - none parity * * 0x08 - odd parity * * 0x18 - even parity * * 0x28 - mark parity * * 0x38 - space parity * * * * Return: 0 : O.K. * * -1 : error * ******************************************************************************/ int sio_ioctl(int fd, int baud, int mode) { unsigned char buf[4]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_IOCTL; buf[1] = 2; buf[2] = (unsigned char)baud; buf[3] = (unsigned char)mode; if ( write(fd, buf, 4) != 4 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * Set Async port baud rate and character mode * * * * Args: int fd - file handle ID return from sio_open() * * int baud - 0: 300 1: 600 2: 1200 * * 3: 2400 4: 4800 5: 7200 * * 6: 9600 7: 19200 8: 38400 * * 9: 57600 10: 115200 11: 230400 * * 12: 460800 13: 921600 14: 150 * * 15: 134 16: 110 17: 75 * * 18: 50 * * int mode - (bit 0,1) 0x00 - 5 data bits * * 0x01 - 6 data bits * * 0x10 - 7 data bits * * 0x11 - 8 data bits * * (bit 2) 0x00 - 1 stop bit * * 0x04 - 1.5/2 stop bits * * (bit 3,4,5) 0x00 - none parity * * 0x08 - odd parity * * 0x18 - even parity * * 0x28 - mark parity * * 0x38 - space parity * * * * Return: 0 : O.K. * * -1 : error * ******************************************************************************/ int sio_ioctl_ex(int fd, int baud, int mode) { unsigned char buf[4]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_IOCTL_EX; buf[1] = 2; buf[2] = (unsigned char)baud; buf[3] = (unsigned char)mode; if ( write(fd, buf, 4) != 4 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * Set Async Port baud rate * * * * Args: int fd - file handle ID return from sio_open() * * long baud - desired baud rate * * * * Return: 0 : O.K. * * -1 : error * ******************************************************************************/ int sio_baud(int fd, long baud) { unsigned char buf[8]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_BAUDRATE; buf[1] = 4; *(long *)(&buf[2]) = baud; if ( write(fd, buf, 6) != 6 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * Set Async Port flow control * * * * Args: int fd - file handle ID return from sio_open() * * int mode - bit 0: CTS flow control * * bit 1: RTS flow control * * bit 2: Tx XON/XOFF flow control * * bit 3: Rx XON/XOFF flow control * * (0 = OFF, 1 = ON) * * * * Return: 0 : O.K. * * -1 : error * ******************************************************************************/ int sio_flowctrl(int fd, int mode) { unsigned char buf[8]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_FLOWCTRL; buf[1] = 4; if ( mode & 1 ) buf[2] = 1; else buf[2] = 0; if ( mode & 2 ) buf[3] = 1; else buf[3] = 0; if ( mode & 4 ) buf[4] = 1; else buf[4] = 0; if ( mode & 8 ) buf[5] = 1; else buf[5] = 0; if ( write(fd, buf, 6) != 6 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * Set Async Port line control * * * * Args: int fd - file handle ID return from sio_open() * * int mode - bit 0: DTR output state * * bit 1: RTS output state * * (0 = OFF, 1 = ON) * * * * Return: 0 : O.K. * * -1 : error * ******************************************************************************/ int sio_lctrl(int fd, int mode) { unsigned char buf[8]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_LINECTRL; buf[1] = 2; if ( mode & 1 ) buf[2] = 1; else buf[2] = 0; if ( mode & 2 ) buf[3] = 1; else buf[3] = 0; if ( write(fd, buf, 4) != 4 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * Get Async Port line status * * * * Args: int fd - file handle ID return from sio_open() * * * * Return: >=0 : line status: bit 0: DSR, bit 1: CTS, * * bit 2: DCD * * (1 - ON, 0 - OFF) * * -1 : error * ******************************************************************************/ int sio_lstatus(int fd) { unsigned char buf[4]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_LSTATUS; buf[1] = 0; if ( write(fd, buf, 2) != 2 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * Flush input/output buffer data * * * * Args: int fd - file handle ID return from sio_open() * * int func - 0 : flush input buffer * * 1 : flush output buffer * * 2 : flush input/output buffer * * * * Return: >= 0 : O.K. * * -1 : error * ******************************************************************************/ int sio_flush(int fd, int func) { unsigned char buf[4]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_FLUSH; buf[1] = 1; buf[2] = func; if ( write(fd, buf, 3) != 3 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * write data to Async Server serial port * * * * Args: int fd - file handle ID return from sio_open() * * char * buf - write out data buffer pointer * * int len - write out data length * * * * Return: >= 0 : write out data length * * -1 : write error * ******************************************************************************/ int sio_write(int fd, char *buf, int len) { return( write(fd, buf, len) ); } /****************************************************************************** * read data from Async Server serial port * * * * Args: int fd - file handle ID return from sio_open() * * char * buf - read data buffer pointer * * int len - read data buffer length * * * * Return: >= 0 : read data length * * -1 : read error * ******************************************************************************/ int sio_read(int fd, char *buf, int len) { return( read(fd, buf, len) ); } /****************************************************************************** * Send out a break signal * * * * Args: int fd - file handle ID return from sio_open() * * int time - break time in mini-second * * * * Return: 0 : O.K. * * -1 : error * ******************************************************************************/ int sio_break(int fd, int time) { unsigned char buf[8]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_BREAK; buf[1] = 2; *(unsigned short *)&buf[2] = ntohs(time); if ( write(fd, buf, 4) != 4 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * Get output buffer data queue size * * * * Args: int fd - file handle ID return from sio_open() * * * * Return: >= 0 : output buffer data queue size * * -1 : error * ******************************************************************************/ int sio_oqueue(int fd) { unsigned char buf[4]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_OQUEUE; buf[1] = 0; if ( write(fd, buf, 2) != 2 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * Get input buffer data queue size * * * * Args: int fd - file handle ID return from sio_open() * * * * Return: >= 0 : input buffer data queue size * * -1 : error * ******************************************************************************/ int sio_iqueue(int fd) { unsigned char buf[4]; if ( (fd = SioCmdportFd(fd)) == -1 ) return(-1); buf[0] = DCMD_IQUEUE; buf[1] = 0; if ( write(fd, buf, 2) != 2 ) return(-1); return( SioWaitAck(fd, buf[0]) ); } /****************************************************************************** * ASPP protocol control sub-functions * ******************************************************************************/ static int SioOpen(unsigned long ipaddr, int tcpport) { struct sockaddr_in des; int fd, len; if ( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) return(-1); memset(&des, 0, sizeof(des)); des.sin_family = AF_INET; des.sin_addr.s_addr = ipaddr; des.sin_port = htons(tcpport); len = sizeof(struct sockaddr_in); if ( connect(fd, (struct sockaddr *)&des, len) < 0 ) { close(fd); return(-1); } return(fd); } static int SioWaitAck(int fd, char cmd) { struct timeval authtime; fd_set readfds; char tmp[20]; int len; short n; memset(&authtime, 0, sizeof(authtime)); authtime.tv_usec = 0L; authtime.tv_sec = 10; FD_ZERO(&readfds); FD_SET(fd, &readfds); if ( select(fd + 1, &readfds, NULL, NULL, &authtime) < 0 ) return(-1); if ( FD_ISSET(fd, &readfds) == 0 ) return(-1); len = read(fd, tmp, 20); if ( cmd == DCMD_IQUEUE || cmd == DCMD_OQUEUE ) { if ( len < 4 ) return(-1); if ( tmp[0] != cmd || tmp[1] != 2 ) return(-1); n = *(short *)(&tmp[2]); return( (int)n ); } else if ( cmd == DCMD_LSTATUS ) { if ( len < 5 ) return(-1); if ( tmp[0] != cmd || tmp[1] != 3 ) return(-1); n = 0; if ( tmp[2] == 1 ) n |= 1; if ( tmp[3] == 1 ) n |= 2; if ( tmp[4] == 1 ) n |= 4; return( (int)n ); } else { if ( len < 3 ) return(-1); if ( tmp[0] != cmd || tmp[1] != 'O' || tmp[2] != 'K' ) return(-1); } return(0); } static int SioCmdportFd(int fd) { int i; for ( i=0; i