Add missing src/call.c
This commit is contained in:
parent
ac55d13057
commit
1240061aa8
1 changed files with 203 additions and 0 deletions
203
src/call.c
Normal file
203
src/call.c
Normal file
|
@ -0,0 +1,203 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <patty/ax25.h>
|
||||||
|
|
||||||
|
int patty_ax25_call_socket(int server,
|
||||||
|
int type) {
|
||||||
|
int call = PATTY_AX25_CALL_SOCKET;
|
||||||
|
|
||||||
|
patty_ax25_call_socket_request request = {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = response.eno;
|
||||||
|
|
||||||
|
return response.ret;
|
||||||
|
|
||||||
|
error_io:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int patty_ax25_call_bind(int server,
|
||||||
|
int socket,
|
||||||
|
patty_ax25_addr *peer) {
|
||||||
|
int call = PATTY_AX25_CALL_BIND;
|
||||||
|
|
||||||
|
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) {
|
||||||
|
int call = PATTY_AX25_CALL_LISTEN;
|
||||||
|
|
||||||
|
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,
|
||||||
|
char *path) {
|
||||||
|
int call = PATTY_AX25_CALL_ACCEPT;
|
||||||
|
|
||||||
|
patty_ax25_call_accept_request request = {
|
||||||
|
socket
|
||||||
|
};
|
||||||
|
|
||||||
|
patty_ax25_call_accept_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 (response.ret >= 0) {
|
||||||
|
strncpy(path, response.path, PATTY_AX25_SOCK_PATH_SIZE);
|
||||||
|
memcpy(peer, &response.peer, sizeof(*peer));
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = response.eno;
|
||||||
|
|
||||||
|
return response.ret;
|
||||||
|
|
||||||
|
error_io:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int patty_ax25_call_connect(int server,
|
||||||
|
int socket,
|
||||||
|
patty_ax25_addr *peer,
|
||||||
|
char *path) {
|
||||||
|
int call = PATTY_AX25_CALL_CONNECT;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.ret >= 0) {
|
||||||
|
strncpy(path, response.path, PATTY_AX25_SOCK_PATH_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = response.eno;
|
||||||
|
|
||||||
|
return response.ret;
|
||||||
|
|
||||||
|
error_io:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int patty_ax25_call_close(int server,
|
||||||
|
int socket) {
|
||||||
|
int call = PATTY_AX25_CALL_CLOSE;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue