#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <time.h>
#include <unistd.h>
#include <atalk/errchk.h>
#include <atalk/logger.h>
#include <atalk/util.h>
Macros | |
#define | CMSG_SPACE(len) |
Functions | |
int | setnonblock (int fd, int cmd) |
set or unset non-blocking IO on a fd | |
ssize_t | readt (int socket, void *data, const size_t length, int setnonblocking, int timeout) |
ssize_t | writet (int socket, void *data, const size_t length, int setnonblocking, int timeout) |
const char * | getip_string (const struct sockaddr *sa) |
convert an IPv4 or IPv6 address to a static string using inet_ntop | |
unsigned int | getip_port (const struct sockaddr *sa) |
return port number from struct sockaddr | |
void | apply_ip_mask (struct sockaddr *sa, int mask) |
apply netmask to IP (v4 or v6) | |
int | compare_ip (const struct sockaddr *sa1, const struct sockaddr *sa2) |
compare IP addresses for equality | |
int | tokenize_ip_port (const char *ipurl, char **address, char **port) |
struct asev * | asev_init (int max) |
bool | asev_add_fd (struct asev *asev, int fd, enum asev_fdtype fdtype, void *private, int protocol) |
bool | asev_del_fd (struct asev *asev, int fd) |
int | recv_fd (int fd, int nonblocking) |
int | send_fd (int socket, int fd) |
Variables | |
static char | ipv4mapprefix [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff} |
Netatalk utility functions
#define CMSG_SPACE | ( | len | ) |
void apply_ip_mask | ( | struct sockaddr * | sa, |
int | mask ) |
apply netmask to IP (v4 or v6)
Modifies IP address in sa->sin[6]_addr-s[6]_addr. The caller is responsible for passing a value for mask that is sensible to the passed address, e.g. 0 <= mask <= 32 for IPv4 or 0<= mask <= 128 for IPv6. mask > 32 for IPv4 is treated as mask = 32, mask > 128 is set to 128 for IPv6.
sa | (rw) pointer to an struct sockaddr |
mask | (r) number of maskbits |
bool asev_add_fd | ( | struct asev * | asev, |
int | fd, | ||
enum asev_fdtype | fdtype, | ||
void * | private, | ||
int | protocol ) |
Add a fd to a dynamic pollfd array and associated data array
This uses an additional array of struct polldata which stores type information (enum fdtype) and a pointer to anciliary user data.
bool asev_del_fd | ( | struct asev * | asev, |
int | fd ) |
Remove fd from asev
struct asev * asev_init | ( | int | max | ) |
Allocate and initialize atalk socket event struct
int compare_ip | ( | const struct sockaddr * | sa1, |
const struct sockaddr * | sa2 ) |
compare IP addresses for equality
sa1 | (r) pointer to an struct sockaddr |
sa2 | (r) pointer to an struct sockaddr |
unsigned int getip_port | ( | const struct sockaddr * | sa | ) |
return port number from struct sockaddr
sa | (r) pointer to an struct sockaddr |
const char * getip_string | ( | const struct sockaddr * | sa | ) |
convert an IPv4 or IPv6 address to a static string using inet_ntop
IPv6 mapped IPv4 addresses are returned as IPv4 addreses e.g. ::ffff:10.0.0.0 is returned as "10.0.0.0".
sa | (r) pointer to an struct sockaddr |
ssize_t readt | ( | int | socket, |
void * | data, | ||
const size_t | length, | ||
int | setnonblocking, | ||
int | timeout ) |
non-blocking drop-in replacement for read with timeout using select
socket | (r) socket, if in blocking mode, pass "setnonblocking" arg as 1 |
data | (rw) buffer for the read data |
length | (r) how many bytes to read |
setnonblocking | (r) when non-zero this func will enable and disable non blocking io mode for the socket |
timeout | (r) number of seconds to try reading, 0 means no timeout |
int recv_fd | ( | int | fd, |
int | nonblocking ) |
Receive a fd on a suitable socket
fd | (r) PF_UNIX socket to receive on |
nonblocking | (r) 0: fd is in blocking mode - 1: fd is nonblocking, poll for 1 sec |
int send_fd | ( | int | socket, |
int | fd ) |
int setnonblock | ( | int | fd, |
int | cmd ) |
set or unset non-blocking IO on a fd
fd | (r) File descriptor |
cmd | (r) 0: disable non-blocking IO, i.e. block <>0: enable non-blocking IO |
int tokenize_ip_port | ( | const char * | ipurl, |
char ** | address, | ||
char ** | port ) |
Tokenize IP(4/6) addresses with an optional port into address and port
ipurl | (r) IP URL string |
address | (w) IP address |
port | (w) IP port |
Tokenize IPv4, IPv4:port, IPv6, [IPv6] or [IPv6:port] URL into address and port and return two allocated strings with the address and the port.
If the function returns 0, then address point to a newly allocated valid address string, port may either be NULL or point to a newly allocated port number.
If the function returns -1, then the contents of address and port are undefined.
ssize_t writet | ( | int | socket, |
void * | data, | ||
const size_t | length, | ||
int | setnonblocking, | ||
int | timeout ) |
non-blocking drop-in replacement for read with timeout using select
socket | (r) socket, if in blocking mode, pass "setnonblocking" arg as 1 |
data | (rw) buffer for the read data |
length | (r) how many bytes to read |
setnonblocking | (r) when non-zero this func will enable and disable non blocking io mode for the socket |
timeout | (r) number of seconds to try reading |
|
static |