Example #1
0
void print_pftp_get( void )
{
    // This function establishes connection
    globalModemStatus |= MODEM_PFTPINPROGRESS;
    print( MODEM_COM, "GET /cgi/pftp.py?get=", globalModemPFTP.File.Name );
    if( globalModemPFTP.ChunkSize != 256 ) { // 256 is PFTP server default
        print( MODEM_COM, "&sz=%d", globalModemPFTP.ChunkSize);
    } // if
    print( MODEM_COM, "&chk=%d", globalModemPFTP.CurrentChunk );
    print_http();
    
}
Example #2
0
void got_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *packet) {
  /* declare pointers to packet headers */
  const struct sniff_ethernet *ethernet;  /* The ethernet header [1] */
  const struct sniff_ip *ip;              /* The IP header */
  const struct sniff_tcp *tcp;            /* The TCP header */
  const char *payload;                    /* Packet payload */

  int size_ip;
  int size_tcp;
  int size_payload;

  ethernet = (struct sniff_ethernet*)(packet);
  ip = (struct sniff_ip*)(packet + SIZE_ETHERNET);
  size_ip = IP_HL(ip)*4;
  if(size_ip < 20) {
    printf("      Invalid IP header length: %u bytes\n", size_ip);
    return;
  }

  printf("\n      From: %s\n", inet_ntoa(ip->ip_src));
  printf("        To: %s\n", inet_ntoa(ip->ip_dst));

  /* determine protocol */  
  switch(ip->ip_p) {
    case IPPROTO_TCP:
      printf("  Protocol: TCP\n");
      break;
    case IPPROTO_UDP:
      printf("  Protocol: UDP\n");
      return;
    case IPPROTO_ICMP:
      printf("  Protocol: ICMP\n");
      return;
    case IPPROTO_IP:
      printf("  Protocol: IP\n");
      return;
    default:
      printf("  Protocol: unknown\n");
      return;
  }

  tcp = (struct sniff_tcp*)(packet + SIZE_ETHERNET + size_ip);
  size_tcp = TH_OFF(tcp)*4;
  if(size_tcp < 20) {
    printf("      Invalid TCP hader length: %u bytes\n", size_tcp);
    return;
  }
  
  printf("    S-Port: %d\n", ntohs(tcp->th_sport));
  printf("    D-Port: %d\n", ntohs(tcp->th_dport));
  printf("       SYN: %d\n", ntohs(tcp->th_seq));
  printf("       ACK: %d\n", ntohs(tcp->th_ack));
  printf("     Flags: %x\n", tcp->th_flags);
  if(tcp ->th_flags & TH_FIN) {
    printf("            :FIN");
  }
  if(tcp ->th_flags & TH_SYN) {
    printf("            SYN");
  }
  if(tcp ->th_flags & TH_ACK) {
    printf("            ACK");
  }
  if(tcp ->th_flags & TH_RST) {
    printf("            RST");
  }
  if(tcp ->th_flags & TH_PUSH) {
    printf("            PUSH");
  }
  printf("\n");

  payload = (packet + SIZE_ETHERNET + size_ip + size_tcp);
  size_payload = ntohs(ip->ip_len) - (size_ip + size_tcp);

  if(size_payload > 0 && (ntohs(tcp->th_dport) == 80 || ntohs(tcp->th_dport) == 443) ) {
    print_http(payload, size_payload);
  }

  return;
}