250 lines
5 KiB
C
250 lines
5 KiB
C
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
|
|
#include <patty/ax25.h>
|
|
|
|
int patty_ax25_call_socket(int server,
|
|
int proto,
|
|
int type,
|
|
char *path,
|
|
size_t len) {
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_SOCKET;
|
|
|
|
patty_ax25_call_socket_request request = {
|
|
proto, type
|
|
};
|
|
|
|
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;
|
|
}
|
|
|
|
if (path) {
|
|
strncpy(path, response.path, len);
|
|
}
|
|
|
|
errno = response.eno;
|
|
|
|
return response.ret;
|
|
|
|
error_io:
|
|
return -1;
|
|
}
|
|
|
|
int patty_ax25_call_setsockopt(int server,
|
|
int fd,
|
|
int opt,
|
|
void *data,
|
|
size_t len) {
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_SETSOCKOPT;
|
|
|
|
patty_ax25_call_setsockopt_request request = {
|
|
.fd = fd,
|
|
.opt = opt,
|
|
.len = len
|
|
};
|
|
|
|
patty_ax25_call_setsockopt_response response;
|
|
|
|
if (write(server, &call, sizeof(call)) < 0) {
|
|
goto error_io;
|
|
}
|
|
|
|
if (write(server, &request, sizeof(request)) < 0) {
|
|
goto error_io;
|
|
}
|
|
|
|
if (write(server, data, len) < 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_bind(int server,
|
|
int fd,
|
|
patty_ax25_addr *peer) {
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_BIND;
|
|
|
|
patty_ax25_call_bind_request request = {
|
|
fd
|
|
};
|
|
|
|
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 fd) {
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_LISTEN;
|
|
|
|
patty_ax25_call_listen_request request = {
|
|
fd
|
|
};
|
|
|
|
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 fd,
|
|
patty_ax25_addr *peer,
|
|
char *path,
|
|
size_t len) {
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_ACCEPT;
|
|
|
|
patty_ax25_call_accept_request request = {
|
|
fd
|
|
};
|
|
|
|
patty_ax25_call_accept_response response;
|
|
|
|
memset(&response, '\0', sizeof(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;
|
|
}
|
|
|
|
if (response.ret >= 0) {
|
|
memcpy(peer, &response.peer, sizeof(*peer));
|
|
|
|
if (path) {
|
|
strncpy(path, response.path, len);
|
|
}
|
|
}
|
|
|
|
errno = response.eno;
|
|
|
|
return response.ret;
|
|
|
|
error_io:
|
|
return -1;
|
|
}
|
|
|
|
int patty_ax25_call_connect(int server,
|
|
int fd,
|
|
patty_ax25_addr *peer) {
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_CONNECT;
|
|
|
|
patty_ax25_call_connect_request request = {
|
|
fd
|
|
};
|
|
|
|
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 fd) {
|
|
enum patty_ax25_call call = PATTY_AX25_CALL_CLOSE;
|
|
|
|
patty_ax25_call_close_request request = {
|
|
fd
|
|
};
|
|
|
|
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;
|
|
}
|