static int start_lldp(sd_lldp **lldp, sd_event *e, sd_lldp_callback_t cb, void *cb_data) { int r; r = sd_lldp_new(lldp); if (r < 0) return r; r = sd_lldp_set_ifindex(*lldp, 42); if (r < 0) return r; r = sd_lldp_set_callback(*lldp, cb, cb_data); if (r < 0) return r; r = sd_lldp_attach_event(*lldp, e, 0); if (r < 0) return r; r = sd_lldp_start(*lldp); if (r < 0) return r; return 0; }
static int start_lldp(sd_lldp **lldp, sd_event *e, sd_lldp_cb_t cb, void *cb_data) { int r; r = sd_lldp_new(42, "dummy", &mac_addr, lldp); if (r) return r; r = sd_lldp_attach_event(*lldp, e, 0); if (r) return r; r = sd_lldp_set_callback(*lldp, cb, cb_data); if (r) return r; r = sd_lldp_start(*lldp); if (r) return r; return 0; }
gboolean nm_lldp_listener_start (NMLldpListener *self, int ifindex, const char *iface, const guint8 *mac, guint mac_len, GError **error) { NMLldpListenerPrivate *priv; int ret; g_return_val_if_fail (NM_IS_LLDP_LISTENER (self), FALSE); g_return_val_if_fail (ifindex > 0, FALSE); g_return_val_if_fail (iface, FALSE); g_return_val_if_fail (!error || !*error, FALSE); priv = NM_LLDP_LISTENER_GET_PRIVATE (self); if (priv->lldp_handle) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "already running"); return FALSE; } if (!mac || mac_len != ETH_ALEN) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "unsupported device"); return FALSE; } ret = sd_lldp_new (ifindex, iface, (struct ether_addr *) mac, &priv->lldp_handle); if (ret) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "initialization failed"); return FALSE; } ret = sd_lldp_attach_event (priv->lldp_handle, NULL, 0); if (ret) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "attach event failed"); goto err_free; } ret = sd_lldp_set_callback (priv->lldp_handle, lldp_event_handler, self); if (ret) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "set callback failed"); goto err; } ret = sd_lldp_start (priv->lldp_handle); if (ret) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "start failed"); goto err; } priv->ifindex = ifindex; priv->iface = strdup (iface); return TRUE; err: sd_lldp_detach_event (priv->lldp_handle); err_free: sd_lldp_unref (priv->lldp_handle); priv->lldp_handle = NULL; return FALSE; }