linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch] can-utils/slcanpty.c pseudo-terminal interface
@ 2012-09-16 22:12 uescher
  2012-09-17  7:40 ` Marc Kleine-Budde
  0 siblings, 1 reply; 7+ messages in thread
From: uescher @ 2012-09-16 22:12 UTC (permalink / raw)
  To: linux-can

[-- Attachment #1: Type: text/plain, Size: 125 bytes --]

Add Support for the Unix 98 pseudo-terminal interface /dev/ptmx /dev/pts/N

please take a look over the little Patch.
Thanks

[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 1643 bytes --]

diff --git a/slcanpty.c b/slcanpty.c
index 67dcf35..e3b7304 100644
--- a/slcanpty.c
+++ b/slcanpty.c
@@ -26,6 +26,11 @@
  *
  */
 
+#ifndef _GNU_SOURCE  
+// To get ptsname grantpt and unlockpt definitions from stdlib.h  
+#define _GNU_SOURCE  
+#endif  
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -45,6 +50,8 @@
 /* maximum rx buffer len: extended CAN frame with timestamp */
 #define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r")+1)
 
+#define DEVICE_NAME_PTMX "/dev/ptmx"
+
 #define DEBUG
 
 static int asc2nibble(char c)
@@ -387,6 +394,8 @@ int main(int argc, char **argv)
 		fprintf(stderr, "Usage: %s <pty> <can interface>\n", argv[0]);
 		fprintf(stderr, "e.g. '%s /dev/ptyc0 can0' creates"
 			" /dev/ttyc0 for the slcan application\n", argv[0]);
+		fprintf(stderr, "e.g. for pseudo-terminal '%s /dev/ptmx can0' creates"
+			" /dev/pts/N\n", argv[0]);
 		fprintf(stderr, "\n");
 		return 1;
 	}
@@ -408,6 +417,27 @@ int main(int argc, char **argv)
 			   ECHONL | ECHOPRT | ECHOKE | ICRNL);
 	tcsetattr(p, TCSANOW, &topts);
 
+	//Support for the Unix 98 pseudo-terminal interface /dev/ptmx /dev/pts/N
+	if  (strcmp(argv[1],DEVICE_NAME_PTMX) == 0) {
+		if (grantpt(p) < 0) {
+			perror("grantpt");
+			return 1;
+		}
+
+		if (unlockpt(p) < 0) {
+			perror("unlockpt");
+			return 1;
+		}
+
+		char* name_pts = NULL;	/* slave pseudo-terminal device name */
+		name_pts = ptsname(p);
+		if (name_pts == NULL) {
+			perror("ptsname");
+			return 1;
+		}
+		printf("open: %s: slave pseudo-terminal is %s\n", argv[1], name_pts);
+	}
+
 	/* open socket */
 	s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
 	if (s < 0) {

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-12-20 10:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-16 22:12 [Patch] can-utils/slcanpty.c pseudo-terminal interface uescher
2012-09-17  7:40 ` Marc Kleine-Budde
2012-09-21  8:28   ` uescher
2012-12-15  1:14   ` uescher
2012-12-16 16:02     ` Oliver Hartkopp
2012-12-17 18:09       ` uescher
2012-12-20 10:43         ` Oliver Hartkopp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).