1 #include <netinet/ip.h>
6 #include <sys/socket.h>
11 main (int argc
, char **argv
)
14 struct sockaddr_in sa
;
18 fd
= socket (AF_INET
, SOCK_DGRAM
, 0);
25 sa
.sin_family
= AF_INET
;
26 sa
.sin_addr
.s_addr
= htonl (INADDR_LOOPBACK
);
27 sa
.sin_port
= htons (PORT
);
28 if (connect (fd
, (struct sockaddr
*) &sa
, sizeof (sa
)) == -1)
30 perror ("connect ()");
34 // Create msg_hdr. Oops, we forget to set msg_name...
36 iov
[0].iov_base
= "one";
38 iov
[1].iov_base
= "two";
40 msg
.msg_iov
= &iov
[0];
42 msg
.msg_control
= NULL
;
43 msg
.msg_controllen
= 0;
45 size_t s
= sendmsg (fd
, &msg
, 0);
47 // Note how we now do set msg_name, but don't set msg_flags.
48 // The msg_flags field is ignored by sendmsg.
51 fd
= socket (AF_INET
, SOCK_DGRAM
, 0);
58 if (connect (fd
, (struct sockaddr
*) &sa
, sizeof (sa
)) == -1)
60 perror ("connect ()");
64 s
= sendmsg (fd
, &msg
, 0);
67 perror ("sendmsg ()");
71 fprintf (stderr
, "sendmsg: %d\n", (int) s
);