X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fbasic%2Fsocket-util.h;h=718de9ba347ff07a8fd2618fd10a08735ced4423;hp=c039f486908d4bd4b96088c2fbd196670bc43dac;hb=a683e1878913969ccf8b0defdec4d955e15ed75a;hpb=3b22396a4b2767a98172f6915929c47738cb0a1e diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h index c039f4869..718de9ba3 100644 --- a/src/basic/socket-util.h +++ b/src/basic/socket-util.h @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - #pragma once /*** @@ -21,9 +19,12 @@ along with systemd; If not, see . ***/ -#include -#include #include +#include +#include +#include +#include +#include #include #include #include @@ -41,8 +42,7 @@ union sockaddr_union { struct sockaddr_ll ll; }; -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind typedef struct SocketAddress { union sockaddr_union sockaddr; @@ -88,7 +88,7 @@ int socket_address_listen( mode_t directory_mode, mode_t socket_mode, const char *label); -int make_socket_fd(int log_level, const char* address, int flags); +int make_socket_fd(int log_level, const char* address, int type, int flags); bool socket_address_is(const SocketAddress *a, const char *s, int type); bool socket_address_is_netlink(const SocketAddress *a, const char *s); @@ -98,13 +98,15 @@ bool socket_address_matches_fd(const SocketAddress *a, int fd); bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) _pure_; const char* socket_address_get_path(const SocketAddress *a); +#endif // 0 bool socket_ipv6_is_supported(void); +#if 0 /// UNNEEDED by elogind int sockaddr_port(const struct sockaddr *_sa) _pure_; int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ipv6, bool include_port, char **ret); -int getpeername_pretty(int fd, char **ret); +int getpeername_pretty(int fd, bool include_port, char **ret); int getsockname_pretty(int fd, char **ret); int socknameinfo_pretty(union sockaddr_union *sa, socklen_t salen, char **_ret); @@ -117,8 +119,50 @@ int netlink_family_to_string_alloc(int b, char **s); int netlink_family_from_string(const char *s) _pure_; bool sockaddr_equal(const union sockaddr_union *a, const union sockaddr_union *b); +#endif // 0 + +int fd_inc_sndbuf(int fd, size_t n); +int fd_inc_rcvbuf(int fd, size_t n); +#if 0 /// UNNEEDED by elogind + +int ip_tos_to_string_alloc(int i, char **s); +int ip_tos_from_string(const char *s); +#endif // 0 + +bool ifname_valid(const char *p); + +int getpeercred(int fd, struct ucred *ucred); +int getpeersec(int fd, char **ret); + +int send_one_fd_sa(int transport_fd, + int fd, + const struct sockaddr *sa, socklen_t len, + int flags); +#define send_one_fd(transport_fd, fd, flags) send_one_fd_sa(transport_fd, fd, NULL, 0, flags) +#if 0 /// UNNEEDED by elogind +int receive_one_fd(int transport_fd, int flags); + +ssize_t next_datagram_size_fd(int fd); + +int flush_accept(int fd); +#endif // 0 + +#define CMSG_FOREACH(cmsg, mh) \ + for ((cmsg) = CMSG_FIRSTHDR(mh); (cmsg); (cmsg) = CMSG_NXTHDR((mh), (cmsg))) + +struct cmsghdr* cmsg_find(struct msghdr *mh, int level, int type, socklen_t length); -#define ETHER_ADDR_TO_STRING_MAX (3*6) +/* Covers only file system and abstract AF_UNIX socket addresses, but not unnamed socket addresses. */ +#define SOCKADDR_UN_LEN(sa) \ + ({ \ + const struct sockaddr_un *_sa = &(sa); \ + assert(_sa->sun_family == AF_UNIX); \ + offsetof(struct sockaddr_un, sun_path) + \ + (_sa->sun_path[0] == 0 ? \ + 1 + strnlen(_sa->sun_path+1, sizeof(_sa->sun_path)-1) : \ + strnlen(_sa->sun_path, sizeof(_sa->sun_path))); \ + }) -char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]); +#if 0 /// UNNEEDED by elogind +int socket_ioctl_fd(void); #endif // 0