#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) |
| non-blocking drop-in replacement for read with timeout using select | |
| 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 | |
| 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) |
| Tokenize IP(4/6) addresses with an optional port into address and port. | |
| struct asev * | asev_init (int max) |
| 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. | |
| bool | asev_del_fd (struct asev *asev, int fd) |
| Remove fd from asev. | |
| int | recv_fd (int fd, int nonblocking) |
| Receive a fd on a suitable socket. | |
| 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: socket
| #define CMSG_SPACE | ( | len | ) |
Length of the space taken up by a padded control message of length 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.
| [in,out] | sa | pointer to an struct sockaddr |
| [in] | mask | 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
| [in] | sa1 | pointer to an struct sockaddr |
| [in] | sa2 | pointer to an struct sockaddr |
| unsigned int getip_port | ( | const struct sockaddr * | sa | ) |
return port number from struct sockaddr
| [in] | sa | 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".
| [in] | sa | 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
| [in] | socket | socket, if in blocking mode, pass "setnonblocking" arg as 1 |
| [in,out] | data | buffer for the read data |
| [in] | length | how many bytes to read |
| [in] | setnonblocking | when non-zero this func will enable and disable non blocking io mode for the socket |
| [in] | timeout | number of seconds to try reading, 0 means no timeout |
| int recv_fd | ( | int | fd, |
| int | nonblocking ) |
Receive a fd on a suitable socket.
| [in] | fd | PF_UNIX socket to receive on |
| [in] | nonblocking | 0: fd is in blocking mode - 1: fd is nonblocking, poll for 1 sec |
| int send_fd | ( | int | socket, |
| int | fd ) |
Send a fd across a suitable socket
| int setnonblock | ( | int | fd, |
| int | cmd ) |
set or unset non-blocking IO on a fd
| [in] | fd | File descriptor |
| [in] | cmd | 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.
| [in] | ipurl | IP URL string |
| [out] | address | IP address |
| [out] | port | 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
| [in] | socket | socket, if in blocking mode, pass "setnonblocking" arg as 1 |
| [in,out] | data | buffer for the read data |
| [in] | length | how many bytes to read |
| [in] | setnonblocking | when non-zero this func will enable and disable non blocking io mode for the socket |
| [in] | timeout | number of seconds to try reading |
|
static |