Skip to content

NCP improvements #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 14, 2025
6 changes: 4 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ finger: finger.o libncp.a
finser: finser.o libncp.a
$(CC) -o $@ $< $(NCP)

telnet: telnet.o libncp.a
$(CC) -o $@ $< $(NCP)
telnet: telnet.o tty.o libncp.a
$(CC) -o $@ telnet.o tty.o $(NCP)

tty:: tty.h
11 changes: 6 additions & 5 deletions src/finger.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

int main (int argc, char **argv)
{
char *command;
char command[1000];
char reply[1000];
int host, connection, size;

if (argc != 2) {
fprintf (stderr, "Usage: %s host\n", argv[0]);
if (argc < 2 || argc > 3) {
fprintf (stderr, "Usage: %s host [user(s)]\n", argv[0]);
exit (1);
}

Expand All @@ -39,8 +39,9 @@ int main (int argc, char **argv)
exit (1);
}

command = "Sample Finger command from client.\r\n";
if (ncp_write (connection, command, strlen (command)) == -1) {
size = snprintf (command, sizeof command, "%s\r\n",
argc == 3 ? argv[2] : "");
if (ncp_write (connection, command, &size) == -1) {
fprintf (stderr, "NCP write error.\n");
exit (1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/finser.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main (int argc, char **argv)
"Sample response from Finger server.\r\n"
"Data from client was: \"%s\".\r\n", command);
size = strlen (reply);
if (ncp_write (connection, reply, size) == -1) {
if (ncp_write (connection, reply, &size) == -1) {
fprintf (stderr, "NCP write error.\n");
exit (1);
}
Expand Down
11 changes: 7 additions & 4 deletions src/libncp.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ int ncp_open (int host, unsigned socket, int *connection)
return -1;
if (u32 (message + 2) != socket)
return -1;
if (message[6] == 255)
if (message[7] == 255)
return -2;
*connection = message[6];
return 0;
Expand Down Expand Up @@ -153,6 +153,7 @@ int ncp_read (int connection, void *data, int *length)
type (WIRE_READ);
add (connection);
add (*length);
*length = 0;
n = transact ();
if (n == -1)
return -1;
Expand All @@ -163,16 +164,18 @@ int ncp_read (int connection, void *data, int *length)
return 0;
}

int ncp_write (int connection, void *data, int length)
int ncp_write (int connection, void *data, int *length)
{
type (WIRE_WRITE);
add (connection);
memcpy (message + size, data, length);
size += length;
memcpy (message + size, data, *length);
size += *length;
*length = 0;
if (transact () == -1)
return -1;
if (message[1] != connection)
return -1;
*length = message[2] << 8 | message[3];
return 0;
}

Expand Down
Loading
Loading