Lines Matching refs:nlg
32 static struct nlmsghdr *__mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd, in __mnlg_msg_prepare() argument
39 nlh = mnl_nlmsg_put_header(nlg->buf); in __mnlg_msg_prepare()
42 nlg->seq = time(NULL); in __mnlg_msg_prepare()
43 nlh->nlmsg_seq = nlg->seq; in __mnlg_msg_prepare()
52 struct nlmsghdr *mnlg_msg_prepare(struct mnlg_socket *nlg, uint8_t cmd, in mnlg_msg_prepare() argument
55 return __mnlg_msg_prepare(nlg, cmd, flags, nlg->id, nlg->version); in mnlg_msg_prepare()
58 int mnlg_socket_send(struct mnlg_socket *nlg, const struct nlmsghdr *nlh) in mnlg_socket_send() argument
60 return mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len); in mnlg_socket_send()
63 int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data) in mnlg_socket_recv_run() argument
68 err = mnl_socket_recvfrom(nlg->nl, nlg->buf, in mnlg_socket_recv_run()
72 err = mnl_cb_run(nlg->buf, err, nlg->seq, nlg->portid, in mnlg_socket_recv_run()
158 int mnlg_socket_group_add(struct mnlg_socket *nlg, const char *group_name) in mnlg_socket_group_add() argument
164 nlh = __mnlg_msg_prepare(nlg, CTRL_CMD_GETFAMILY, in mnlg_socket_group_add()
166 mnl_attr_put_u32(nlh, CTRL_ATTR_FAMILY_ID, nlg->id); in mnlg_socket_group_add()
168 err = mnlg_socket_send(nlg, nlh); in mnlg_socket_group_add()
174 err = mnlg_socket_recv_run(nlg, get_group_id_cb, &group_info); in mnlg_socket_group_add()
183 err = mnl_socket_setsockopt(nlg->nl, NETLINK_ADD_MEMBERSHIP, in mnlg_socket_group_add()
221 struct mnlg_socket *nlg; in mnlg_socket_open() local
225 nlg = malloc(sizeof(*nlg)); in mnlg_socket_open()
226 if (!nlg) in mnlg_socket_open()
229 nlg->buf = malloc(MNL_SOCKET_BUFFER_SIZE); in mnlg_socket_open()
230 if (!nlg->buf) in mnlg_socket_open()
233 nlg->nl = mnl_socket_open(NETLINK_GENERIC); in mnlg_socket_open()
234 if (!nlg->nl) in mnlg_socket_open()
237 err = mnl_socket_bind(nlg->nl, 0, MNL_SOCKET_AUTOPID); in mnlg_socket_open()
241 nlg->portid = mnl_socket_get_portid(nlg->nl); in mnlg_socket_open()
243 nlh = __mnlg_msg_prepare(nlg, CTRL_CMD_GETFAMILY, in mnlg_socket_open()
247 err = mnlg_socket_send(nlg, nlh); in mnlg_socket_open()
251 err = mnlg_socket_recv_run(nlg, get_family_id_cb, &nlg->id); in mnlg_socket_open()
255 nlg->version = version; in mnlg_socket_open()
256 return nlg; in mnlg_socket_open()
261 mnl_socket_close(nlg->nl); in mnlg_socket_open()
263 free(nlg->buf); in mnlg_socket_open()
265 free(nlg); in mnlg_socket_open()
269 void mnlg_socket_close(struct mnlg_socket *nlg) in mnlg_socket_close() argument
271 mnl_socket_close(nlg->nl); in mnlg_socket_close()
272 free(nlg->buf); in mnlg_socket_close()
273 free(nlg); in mnlg_socket_close()