2020-06-25 20:37:12 -04:00
|
|
|
#include <stdio.h>
|
2020-06-20 00:37:19 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <patty/ax25.h>
|
|
|
|
|
|
|
|
int patty_ax25_call_socket(int server,
|
2020-06-30 23:20:12 -04:00
|
|
|
int opts,
|
2020-07-02 16:07:23 -04:00
|
|
|
int proto,
|
2020-06-30 23:20:12 -04:00
|
|
|
char *path,
|
|
|
|
size_t len) {
|
2020-06-20 19:37:03 -04:00
|
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_SOCKET;
|
2020-06-20 00:37:19 -04:00
|
|
|
|
|
|
|
patty_ax25_call_socket_request request = {
|
2020-07-02 16:07:23 -04:00
|
|
|
opts, proto
|
2020-06-20 00:37:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
patty_ax25_call_socket_response response;
|
|
|
|
|
|
|
|
if (write(server, &call, sizeof(call)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write(server, &request, sizeof(request)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read(server, &response, sizeof(response)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
2020-06-30 23:20:12 -04:00
|
|
|
if (path) {
|
|
|
|
strncpy(path, response.path, len);
|
|
|
|
}
|
|
|
|
|
2020-06-20 00:37:19 -04:00
|
|
|
errno = response.eno;
|
|
|
|
|
|
|
|
return response.ret;
|
|
|
|
|
|
|
|
error_io:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int patty_ax25_call_bind(int server,
|
|
|
|
int socket,
|
|
|
|
patty_ax25_addr *peer) {
|
2020-06-20 19:37:03 -04:00
|
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_BIND;
|
2020-06-20 00:37:19 -04:00
|
|
|
|
|
|
|
patty_ax25_call_bind_request request = {
|
|
|
|
socket
|
|
|
|
};
|
|
|
|
|
|
|
|
patty_ax25_call_bind_response response;
|
|
|
|
|
|
|
|
memcpy(&request.peer, peer, sizeof(*peer));
|
|
|
|
|
|
|
|
if (write(server, &call, sizeof(call)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write(server, &request, sizeof(request)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read(server, &response, sizeof(response)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = response.eno;
|
|
|
|
|
|
|
|
return response.ret;
|
|
|
|
|
|
|
|
error_io:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int patty_ax25_call_listen(int server,
|
|
|
|
int socket) {
|
2020-06-20 19:37:03 -04:00
|
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_LISTEN;
|
2020-06-20 00:37:19 -04:00
|
|
|
|
|
|
|
patty_ax25_call_listen_request request = {
|
|
|
|
socket
|
|
|
|
};
|
|
|
|
|
|
|
|
patty_ax25_call_listen_response response;
|
|
|
|
|
|
|
|
if (write(server, &call, sizeof(call)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write(server, &request, sizeof(request)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read(server, &response, sizeof(response)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = response.eno;
|
|
|
|
|
|
|
|
return response.ret;
|
|
|
|
|
|
|
|
error_io:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int patty_ax25_call_accept(int server,
|
|
|
|
int socket,
|
|
|
|
patty_ax25_addr *peer,
|
2020-06-30 23:20:12 -04:00
|
|
|
char *path,
|
|
|
|
size_t len) {
|
2020-06-20 19:37:03 -04:00
|
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_ACCEPT;
|
2020-06-20 00:37:19 -04:00
|
|
|
|
|
|
|
patty_ax25_call_accept_request request = {
|
|
|
|
socket
|
|
|
|
};
|
|
|
|
|
|
|
|
patty_ax25_call_accept_response response;
|
|
|
|
|
2020-06-30 23:20:12 -04:00
|
|
|
memset(&response, '\0', sizeof(response));
|
|
|
|
|
2020-06-20 00:37:19 -04:00
|
|
|
if (write(server, &call, sizeof(call)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write(server, &request, sizeof(request)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read(server, &response, sizeof(response)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.ret >= 0) {
|
|
|
|
memcpy(peer, &response.peer, sizeof(*peer));
|
2020-06-30 23:20:12 -04:00
|
|
|
|
|
|
|
if (path) {
|
|
|
|
strncpy(path, response.path, len);
|
|
|
|
}
|
2020-06-20 00:37:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
errno = response.eno;
|
|
|
|
|
|
|
|
return response.ret;
|
|
|
|
|
|
|
|
error_io:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int patty_ax25_call_connect(int server,
|
|
|
|
int socket,
|
2020-06-30 23:20:12 -04:00
|
|
|
patty_ax25_addr *peer) {
|
2020-06-20 19:37:03 -04:00
|
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_CONNECT;
|
2020-06-20 00:37:19 -04:00
|
|
|
|
|
|
|
patty_ax25_call_connect_request request = {
|
|
|
|
socket
|
|
|
|
};
|
|
|
|
|
|
|
|
patty_ax25_call_connect_response response;
|
|
|
|
|
|
|
|
memcpy(&request.peer, peer, sizeof(*peer));
|
|
|
|
|
|
|
|
if (write(server, &call, sizeof(call)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write(server, &request, sizeof(request)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read(server, &response, sizeof(response)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = response.eno;
|
|
|
|
|
|
|
|
return response.ret;
|
|
|
|
|
|
|
|
error_io:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int patty_ax25_call_close(int server,
|
|
|
|
int socket) {
|
2020-06-20 19:37:03 -04:00
|
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_CLOSE;
|
2020-06-20 00:37:19 -04:00
|
|
|
|
|
|
|
patty_ax25_call_close_request request = {
|
|
|
|
socket
|
|
|
|
};
|
|
|
|
|
|
|
|
patty_ax25_call_close_response response;
|
|
|
|
|
|
|
|
if (write(server, &call, sizeof(call)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write(server, &request, sizeof(request)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read(server, &response, sizeof(response)) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = response.eno;
|
|
|
|
|
|
|
|
return response.ret;
|
|
|
|
|
|
|
|
error_io:
|
|
|
|
return -1;
|
|
|
|
}
|