On Thursday 2012-04-19 12:33, Michael Kerrisk (man-pages) wrote:
Anyway, I've dug deeper, looking at hat happens on other platforms.
It's a mess: the BSDs don't even guarantee that sun_path is
null_terminated. So, here's how one has to portably deal with the
variations:
addrlen = sizeof(struct sockaddr_un);
cfd = accept(lfd, &addr, &addlen);
printf("%.*s", addrlen - offsetof(struct sockaddr_un, sun_path), addr.sun_path);
What operating system made you write that?
I just ask for fun and the record. Solaris's dirent is also
constructed such that using sizeof(...) is useless.
typedef struct dirent {
ino_t d_ino; /* "inode number" of entry */
off_t d_off; /* offset of disk directory entry */
unsigned short d_reclen; /* length of this record */
char d_name[1]; /* name of file */
} dirent_t;