sbin_PROGRAMS = lldpd lldpctl
-noinst_LTLIBRARIES = liblldpd.la
+noinst_LTLIBRARIES = liblldpd.la libcommon.la
-COMMON = log.c ctl.c lldpd.h lldp.h cdp.h compat.h sonmp.h edp.h
-liblldpd_la_SOURCES = frame.h frame.c lldpd.c lldp.c cdp.c sonmp.c edp.c interfaces.c client.c priv.c privsep_fdpass.c dmi.c $(COMMON)
-lldpctl_SOURCES = lldpctl.c $(COMMON)
+## Shared by all executables
+libcommon_la_SOURCES = log.c ctl.c lldpd.h lldp.h cdp.h compat.h sonmp.h edp.h
+libcommon_la_LIBADD = @LTLIBOBJS@
-liblldpd_la_LIBADD = @LTLIBOBJS@
-lldpctl_LDADD = @LIBOBJS@
-lldpctl_CFLAGS = -DCLIENT_ONLY
+## Used for lldpd and tests
+liblldpd_la_SOURCES = frame.h frame.c lldpd.c lldp.c cdp.c sonmp.c edp.c \
+ interfaces.c client.c priv.c privsep_fdpass.c dmi.c ctl-server.c
+liblldpd_la_LIBADD = libcommon.la
+## lldpd
lldpd_SOURCES = main.c
lldpd_LDADD = liblldpd.la
+## lldpctl
+lldpctl_SOURCES = lldpctl.c
+lldpctl_LDADD = libcommon.la
+
+## With SNMP...
if USE_SNMP
liblldpd_la_SOURCES += agent.c agent_priv.c
lldpd_LDADD += @NETSNMP_LIB@
endif
-
--- /dev/null
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+static void
+ctl_callback(struct lldpd *cfg, struct lldpd_callback *callback)
+{
+ char *buffer;
+ int n;
+
+ if ((buffer = (char *)malloc(MAX_HMSGSIZE)) ==
+ NULL) {
+ LLOG_WARN("failed to alloc reception buffer");
+ return;
+ }
+ if ((n = recv(callback->fd, buffer,
+ MAX_HMSGSIZE, 0)) == -1) {
+ LLOG_WARN("error while receiving message");
+ free(buffer);
+ return;
+ }
+ if (n > 0)
+ client_handle_client(cfg, callback, buffer, n);
+ else {
+ close(callback->fd);
+ lldpd_callback_del(cfg, callback->fd, ctl_callback);
+ }
+ free(buffer);
+}
+
+void
+ctl_accept(struct lldpd *cfg, struct lldpd_callback *callback)
+{
+ int s;
+ if ((s = accept(callback->fd, NULL, NULL)) == -1) {
+ LLOG_WARN("unable to accept connection from socket");
+ return;
+ }
+ if (lldpd_callback_add(cfg, s, ctl_callback, NULL) != 0) {
+ LLOG_WARN("unable to add callback for new client");
+ close(s);
+ }
+ return;
+}
return s;
}
-#ifndef CLIENT_ONLY
-static void
-ctl_callback(struct lldpd *cfg, struct lldpd_callback *callback)
-{
- char *buffer;
- int n;
-
- if ((buffer = (char *)malloc(MAX_HMSGSIZE)) ==
- NULL) {
- LLOG_WARN("failed to alloc reception buffer");
- return;
- }
- if ((n = recv(callback->fd, buffer,
- MAX_HMSGSIZE, 0)) == -1) {
- LLOG_WARN("error while receiving message");
- free(buffer);
- return;
- }
- if (n > 0)
- client_handle_client(cfg, callback, buffer, n);
- else {
- close(callback->fd);
- lldpd_callback_del(cfg, callback->fd, ctl_callback);
- }
- free(buffer);
-}
-
-void
-ctl_accept(struct lldpd *cfg, struct lldpd_callback *callback)
-{
- int s;
- if ((s = accept(callback->fd, NULL, NULL)) == -1) {
- LLOG_WARN("unable to accept connection from socket");
- return;
- }
- if (lldpd_callback_add(cfg, s, ctl_callback, NULL) != 0) {
- LLOG_WARN("unable to add callback for new client");
- close(s);
- }
- return;
-}
-#endif
-
void
ctl_msg_init(struct hmsg *t, enum hmsg_type type)
{
int ctl_create(char *);
int ctl_connect(char *);
void ctl_cleanup(char *);
-#ifndef CLIENT_ONLY
void ctl_accept(struct lldpd *, struct lldpd_callback *);
-#endif
void ctl_msg_init(struct hmsg *, enum hmsg_type);
int ctl_msg_send(int, struct hmsg *);
int ctl_msg_recv(int, struct hmsg *);