/* Connect to the remote end */
static int
-sync_connect()
+sync_connect(lldpctl_conn_t *lldpctl)
{
- return ctl_connect(LLDPD_CTL_SOCKET);
+ return ctl_connect(lldpctl->ctlname);
}
/* Synchronously send data to remote end. */
size_t nb;
if (conn->fd == -1 &&
- ((conn->fd = sync_connect()) == -1)) {
+ ((conn->fd = sync_connect(lldpctl)) == -1)) {
return LLDPCTL_ERR_CANNOT_CONNECT;
}
size_t nb;
if (conn->fd == -1 &&
- ((conn->fd = sync_connect()) == -1)) {
+ ((conn->fd = sync_connect(lldpctl)) == -1)) {
lldpctl->error = LLDPCTL_ERR_CANNOT_CONNECT;
return LLDPCTL_ERR_CANNOT_CONNECT;
}
}
-
lldpctl_conn_t*
lldpctl_new(lldpctl_send_callback send, lldpctl_recv_callback recv, void *user_data)
+{
+ return lldpctl_new_name(lldpctl_get_default_transport(), send, recv, user_data);
+}
+
+lldpctl_conn_t*
+lldpctl_new_name(const char *ctlname, lldpctl_send_callback send, lldpctl_recv_callback recv, void *user_data)
{
lldpctl_conn_t *conn = NULL;
struct lldpctl_conn_sync_t *data = NULL;
if ((conn = calloc(1, sizeof(lldpctl_conn_t))) == NULL)
return NULL;
+ conn->ctlname = strdup(ctlname);
+ if (conn->ctlname == NULL) {
+ free(conn);
+ return NULL;
+ }
if (!send && !recv) {
if ((data = malloc(sizeof(struct lldpctl_conn_sync_t))) == NULL) {
free(conn);
lldpctl_release(lldpctl_conn_t *conn)
{
if (conn == NULL) return 0;
+ free(conn->ctlname);
if (conn->send == sync_send) {
struct lldpctl_conn_sync_t *data = conn->user_data;
if (data->fd != -1) close(data->fd);