Logo Search packages:      
Sourcecode: libnl2 version File versions  Download package

void nl_msg_dump ( struct nl_msg *  msg,
FILE *  ofd 
)

Dump message in human readable format to file descriptor

  • msg Message to print
  • ofd File descriptor.

Definition at line 965 of file msg.c.

References nl_cache_ops::co_hdrsize, nlmsgerr::error, nlmsgerr::msg, nl_cache_ops_associate(), nlmsg_attrdata(), nlmsg_attrlen(), nlmsg_data(), nlmsg_free(), nlmsg_hdr(), nlmsg_inherit(), nlmsg_len(), nlmsghdr::nlmsg_len, nlmsg_msg_size(), and nlmsghdr::nlmsg_type.

{
      struct nlmsghdr *hdr = nlmsg_hdr(msg);
      
      fprintf(ofd, 
      "--------------------------   BEGIN NETLINK MESSAGE "
      "---------------------------\n");

      fprintf(ofd, "  [HEADER] %Zu octets\n", sizeof(struct nlmsghdr));
      print_hdr(ofd, msg);

      if (hdr->nlmsg_type == NLMSG_ERROR &&
          hdr->nlmsg_len >= nlmsg_msg_size(sizeof(struct nlmsgerr))) {
            struct nl_msg *errmsg;
            struct nlmsgerr *err = nlmsg_data(hdr);

            fprintf(ofd, "  [ERRORMSG] %Zu octets\n", sizeof(*err));
            fprintf(ofd, "    .error = %d \"%s\"\n", err->error,
                  strerror(-err->error));
            fprintf(ofd, "  [ORIGINAL MESSAGE] %Zu octets\n", sizeof(*hdr));

            errmsg = nlmsg_inherit(&err->msg);
            print_hdr(ofd, errmsg);
            nlmsg_free(errmsg);
      } else if (nlmsg_len(hdr) > 0) {
            struct nl_cache_ops *ops;
            int payloadlen = nlmsg_len(hdr);
            int attrlen = 0;

            ops = nl_cache_ops_associate(nlmsg_get_proto(msg),
                                   hdr->nlmsg_type);
            if (ops) {
                  attrlen = nlmsg_attrlen(hdr, ops->co_hdrsize);
                  payloadlen -= attrlen;
            }

            fprintf(ofd, "  [PAYLOAD] %d octets\n", payloadlen);
            dump_hex(ofd, nlmsg_data(hdr), payloadlen, 0);

            if (attrlen) {
                  struct nlattr *attrs;
                  int attrlen;
                  
                  attrs = nlmsg_attrdata(hdr, ops->co_hdrsize);
                  attrlen = nlmsg_attrlen(hdr, ops->co_hdrsize);
                  dump_attrs(ofd, attrs, attrlen, 0);
            }
      }

      fprintf(ofd, 
      "---------------------------  END NETLINK MESSAGE   "
      "---------------------------\n");
}


Generated by  Doxygen 1.6.0   Back to index