socket-util: Move getsockopt_int() to implementation file
And switch back to negative_errno() at the same time.
This commit is contained in:
+17
-1
@@ -1529,6 +1529,22 @@ int sockaddr_un_set_path(struct sockaddr_un *ret, const char *path) {
|
||||
}
|
||||
}
|
||||
|
||||
int getsockopt_int(int fd, int level, int optname, int *ret) {
|
||||
int v;
|
||||
socklen_t sl = sizeof(v);
|
||||
|
||||
assert(fd >= 0);
|
||||
assert(ret);
|
||||
|
||||
if (getsockopt(fd, level, optname, &v, &sl) < 0)
|
||||
return negative_errno();
|
||||
if (sl != sizeof(v))
|
||||
return -EIO;
|
||||
|
||||
*ret = v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int socket_bind_to_ifname(int fd, const char *ifname) {
|
||||
assert(fd >= 0);
|
||||
|
||||
@@ -1684,7 +1700,7 @@ int socket_set_option(int fd, int af, int opt_ipv4, int opt_ipv6, int val) {
|
||||
}
|
||||
|
||||
int socket_get_mtu(int fd, int af, size_t *ret) {
|
||||
int mtu = 0, r; /* Avoid maybe-uninitialized false positive */
|
||||
int mtu, r;
|
||||
|
||||
if (af == AF_UNSPEC) {
|
||||
af = socket_get_family(fd);
|
||||
|
||||
+1
-12
@@ -248,18 +248,7 @@ static inline int setsockopt_int(int fd, int level, int optname, int value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int getsockopt_int(int fd, int level, int optname, int *ret) {
|
||||
int v;
|
||||
socklen_t sl = sizeof(v);
|
||||
|
||||
if (getsockopt(fd, level, optname, &v, &sl) < 0)
|
||||
return -errno;
|
||||
if (sl != sizeof(v))
|
||||
return -EIO;
|
||||
|
||||
*ret = v;
|
||||
return 0;
|
||||
}
|
||||
int getsockopt_int(int fd, int level, int optname, int *ret);
|
||||
|
||||
int socket_bind_to_ifname(int fd, const char *ifname);
|
||||
int socket_bind_to_ifindex(int fd, int ifindex);
|
||||
|
||||
Reference in New Issue
Block a user