5 #include <sys/socket.h>
6 #include <netinet/in.h>
7 #include <netinet/ip.h>
12 main (int argc
, char **argv
)
15 struct sockaddr_in sa
;
19 fd
= socket (AF_INET
, SOCK_DGRAM
, 0);
26 sa
.sin_family
= AF_INET
;
27 sa
.sin_addr
.s_addr
= htonl (INADDR_LOOPBACK
);
28 sa
.sin_port
= htons (PORT
);
29 if (connect (fd
, (struct sockaddr
*) &sa
, sizeof (sa
)) == -1)
31 perror ("connect ()");
35 // Create msg_hdr. Oops, we forget to set msg_name...
37 iov
[0].iov_base
= "one";
39 iov
[1].iov_base
= "two";
41 msg
.msg_iov
= &iov
[0];
43 msg
.msg_control
= NULL
;
44 msg
.msg_controllen
= 0;
46 size_t s
= sendmsg (fd
, &msg
, 0);
48 // Note how we now do set msg_name, but don't set msg_flags.
49 // The msg_flags field is ignored by sendmsg.
52 fd
= socket (AF_INET
, SOCK_DGRAM
, 0);
59 if (connect (fd
, (struct sockaddr
*) &sa
, sizeof (sa
)) == -1)
61 perror ("connect ()");
65 s
= sendmsg (fd
, &msg
, 0);
68 perror ("sendmsg ()");
72 fprintf (stderr
, "sendmsg: %d\n", (int) s
);