(X)Net slip link linux

Well here I have been working on it for a while. Because (new) Linux works with master /dev/pmtx and slave /dev/pts/? it is not always easy to find out which slave you will be assigned. Custom programs such as kissattach that give the slave with stdout. Now slattach does not suffer from it unfortunately. Oh well in Debian than.

I use the following program to create a master and slave.

/*compile with : gcc -Wall -O2 -D_GNU_SOURCE tty0tty.c -o tty0tty */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>


int
ptym_open(char *pts_name, char *pts_name_s , int pts_namesz)
{
char *ptr;
int fdm;

strncpy(pts_name, "/dev/ptmx", pts_namesz);
pts_name[pts_namesz - 1] = '\0';

fdm = posix_openpt(O_RDWR | O_NONBLOCK);
if (fdm < 0)
return(-1);
if (grantpt(fdm) < 0) 
{
close(fdm);
return(-2);
}
if (unlockpt(fdm) < 0) 
{
close(fdm);
return(-3);
}
if ((ptr = ptsname(fdm)) == NULL) 
{
close(fdm);
return(-4);
}

strncpy(pts_name_s, ptr, pts_namesz);
pts_name[pts_namesz - 1] = '\0';

return(fdm); 
}


int main(void)
{
char master1[1024];
char slave1[1024];
char master2[1024];
char slave2[1024];

int fd1;
int fd2;

char c1,c2;

fd1=ptym_open(master1,slave1,1024);

fd2=ptym_open(master2,slave2,1024);

{
  FILE *fp;

  printf("%s <-> %s\n",slave1,slave2);

  if((fp=freopen("/tmp/slip", "w" ,stdout))==NULL) {
    printf("Cannot open file.\n");
    exit(1);
}

  printf("%s %s\n",slave1,slave2);

  fclose(fp);

}
while(1)
{
if(read (fd1,&c1,1) == 1) write(fd2,&c1,1);
usleep(20);
if(read (fd2,&c2,1) == 1) write(fd1,&c2,1);
usleep(20);
};

close(fd1);
close(fd2);

return EXIT_SUCCESS;
}

I have added the code below. Because I would like the pts to be written down in a file.

{
  FILE *fp;

  printf("%s <-> %s\n",slave1,slave2);

  if((fp=freopen("/tmp/slip", "w" ,stdout))==NULL) {
    printf("Cannot open file.\n");
    exit(1);
}

  printf("%s %s\n",slave1,slave2);

  fclose(fp);

}
As you can see above, the pts are displayed with printf and they are written in /tmp/slip. Well here I wanted to go. Now I can read the file. Here I use the following in my start script of (X) Net.
#!/bin/sh
XNET_DIR=/usr/local/xnet
LINIP=192.168.1.200 # LINUX-IP address
XNET=192.168.1.201 # XNET address
#
cd /usr/local/xnet
./pts & # Hier worden de ptssen gemaakt ?
#
sleep 2
#
attachthem () {
read PTS1 PTS2
echo “Starting PTS gekloot voor de slip link :)”
slattach -s 38400 -p slip $PTS1 &
sleep 1
ifconfig sl0 $LINIP netmask 255.255.255.255 pointopoint $XNET mtu 236 up
sleep 1
sed -i “s,attach sdev6 slip 38400 /dev/.*$,attach sdev6 slip 38400 $PTS2,” /usr/local/xnet/AUTOBOOT.NET
}

tail -n 1 /tmp/slip | attachthem
#rm /tmp/slip <> Niet weg gooien sukkel, die hebben we nog nodig

With the command “sed” the PTS is adjusted in AUTOBOOT.NET. Now I do not have to worry about what pts I get assigned.