Skip to content

Commit 572318c

Browse files
committed
TELNET server and client.
1 parent 6363ea1 commit 572318c

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ src/libncp.a
55
src/ping
66
src/finger
77
src/finser
8+
src/telnet
9+
src/telser
810
test/*.log

src/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CFLAGS=-g -Wall
22

33
NCP=-L. -lncp
44

5-
all: ncp ping finger finser
5+
all: ncp ping finger finser telnet telser
66

77
ncp: ncp.o imp.o
88

@@ -18,3 +18,9 @@ finger: finger.o libncp.a
1818

1919
finser: finser.o libncp.a
2020
$(CC) -o $@ $< $(NCP)
21+
22+
telnet: telnet.o libncp.a
23+
$(CC) -o $@ $< $(NCP)
24+
25+
telser: telser.o libncp.a
26+
$(CC) -o $@ $< $(NCP)

src/telnet.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <stdio.h>
2+
#include <errno.h>
3+
#include <stdlib.h>
4+
#include <unistd.h>
5+
#include <string.h>
6+
#include "ncp.h"
7+
8+
int main (int argc, char **argv)
9+
{
10+
char *command;
11+
char reply[1000];
12+
int host, connection, size;
13+
14+
if (argc != 2) {
15+
fprintf (stderr, "Usage: %s host\n", argv[0]);
16+
exit (1);
17+
}
18+
19+
host = atoi (argv[1]);
20+
21+
if (ncp_init (NULL) == -1) {
22+
fprintf (stderr, "NCP initializtion error: %s.\n", strerror (errno));
23+
if (errno == ECONNREFUSED)
24+
fprintf (stderr, "Is the NCP server started?\n");
25+
exit (1);
26+
}
27+
28+
printf ("TELNET to host %03o.\n", host);
29+
30+
switch (ncp_open (host, 23, &connection)) {
31+
case 0:
32+
break;
33+
case -1:
34+
default:
35+
fprintf (stderr, "NCP open error.\n");
36+
exit (1);
37+
case -2:
38+
fprintf (stderr, "Open refused.\n");
39+
exit (1);
40+
}
41+
42+
if (ncp_close (connection) == -1) {
43+
fprintf (stderr, "NCP close error.\n");
44+
exit (1);
45+
}
46+
}

src/telser.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdio.h>
2+
#include <errno.h>
3+
#include <stdlib.h>
4+
#include <unistd.h>
5+
#include <string.h>
6+
#include "ncp.h"
7+
8+
int main (int argc, char **argv)
9+
{
10+
char command[1000];
11+
char reply[1000];
12+
int host, connection, size;
13+
14+
if (argc != 1) {
15+
fprintf (stderr, "Usage: %s\n", argv[0]);
16+
exit (1);
17+
}
18+
19+
if (ncp_init (NULL) == -1) {
20+
fprintf (stderr, "NCP initializtion error: %s.\n", strerror (errno));
21+
if (errno == ECONNREFUSED)
22+
fprintf (stderr, "Is the NCP server started?\n");
23+
exit (1);
24+
}
25+
26+
if (ncp_listen (23, &host, &connection) == -1) {
27+
fprintf (stderr, "NCP listen error.\n");
28+
exit (1);
29+
}
30+
31+
if (ncp_close (connection) == -1) {
32+
fprintf (stderr, "NCP close error.\n");
33+
exit (1);
34+
}
35+
36+
}

0 commit comments

Comments
 (0)