libredirect: add 'connect' for AF_UNIX
This commit is contained in:
@@ -130,6 +130,25 @@ WRAPPER(int, bind)(int socket, const struct sockaddr *addr, socklen_t addr_len)
|
||||
}
|
||||
WRAPPER_DEF(bind)
|
||||
|
||||
WRAPPER(int, connect)(int socket, const struct sockaddr *addr, socklen_t addr_len)
|
||||
{
|
||||
int (*connect_real) (int, const struct sockaddr *, socklen_t) = LOOKUP_REAL(connect);
|
||||
char buf[PATH_MAX];
|
||||
const struct sockaddr *real_addr = addr;
|
||||
if (addr->sa_family == AF_UNIX) {
|
||||
struct sockaddr_un real_addr_un = *(struct sockaddr_un *)addr;
|
||||
const char *sun_path = rewrite(real_addr_un.sun_path, buf);
|
||||
if (sun_path != real_addr_un.sun_path) {
|
||||
strncpy(real_addr_un.sun_path, buf, sizeof(real_addr_un.sun_path) - 1);
|
||||
real_addr_un.sun_path[sizeof(real_addr_un.sun_path) - 1] = '\0';
|
||||
real_addr = (struct sockaddr *)&real_addr_un;
|
||||
addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(real_addr_un.sun_path) + 1;
|
||||
}
|
||||
}
|
||||
return connect_real(socket, real_addr, addr_len);
|
||||
}
|
||||
WRAPPER_DEF(connect)
|
||||
|
||||
WRAPPER(int, open)(const char * path, int flags, ...)
|
||||
{
|
||||
int (*open_real) (const char *, int, ...) = LOOKUP_REAL(open);
|
||||
|
||||
Reference in New Issue
Block a user