Mario
Mario

Reputation: 1028

sys/socket missing member for msgdr: msg_control, msg_controllen, msg_flags

I'm trying to write a little Client-Server application using the UNIX DOMAIN SOCKETS.

I'm using the msghdr for the sendmsg/recvmsg but when I compile the following code, it gives me the following error:

include <sys/socket.h>
...
struct msghdr mh;
struct cmsghdr *cmp;
union{
    struct cmsghdr cm;
    char ctrl[sizeof(struct cmsghdr) + sizeof(int)];
} ctrlu;
...
mh.msg_name = NULL;
mh.msg_namelen = 0;
mh.msg_iov = iov;
mh.msg_iovlen = 1;
mh.msg_control = ctrlu.ctrl;
mh.msg_controllen = sizeof(ctrlu);
mh.msg_flags = 0;

Error message:

gcc s.c -o s -lsocket

s.c: In function `main':

s.c:59: error: structure has no member named `msg_control'

s.c:60: error: structure has no member named `msg_controllen'

s.c:61: error: structure has no member named `msg_flags'

* Error code 1

Upvotes: 0

Views: 1226

Answers (2)

Tanz87
Tanz87

Reputation: 1294

I've encountered this issue (i.e. msg_flags not being a member of the msghdr structure) when trying to compile the C++ project Boost.Asio on Solaris 11.3 using the default compiler settings of the IDE in Oracle Developer Studio 12.6. Boost.Asio's build system seems to work around the problem by providing these options to the compiler:

-D_XOPEN_SOURCE=500 -D__EXTENSIONS__

and these to the linker:

-lsocket -lnsl

My problem was solved after I added these settings to my project in the IDE.

I'm not sure exactly how it worked, but it may have something to do with the Oracle documentation saying that msg_flags, msg_control and msg_controllen are available only in the "libxnet interface" and not the "libsocket interface".

Also notable how the Samba project dealt with this: https://bugzilla.samba.org/show_bug.cgi?id=11053 (they #define-ed _XPG4_2 and __EXTENSIONS__).

Upvotes: 0

Yu Hao
Yu Hao

Reputation: 122403

This seems a bug in Solaris, it works fine in Linux. (You didn't specify the OS exactly, but I saw you used -lsocket compiler option, which is not necessary in Linux)

Upvotes: 1

Related Questions