Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/compat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(COMPAT_HEADERS
compat/getent.h
compat/getent-sun.h
compat/getent-generic.h
compat/un.h
PARENT_SCOPE)

set(COMPAT_SOURCES
Expand Down
3 changes: 2 additions & 1 deletion lib/compat/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ compatinclude_HEADERS = \
lib/compat/pcre.h \
lib/compat/getent.h \
lib/compat/getent-sun.h \
lib/compat/getent-generic.h
lib/compat/getent-generic.h \
lib/compat/un.h

compat_sources = \
lib/compat/getutent.c \
Expand Down
37 changes: 37 additions & 0 deletions lib/compat/un.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2002-2018 Balabit
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#ifndef COMPAT_UN_H_INCLUDED
#define COMPAT_UN_H_INCLUDED 1

#include <sys/un.h>

/*
SUN_LEN is not a POSIX standard, thus not available on all platforms.
If it is available we should rely on it. Otherwise we use the formula
from the Linux man page.
*/
#ifndef SUN_LEN
#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen ((ptr)->sun_path))
#endif

#endif
2 changes: 1 addition & 1 deletion lib/gsockaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ g_sockaddr_unix_new(const gchar *name)
{
strncpy(addr->saun.sun_path, name, sizeof(addr->saun.sun_path) - 1);
addr->saun.sun_path[sizeof(addr->saun.sun_path) - 1] = 0;
addr->salen = sizeof(addr->saun) - sizeof(addr->saun.sun_path) + strlen(addr->saun.sun_path) + 1;
addr->salen = SUN_LEN(&(addr->saun));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion lib/gsockaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <compat/un.h>
#include <netinet/in.h>

/* sockaddr public interface */
Expand Down