1 | /* 2 | * Layer Two Tunnelling Protocol Daemon 3 | * Copyright (C) 1998 Adtran, Inc. 4 | * 5 | * Mark Spencer 6 | * 7 | * This software is distributed under the terms 8 | * of the GPL, which you should have received 9 | * along with this source. 10 | * 11 | * Pseudo-pty allocation routines... Concepts and code borrowed 12 | * from pty-redir by Magosanyi Arpad. 13 | * 14 | */ 15 | 16 | #include "l2tp.h" 17 | #include <fcntl.h> 18 | 19 | #ifdef SOLARIS 20 | #define PTY00 "/dev/ptyXX" 21 | #define PTY10 "pqrstuvwxyz" 22 | #define PTY01 "0123456789abcdef" 23 | #endif 24 | 25 | #ifdef LINUX 26 | #define PTY00 "/dev/ptyXX" 27 | #define PTY10 "pqrstuvwxyzabcde" 28 | #define PTY01 "0123456789abcdef" 29 | #endif 30 | 31 | #ifdef FREEBSD 32 | #define PTY00 "/dev/ptyXX" 33 | #define PTY10 "p" 34 | #define PTY01 "0123456789abcdefghijklmnopqrstuv" 35 | #endif 36 | 37 | int getPtyMaster (char *tty10, char *tty01) 38 | { 39 | char *p10; 40 | char *p01; 41 | static char dev[] = PTY00; 42 | int fd; 43 | 44 | for (p10 = PTY10; *p10; p10++) 45 | { 46 | dev[8] = *p10; 47 | for (p01 = PTY01; *p01; p01++) 48 | { 49 | dev[9] = *p01; 50 | fd = open (dev, O_RDWR | O_NONBLOCK); 51 | if (fd >= 0) 52 | { 53 | *tty10 = *p10; 54 | *tty01 = *p01; 55 | return fd; 56 | } 57 | } 58 | } 59 | log (LOG_CRIT, "%s: No more free pseudo-tty's\n", __FUNCTION__); 60 | return -1; 61 | }