From 4af143a85531a5635d441a201b259fbd45a23660 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 12 Mar 2013 10:35:45 +0100 Subject: econfind: Put clientinfo parsing into subfunction --- econfind.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/econfind.c b/econfind.c index fdda71e..0abde0f 100644 --- a/econfind.c +++ b/econfind.c @@ -27,6 +27,24 @@ #include "econproto.h" #include "econpacket.h" +static void +parse_clientinfo(struct econ_packet *pkt) +{ + struct in_addr beamer; + + beamer.s_addr = *(uint32_t*)pkt->hdr.IPaddress; + printf("%s", inet_ntoa(beamer)); + if (pkt->hdr.datasize > 0) { + char *name = pkt->cmd.command.clientinfo.projName; + int state = pkt->cmd.command.clientinfo.projState; + + name[ECON_PROJNAME_MAXLEN-1] = '\0'; + printf(" - %s: %s", name, + state == E_PSTAT_NOUSE ? "no use" : "in use"); + } + printf("\n"); +} + int main(int argc, char *argv[]) { @@ -54,21 +72,8 @@ main(int argc, char *argv[]) if (epkt_read(sfd, &pkt) < 0) exit(EXIT_FAILURE); - if (pkt.hdr.commandID == E_CMD_CLIENTINFO) { - struct in_addr beamer; - - beamer.s_addr = *(uint32_t*)pkt.hdr.IPaddress; - printf("%s", inet_ntoa(beamer)); - if (pkt.hdr.datasize > 0) { - char *name = pkt.cmd.command.clientinfo.projName; - int state = pkt.cmd.command.clientinfo.projState; - - name[ECON_PROJNAME_MAXLEN-1] = '\0'; - printf(" - %s: %s", name, - state == E_PSTAT_NOUSE ? "no use" : "in use"); - } - printf("\n"); - } + if (pkt.hdr.commandID == E_CMD_CLIENTINFO) + parse_clientinfo(&pkt); close(cfd); close(sfd); -- cgit