MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ParseFtp229Reply

Function ParseFtp229Reply

freebsd/netinet/libalias/alias_ftp.c:576–643  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

574}
575
576static int
577ParseFtp229Reply(struct libalias *la, char *sptr, int dlen)
578{
579 char ch, delim;
580 int i, state;
581 u_short port;
582
583 /* Format: "229 Entering Extended Passive Mode (|||PORT|)" */
584
585 /* Return if data length is too short. */
586 if (dlen < 11)
587 return (0);
588
589 if (strncmp("229 ", sptr, 4))
590 return (0);
591
592 port = 0;
593 delim = '|'; /* XXX gcc -Wuninitialized */
594
595 state = 0;
596 for (i = 4; i < dlen; i++) {
597 ch = sptr[i];
598 switch (state) {
599 case 0:
600 if (ch == '(')
601 state++;
602 break;
603 case 1:
604 delim = ch;
605 state++;
606 break;
607 case 2:
608 case 3:
609 if (ch == delim)
610 state++;
611 else
612 return (0);
613 break;
614 case 4:
615 if (isdigit(ch)) {
616 port = ch - '0';
617 state++;
618 } else
619 return (0);
620 break;
621 case 5:
622 if (isdigit(ch))
623 port = 10 * port + ch - '0';
624 else if (ch == delim)
625 state++;
626 else
627 return (0);
628 break;
629 case 6:
630 if (ch == ')')
631 state++;
632 else
633 return (0);

Callers 1

AliasHandleFtpOutFunction · 0.85

Calls 2

strncmpFunction · 0.85
isdigitFunction · 0.85

Tested by

no test coverage detected