diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-09-04 12:37:50 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-09-04 13:05:58 +0200 |
commit | 4e0a46f65ea0188b9d361b59a4eff11d43f99444 (patch) | |
tree | b44fc78ff130650f8b052329e9e988178cf60935 /src/basic/socket-util.h | |
parent | test: add tests for in_addr_port_from_string_auto() (diff) | |
download | systemd-4e0a46f65ea0188b9d361b59a4eff11d43f99444.tar.xz systemd-4e0a46f65ea0188b9d361b59a4eff11d43f99444.zip |
util: introduce SOCKADDR_LEN() macro
Diffstat (limited to 'src/basic/socket-util.h')
-rw-r--r-- | src/basic/socket-util.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h index 9e02e39887..5610a99e53 100644 --- a/src/basic/socket-util.h +++ b/src/basic/socket-util.h @@ -205,6 +205,35 @@ struct cmsghdr* cmsg_find(struct msghdr *mh, int level, int type, socklen_t leng strnlen(_sa->sun_path, sizeof(_sa->sun_path))+1); \ }) +#define SOCKADDR_LEN(sa) \ + ({ \ + const union sockaddr_union *__sa = &(sa); \ + size_t _len; \ + switch(__sa->sa.sa_family) { \ + case AF_INET: \ + _len = sizeof(struct sockaddr_in); \ + break; \ + case AF_INET6: \ + _len = sizeof(struct sockaddr_in6); \ + break; \ + case AF_UNIX: \ + _len = SOCKADDR_UN_LEN(__sa->un); \ + break; \ + case AF_PACKET: \ + _len = SOCKADDR_LL_LEN(__sa->ll); \ + break; \ + case AF_NETLINK: \ + _len = sizeof(struct sockaddr_nl); \ + break; \ + case AF_VSOCK: \ + _len = sizeof(struct sockaddr_vm); \ + break; \ + default: \ + assert_not_reached("invalid socket family"); \ + } \ + _len; \ + }) + int socket_ioctl_fd(void); int sockaddr_un_set_path(struct sockaddr_un *ret, const char *path); |