Discussion:
[Xcb] Questions about XCB using domain sockets.
xc haze
2018-02-26 08:13:49 UTC
Permalink
Hi:
When I look at XCB communication
static int _xcb_open_abstract(char *protocol, const char *file, size_t
filelen)
{
int fd;
struct sockaddr_un addr = {0};
socklen_t namelen;

if (protocol && strcmp("unix",protocol))
return -1;

strcpy(addr.sun_path + 1, file);
addr.sun_family = AF_UNIX;
namelen = offsetof(struct sockaddr_un, sun_path) + 1 + filelen;
。。。。。。

Why do we add one to addr->sun_path?
Alan Coopersmith
2018-02-26 18:07:08 UTC
Permalink
When I look at XCB communication,
static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen)
{
    int fd;
    struct sockaddr_un addr = {0};
    socklen_t namelen;
    if (protocol && strcmp("unix",protocol))
        return -1;
    strcpy(addr.sun_path + 1, file);
    addr.sun_family = AF_UNIX;
    namelen = offsetof(struct sockaddr_un, sun_path) + 1 + filelen;
   。。。。。。

Why do we add one to addr->sun_path?
Because abstract sockets have the name field start with a byte of 0,
then the actual name, to distinguish them from filesystem pathnames.

See "Address format" in http://man7.org/linux/man-pages/man7/unix.7.html
--
-Alan Coopersmith- ***@oracle.com
Oracle Solaris Engineering - https://blogs.oracle.com/alanc
Loading...