2020-06-25 00:07:20 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
2020-06-25 01:54:39 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2020-06-25 00:07:20 -04:00
|
|
|
|
|
|
|
#include <patty/ax25.h>
|
|
|
|
|
|
|
|
static void usage(int argc, char **argv, const char *message, ...) {
|
|
|
|
if (message != NULL) {
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, message);
|
|
|
|
vfprintf(stderr, message, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2020-07-10 22:32:09 -04:00
|
|
|
fprintf(stderr, "usage: %s /var/run/patty/patty.sock remotecall\n", argv[0]);
|
2020-06-25 00:07:20 -04:00
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
patty_client *client;
|
2020-06-26 22:44:19 -04:00
|
|
|
patty_ax25_addr peer;
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
|
|
|
|
int fd;
|
2020-06-30 23:20:12 -04:00
|
|
|
|
|
|
|
uint8_t buf[4096];
|
|
|
|
ssize_t readlen;
|
2020-06-26 22:44:19 -04:00
|
|
|
|
2020-07-10 22:32:09 -04:00
|
|
|
if (argc < 2) {
|
2020-06-25 01:54:39 -04:00
|
|
|
usage(argc, argv, "No patty socket provided");
|
2020-07-10 22:32:09 -04:00
|
|
|
} else if (argc < 3) {
|
|
|
|
usage(argc, argv, "No remote callsign provided");
|
|
|
|
} else if (argc > 3) {
|
|
|
|
usage(argc, argv, "Too many arguments provided");
|
2020-06-25 00:07:20 -04:00
|
|
|
}
|
|
|
|
|
2020-08-24 22:52:52 -05:00
|
|
|
patty_ax25_pton(argv[2], &peer);
|
2020-06-26 22:44:19 -04:00
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
if ((client = patty_client_new(argv[1])) == NULL) {
|
2020-06-25 01:54:39 -04:00
|
|
|
fprintf(stderr, "%s: %s: %s: %s\n",
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
argv[0], "patty_client_new()", argv[1], strerror(errno));
|
2020-06-25 01:54:39 -04:00
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
goto error_client_new;
|
2020-06-25 00:07:20 -04:00
|
|
|
}
|
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
if ((fd = patty_client_socket(client, PATTY_AX25_PROTO_NONE, PATTY_AX25_SOCK_STREAM)) < 0) {
|
2020-06-25 20:37:12 -04:00
|
|
|
fprintf(stderr, "%s: %s: %s\n",
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
argv[0], "patty_client_socket()", strerror(errno));
|
2020-06-25 20:37:12 -04:00
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
goto error_client_socket;
|
2020-06-25 20:37:12 -04:00
|
|
|
}
|
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
if (patty_client_connect(client, fd, &peer) < 0) {
|
2020-06-25 20:37:12 -04:00
|
|
|
fprintf(stderr, "%s: %s: %s\n",
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
argv[0], "patty_client_connect()", strerror(errno));
|
2020-06-25 20:37:12 -04:00
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
goto error_client_connect;
|
2020-06-30 23:20:12 -04:00
|
|
|
}
|
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
while ((readlen = read(fd, buf, sizeof(buf))) > 0) {
|
2020-06-30 23:20:12 -04:00
|
|
|
if (write(1, buf, readlen) < 0) {
|
|
|
|
goto error_write;
|
|
|
|
}
|
2020-06-25 20:37:12 -04:00
|
|
|
}
|
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
patty_client_close(client, fd);
|
2020-06-25 20:37:12 -04:00
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
patty_client_destroy(client);
|
2020-06-25 00:07:20 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2020-06-30 23:20:12 -04:00
|
|
|
error_write:
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
error_client_connect:
|
|
|
|
patty_client_close(client, fd);
|
2020-06-30 23:20:12 -04:00
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
error_client_socket:
|
|
|
|
patty_client_destroy(client);
|
2020-06-25 20:37:12 -04:00
|
|
|
|
Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally
Changes:
* Implement patty_client_new() to handle opening the server Unix
domain socket, and to allocate a dict for mapping server-side
sockets with current process file descriptors
* Reimplement all server calls in src/call.c around the new
patty_client type; calls which result in the creation of a
Unix98 PTY by the patty server now handle opening the local PTY
and setting the file descriptor to raw mode. Furthermore, these
calls deal exclusively in terms of current process file
descriptors
* Refactor src/server.c to use the new patty_client type and calls
* Refactor examples/client.c, examples/server.c, examples/ax25dump.c
to use the new patty_client type and calls
* Fix a bug in src/server.c, respond_accept() wherein a 0, rather
than the file descriptor of the socket, is sent to the client as a
return value
2020-08-01 20:21:01 -04:00
|
|
|
error_client_new:
|
2020-06-25 00:07:20 -04:00
|
|
|
return 1;
|
|
|
|
}
|