Guest User

Pseudo Ports

a guest
Oct 12th, 2010
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #define _XOPEN_SOURCE
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <stdio.h>
  5. #include <string.h>  /* String function definitions */
  6. #include <unistd.h>  /* UNIX standard function definitions */
  7. #include <errno.h>   /* Error number definitions */
  8. #include <termios.h> /* POSIX terminal control definitions */
  9.  
  10. int main()
  11. {
  12.     int fd, n = 0, error = 0;
  13.     int chk1 = -1, chk2 = -1;
  14.     char *dato;
  15.     char *PTS;
  16.     fd = open("/dev/ptmx", O_RDWR);
  17.     if (fd == -1)
  18.     {
  19.         printf ("Error opening the serial device");
  20.         exit(0);
  21.     }
  22.    
  23.     PTS = ptsname(fd);
  24.     printf("The slave port name is: %s", PTS);
  25.    
  26.     chk1 = grantpt(fd);
  27.     chk2 = grantpt(fd);
  28.    
  29.     if (chk1 == -1 | chk2 == -1)
  30.         printf("\nPort access denied");
  31.  
  32.     getchar();
  33.    
  34.     error = read(fd,dato,4);
  35.    
  36.     if (error = 0)
  37.     printf("\nNothing in buffer");
  38.     else
  39.     printf("%s",dato);
  40.     close(fd);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment