[lldp-devel] [PATCH 1/3] lldptool add command to return PID of lldpad

Thomas Richter tmricht at linux.vnet.ibm.com
Thu Feb 21 15:38:42 UTC 2013


When lldpad is invoked with command line option -p, no
/var/run/lldpad.pid file is created. External tools which
need to know the pid of lldpad, need to connect to the
control interface of lldpad and send a ping command
to retrieve the pid.

This patch adds command line option -p to the lldptool to
display the pid of lldpad. The leading PPONG string is
stripped.
Example:
24112

Same behavior for interactive mode. Each ping command
returns the PID of lldpad.

Signed-off-by: Thomas Richter <tmricht at linux.vnet.ibm.com>
---
 lldptool.c      |    6 +++++-
 lldptool_cmds.c |    2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lldptool.c b/lldptool.c
index b80621d..512811f 100644
--- a/lldptool.c
+++ b/lldptool.c
@@ -157,6 +157,7 @@ static const char *commands_help =
 "  license                              show license information\n"
 "  -h|help                              show command usage information\n"
 "  -v|version                           show version\n"
+"  -p|ping                              ping lldpad and query pid of lldpad\n"
 "  -q|quit                              exit lldptool (interactive mode)\n"
 "  -S|stats                             get LLDP statistics for ifname\n"
 "  -t|get-tlv                           get TLVs from ifname\n"
@@ -478,7 +479,7 @@ static int request(struct clif *clif, int argc, char *argv[])
 
 	opterr = 0;
 	for (;;) {
-		c = getopt_long(argc, argv, "Si:tTlLhcdnvrRqV:g:",
+		c = getopt_long(argc, argv, "Si:tTlLhcdnvrRpqV:g:",
 				lldptool_opts, &option_index);
 		if (c < 0)
 			break;
@@ -531,6 +532,9 @@ static int request(struct clif *clif, int argc, char *argv[])
 				return -1;
 			}
 			break;
+		case 'p':
+			command.cmd = cmd_ping;
+			break;
 		case 'q':
 			command.cmd = cmd_quit;
 			break;
diff --git a/lldptool_cmds.c b/lldptool_cmds.c
index 27c88b9..17b4d8b 100644
--- a/lldptool_cmds.c
+++ b/lldptool_cmds.c
@@ -576,7 +576,7 @@ void print_response(char *buf, int status)
 		if (status)
 			printf("FAILED:%s\n", print_status(status));
 		else
-			printf("%s\n", buf+CLIF_RSP_OFF);
+			printf("%s\n", buf+CLIF_RSP_OFF+5);
 		break;
 	case ATTACH_CMD:
 	case DETACH_CMD:
-- 
1.7.1



More information about the lldp-devel mailing list