stun

simple point to point tunnel
git clone git://git.2f30.org/stun.git
Log | Files | Refs | README

commit 6909ec1c5e64a4e09507bcc77cabb3c50222f269
parent 89ff82a312ad917e7405e1684b0c030c0ff4dc96
Author: sin <sin@2f30.org>
Date:   Sat Apr 30 18:30:43 +0100

Rename state to rxstate along with associated enum

Diffstat:
netpkt.c | 50+++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/netpkt.c b/netpkt.c @@ -11,13 +11,13 @@ /* the various states the input handler can be in */ enum { - INPUTINITIAL, - INPUTNONCE, - INPUTHDR, - INPUTPAYLOAD, - INPUTTAG, - INPUTDECRYPT, - INPUTDISCARD + RXINITIAL, + RXNONCE, + RXHDR, + RXPAYLOAD, + RXTAG, + RXDECRYPT, + RXDISCARD }; /* output buffer for writing data to the network */ @@ -39,7 +39,7 @@ static size_t noncelen; static size_t taglen; /* state tracking for input handling */ -static int state; +static int rxstate; int netwrite(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) @@ -91,23 +91,23 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) } for (;;) { - switch (state) { - case INPUTINITIAL: + switch (rxstate) { + case RXINITIAL: rbuftotal = 0; rbufrem = noncelen; - state = INPUTNONCE; + rxstate = RXNONCE; break; - case INPUTNONCE: + case RXNONCE: if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) goto out; rbuftotal += n; rbufrem -= n; if (rbufrem == 0) { rbufrem = HDRLEN; - state = INPUTHDR; + rxstate = RXHDR; } break; - case INPUTHDR: + case RXHDR: if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) goto out; rbuftotal += n; @@ -115,33 +115,33 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) if (rbufrem == 0) { ctlen = unpack16(&rbuf[noncelen]); if (ctlen > ptlen) { - state = INPUTDISCARD; + rxstate = RXDISCARD; } else { rbufrem = ctlen; - state = INPUTPAYLOAD; + rxstate = RXPAYLOAD; } } break; - case INPUTPAYLOAD: + case RXPAYLOAD: if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) goto out; rbuftotal += n; rbufrem -= n; if (rbufrem == 0) { rbufrem = taglen; - state = INPUTTAG; + rxstate = RXTAG; } break; - case INPUTTAG: + case RXTAG: if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) goto out; rbuftotal += n; rbufrem -= n; if (rbufrem == 0) - state = INPUTDECRYPT; + rxstate = RXDECRYPT; break; - case INPUTDECRYPT: - state = INPUTINITIAL; + case RXDECRYPT: + rxstate = RXINITIAL; if (!cryptoopen(pt, outlen, ptlen, rbuf, noncelen, &rbuf[noncelen + HDRLEN], rbuftotal - noncelen - HDRLEN, @@ -150,8 +150,8 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) return PKTPARTIAL; } return PKTCOMPLETE; - case INPUTDISCARD: - state = INPUTINITIAL; + case RXDISCARD: + rxstate = RXINITIAL; for (;;) if ((n = read(fd, rbuf, maxbuflen)) <= 0) goto out; @@ -170,7 +170,7 @@ out: void netreset(void) { - state = INPUTINITIAL; + rxstate = RXINITIAL; } void