~ubuntu-branches/ubuntu/wily/maradns/wily-proposed

« back to all changes in this revision

Viewing changes to deadwood-3.2.05/sqa/sqa_badid_question/badquestion.dns.c

  • Committer: Package Import Robot
  • Author(s): Dariusz Dwornikowski, Tomasz Buchert, Dariusz Dwornikowski
  • Date: 2015-03-27 18:34:08 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20150327183408-wnfachdkdjt96yu6
Tags: 2.0.11-1
[ Tomasz Buchert ]
* Imported Upstream version 2.0.11

[ Dariusz Dwornikowski ]
* d/patches: 
  - refreshed all patches for new deadwood version
  - removed generating of random prime on build (Closes: #785536) 
* d/rules: date taken from changelog (Closes: #785535)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2009 Sam Trenholme
2
 
 *
3
 
 * TERMS
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions
7
 
 * are met:
8
 
 *
9
 
 * 1. Redistributions of source code must retain the above copyright
10
 
 *    notice, this list of conditions and the following disclaimer.
11
 
 * 2. Redistributions in binary form must reproduce the above copyright
12
 
 *    notice, this list of conditions and the following disclaimer in the
13
 
 *    documentation and/or other materials provided with the distribution.
14
 
 *
15
 
 * This software is provided 'as is' with no guarantees of correctness or
16
 
 * fitness for purpose.
17
 
 */
18
 
 
19
 
/* Simple UDP DNS server; this sends "10.11.12.13" as an IP as a reply
20
 
 * to any DNS packet; to test handle_noreply this only answers every
21
 
 * third packet */
22
 
 
23
 
#include <sys/socket.h>
24
 
#include <netinet/in.h>
25
 
#include <arpa/inet.h>
26
 
#include <string.h>
27
 
#include <unistd.h>
28
 
#include <fcntl.h>
29
 
#include <stdlib.h>
30
 
#include <stdio.h>
31
 
 
32
 
/* This is the IP "10.11.12.13" added to their question */
33
 
char p[17] =
34
 
"\xc0\x0c\x00\x01\x00\x01\x00\x00\x00\x00\x00\x04\x0a\x0b\x0c\x0d";
35
 
 
36
 
main() {
37
 
        int a, b, len_inet, sock;
38
 
        struct sockaddr_in dns_udp;
39
 
        char in[512];
40
 
        int foo = sizeof(in);
41
 
        int localhost = 0x7f000001; /* 127.0.0.1 */
42
 
        int leni = sizeof(struct sockaddr);
43
 
 
44
 
        /* Bind to 127.0.0.1 port 53 */
45
 
        sock = socket(AF_INET,SOCK_DGRAM,0);
46
 
        if(sock == -1) {printf("socket error\n");exit(0);}
47
 
        memset(&dns_udp,0,sizeof(dns_udp));
48
 
        dns_udp.sin_family = AF_INET;
49
 
        dns_udp.sin_port = htons(53);
50
 
        dns_udp.sin_addr.s_addr = htonl(localhost);
51
 
        if(dns_udp.sin_addr.s_addr == INADDR_NONE) {
52
 
                printf("htonl error\n");exit(0);}
53
 
        len_inet = sizeof(dns_udp);
54
 
        if(bind(sock,(struct sockaddr *)&dns_udp,len_inet) == -1) {
55
 
                printf("bind error\n");exit(0);}
56
 
 
57
 
        /* Linux kernel bug */
58
 
        /* fcntl(sock, F_SETFL, O_NONBLOCK); */
59
 
 
60
 
        for(b=0;;b++) {
61
 
          /* Get data from UDP port 53 */
62
 
          len_inet = recvfrom(sock,in,255,0,(struct sockaddr *)&dns_udp,&foo);
63
 
          /* Roy Arends check: We only answer questions */
64
 
          if(len_inet < 3 || (in[2] & 0x80) != 0x00) {
65
 
                continue;
66
 
          }
67
 
          if(len_inet > 12) {
68
 
                /* Make this an answer */
69
 
                in[2] |= 0x80;
70
 
                /* We add an additional answer */
71
 
                in[7]++;
72
 
          }
73
 
          for(a=0;a<16;a++) {
74
 
                in[len_inet + a] = p[a];
75
 
          }
76
 
 
77
 
          /* Munge the question a little */
78
 
          if(in[12] > 0 && in[12] < 63) {
79
 
                in[13]++;
80
 
          }
81
 
 
82
 
          /* Send the reply */
83
 
          sendto(sock,in,len_inet + 16,0,
84
 
                (struct sockaddr *)&dns_udp,leni);
85
 
          printf("Packet sent\n");
86
 
 
87
 
        }
88
 
 
89
 
}
90