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

int nl_connect ( struct nl_sock *  sk,
int  protocol 
)

Create and connect netlink socket.

  • sk Netlink socket.
  • 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 106 of file nl.c.

References nl_socket_set_buffer_size().

Referenced by nfnl_connect(), and nl_cache_mngr_alloc().

{
      int err;
      socklen_t addrlen;

      sk->s_fd = socket(AF_NETLINK, SOCK_RAW, protocol);
      if (sk->s_fd < 0) {
            err = -nl_syserr2nlerr(errno);
            goto errout;
      }

      if (!(sk->s_flags & NL_SOCK_BUFSIZE_SET)) {
            err = nl_socket_set_buffer_size(sk, 0, 0);
            if (err < 0)
                  goto errout;
      }

      err = bind(sk->s_fd, (struct sockaddr*) &sk->s_local,
               sizeof(sk->s_local));
      if (err < 0) {
            err = -nl_syserr2nlerr(errno);
            goto errout;
      }

      addrlen = sizeof(sk->s_local);
      err = getsockname(sk->s_fd, (struct sockaddr *) &sk->s_local,
                    &addrlen);
      if (err < 0) {
            err = -nl_syserr2nlerr(errno);
            goto errout;
      }

      if (addrlen != sizeof(sk->s_local)) {
            err = -NLE_NOADDR;
            goto errout;
      }

      if (sk->s_local.nl_family != AF_NETLINK) {
            err = -NLE_AF_NOSUPPORT;
            goto errout;
      }

      sk->s_proto = protocol;

      return 0;
errout:
      close(sk->s_fd);
      sk->s_fd = -1;

      return err;
}


Generated by  Doxygen 1.6.0   Back to index