| 643 | } |
| 644 | |
| 645 | static void |
| 646 | NewFtpMessage(struct libalias *la, struct ip *pip, |
| 647 | struct alias_link *lnk, |
| 648 | int maxpacketsize, |
| 649 | int ftp_message_type) |
| 650 | { |
| 651 | struct alias_link *ftp_lnk; |
| 652 | |
| 653 | /* Security checks. */ |
| 654 | if (pip->ip_src.s_addr != la->true_addr.s_addr) |
| 655 | return; |
| 656 | |
| 657 | if (la->true_port < IPPORT_RESERVED) |
| 658 | return; |
| 659 | |
| 660 | /* Establish link to address and port found in FTP control message. */ |
| 661 | ftp_lnk = AddLink(la, la->true_addr, GetDestAddress(lnk), |
| 662 | GetAliasAddress(lnk), htons(la->true_port), 0, GET_ALIAS_PORT, |
| 663 | IPPROTO_TCP); |
| 664 | |
| 665 | if (ftp_lnk != NULL) { |
| 666 | int slen, hlen, tlen, dlen; |
| 667 | struct tcphdr *tc; |
| 668 | |
| 669 | #ifndef NO_FW_PUNCH |
| 670 | /* Punch hole in firewall */ |
| 671 | PunchFWHole(ftp_lnk); |
| 672 | #endif |
| 673 | |
| 674 | /* Calculate data length of TCP packet */ |
| 675 | tc = (struct tcphdr *)ip_next(pip); |
| 676 | hlen = (pip->ip_hl + tc->th_off) << 2; |
| 677 | tlen = ntohs(pip->ip_len); |
| 678 | dlen = tlen - hlen; |
| 679 | |
| 680 | /* Create new FTP message. */ |
| 681 | { |
| 682 | char stemp[MAX_MESSAGE_SIZE + 1]; |
| 683 | char *sptr; |
| 684 | u_short alias_port; |
| 685 | u_char *ptr; |
| 686 | int a1, a2, a3, a4, p1, p2; |
| 687 | struct in_addr alias_address; |
| 688 | |
| 689 | /* Decompose alias address into quad format */ |
| 690 | alias_address = GetAliasAddress(lnk); |
| 691 | ptr = (u_char *) & alias_address.s_addr; |
| 692 | a1 = *ptr++; |
| 693 | a2 = *ptr++; |
| 694 | a3 = *ptr++; |
| 695 | a4 = *ptr; |
| 696 | |
| 697 | alias_port = GetAliasPort(ftp_lnk); |
| 698 | |
| 699 | /* Prepare new command */ |
| 700 | switch (ftp_message_type) { |
| 701 | case FTP_PORT_COMMAND: |
| 702 | case FTP_227_REPLY: |
no test coverage detected