All of lore.kernel.org
 help / color / mirror / Atom feed
From: uescher <linux-can_ger.kernel.org@myvdr.de>
To: linux-can@vger.kernel.org
Subject: [Patch] can-utils/slcanpty.c pseudo-terminal interface
Date: Mon, 17 Sep 2012 00:12:23 +0200	[thread overview]
Message-ID: <50564EC7.7020005@myvdr.de> (raw)

[-- 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) {

             reply	other threads:[~2012-09-16 22:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-16 22:12 uescher [this message]
2012-09-17  7:40 ` [Patch] can-utils/slcanpty.c pseudo-terminal interface 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50564EC7.7020005@myvdr.de \
    --to=linux-can_ger.kernel.org@myvdr.de \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.