From 8fc71d5ac89bce74b771c6aa275541a722db275f Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 27 Sep 2017 23:30:30 +0100 Subject: [PATCH] pkstream/pkstream.c: Set a flag if we're listening. Rather than having to check the address. This means that we don't need to initialize `cw.me' if we /aren't/ listening, so don't. --- pkstream/pkstream.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkstream/pkstream.c b/pkstream/pkstream.c index f1ddf779..b291a1c7 100644 --- a/pkstream/pkstream.c +++ b/pkstream/pkstream.c @@ -73,6 +73,8 @@ typedef struct pkstream { } pkstream; typedef struct connwait { + unsigned f; /* Various flags */ +#define cwf_port 1u /* Port is defined => listen */ sel_file a; /* Selector */ struct sockaddr_in me, peer; /* Who I'm meant to be; who peer is */ } connwait; @@ -115,7 +117,7 @@ static void doclose(pkstream *p) xfree(pk); } xfree(p); - if (cw.me.sin_port) dolisten(); + if (cw.f&cwf_port) dolisten(); else exit(0); } @@ -337,6 +339,8 @@ int main(int argc, char *argv[]) #define f_bogus 1u + cw.f = 0; + ego(argv[0]); sel_init(&sel); for (;;) { @@ -375,11 +379,14 @@ int main(int argc, char *argv[]) if (bindsvc && connhost) die(1, "can't listen and connect"); - initaddr(&cw.me); if (bindhost || bindsvc) { initaddr(&bindaddr); if (!bindsvc) parseaddr(bindhost, 0, 0, &bindaddr); - else parseaddr(bindhost, bindsvc, 0, &cw.me); + else { + initaddr(&cw.me); + parseaddr(bindhost, bindsvc, 0, &cw.me); + cw.f |= cwf_port; + } } initaddr(&cw.peer); -- 2.11.0