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

int nl_connect ( struct nl_handle *  handle,
int  protocol 
)

Create and connect netlink socket.

  • handle Netlink handle.
  • protocol Netlink protocol to use.
Creates a netlink socket using the specified protocol, binds the socket and issues a connection attempt.

Returns:
0 on success or a negative error code.

Definition at line 373 of file nl.c.

References nl_set_buffer_size().

{
      int err;
      socklen_t addrlen;

      handle->h_fd = socket(AF_NETLINK, SOCK_RAW, protocol);
      if (handle->h_fd < 0)
            return nl_error(1, "socket(AF_NETLINK, ...) failed");

      if (!(handle->h_flags & NL_SOCK_BUFSIZE_SET)) {
            err = nl_set_buffer_size(handle, 0, 0);
            if (err < 0)
                  return err;
      }

      err = bind(handle->h_fd, (struct sockaddr*) &handle->h_local,
               sizeof(handle->h_local));
      if (err < 0)
            return nl_error(1, "bind() failed");

      addrlen = sizeof(handle->h_local);
      err = getsockname(handle->h_fd, (struct sockaddr *) &handle->h_local,
                    &addrlen);
      if (err < 0)
            return nl_error(1, "getsockname failed");

      if (addrlen != sizeof(handle->h_local))
            return nl_error(EADDRNOTAVAIL, "Invalid address length");

      if (handle->h_local.nl_family != AF_NETLINK)
            return nl_error(EPFNOSUPPORT, "Address format not supported");

      handle->h_proto = protocol;

      return 0;
}


Generated by  Doxygen 1.6.0   Back to index