1

I have some code snippet where I send then receive message through API.

 //...
 struct msghdr msg = {0};
 //...
 // some other structures initialization

 msg.msg_name = &sa;
 msg.msg_namelen = sizeof sa; 
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;

 fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
 if(fd < 0) {
      perror("SOCKET");
      return -1; 
 }   

 if(sendmsg(fd, &msg, 0) < 0) {
      perror("SENDMSG");
      return -1; 
 }   

 iov.iov_base = buf;
 iov.iov_len = sizeof buf;

 /* Should I do this? 
 msg.msg_name = &sa;
 msg.msg_namelen = sizeof sa;
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 */

 int len = recvmsg(fd, &msg, 0);

So the question is, should I re-initialize msg members? Or it is guaranteed from a perspective of API that sendmsg() will not spoil these fields? Unfortunately I didn't find any confirmation or denial.
Sorry if obvious.

z0lupka
  • 236
  • 4
  • 19

0 Answers0