tel/libtel.h
2023-11-02 19:43:50 -04:00

42 lines
1 KiB
C

#pragma once
#include <sys/types.h>
#define TEL_STRADDRLEN (INET6_ADDRSTRLEN + 1 + 5)
union tel_sa_any {
struct sockaddr_in v4;
struct sockaddr_in6 v6;
};
int tel_sa_any_eq(union tel_sa_any *a, union tel_sa_any *b);
enum tel_message {
MSG_PICKUP,
MSG_CALL,
MSG_LIST,
MSG_SOCKET,
MSG_OK,
MSG_ERROR,
MSG_NONE,
};
int tel_get_addr(char *ip, char *port, struct sockaddr **addr, socklen_t *addr_len);
int tel_straddr(const struct sockaddr *restrict addr, char *restrict buf);
ssize_t tel_write_all(int fd, const void *buf, size_t count);
ssize_t tel_read_all(int fd, void *buf, size_t count);
ssize_t tel_write_u32(int fd, uint32_t n);
ssize_t tel_read_u32(int fd, uint32_t *n);
ssize_t tel_write_u16(int fd, uint16_t n);
ssize_t tel_read_u16(int fd, uint16_t *n);
ssize_t tel_write_fd(int stream, int fd);
ssize_t tel_read_fd(int sock, int *fd);
ssize_t tel_write_sockaddr(int fd, struct sockaddr *addr);
ssize_t tel_read_sockaddr(int fd, union tel_sa_any *addr, socklen_t *addr_len);
ssize_t tel_write_err(int fd, const char *msg);