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

Function ParseFtpEprtCommand

freebsd/netinet/libalias/alias_ftp.c:413–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411}
412
413static int
414ParseFtpEprtCommand(struct libalias *la, char *sptr, int dlen)
415{
416 char ch, delim;
417 int i, state;
418 u_int32_t addr;
419 u_short port;
420 u_int8_t octet;
421
422 /* Format: "EPRT |1|A.D.D.R|PORT|". */
423
424 /* Return if data length is too short. */
425 if (dlen < 18)
426 return (0);
427
428 if (strncasecmp("EPRT ", sptr, 5))
429 return (0);
430
431 addr = port = octet = 0;
432 delim = '|'; /* XXX gcc -Wuninitialized */
433 state = 0;
434 for (i = 5; i < dlen; i++) {
435 ch = sptr[i];
436 switch (state) {
437 case 0:
438 if (!isspace(ch)) {
439 delim = ch;
440 state++;
441 }
442 break;
443 case 1:
444 if (ch == '1') /* IPv4 address */
445 state++;
446 else
447 return (0);
448 break;
449 case 2:
450 if (ch == delim)
451 state++;
452 else
453 return (0);
454 break;
455 case 3:
456 case 5:
457 case 7:
458 case 9:
459 if (isdigit(ch)) {
460 octet = ch - '0';
461 state++;
462 } else
463 return (0);
464 break;
465 case 4:
466 case 6:
467 case 8:
468 case 10:
469 if (isdigit(ch))
470 octet = 10 * octet + ch - '0';

Callers 2

AliasHandleFtpOutFunction · 0.85
AliasHandleFtpInFunction · 0.85

Calls 3

strncasecmpFunction · 0.85
isspaceFunction · 0.85
isdigitFunction · 0.85

Tested by

no test coverage detected