1
/* Copyright (c) 2009 Sam Trenholme
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
15
* This software is provided 'as is' with no guarantees of correctness or
16
* fitness for purpose.
19
/* Simple UDP DNS server; this never replies to a DNS query one sends
22
#include <sys/socket.h>
23
#include <netinet/in.h>
24
#include <arpa/inet.h>
31
/* This is the IP "10.11.12.13" added to their question */
33
"\xc0\x0c\x00\x01\x00\x01\x00\x00\x00\x00\x00\x04\x0a\x0b\x0c\x0d";
36
int a, b, len_inet, sock;
37
struct sockaddr_in dns_udp;
40
int localhost = 0x7f000002; /* 127.0.0.2 */
41
int leni = sizeof(struct sockaddr);
43
/* Bind to 127.0.0.2 port 53 */
44
sock = socket(AF_INET,SOCK_DGRAM,0);
45
if(sock == -1) {printf("socket error\n");exit(0);}
46
memset(&dns_udp,0,sizeof(dns_udp));
47
dns_udp.sin_family = AF_INET;
48
dns_udp.sin_port = htons(53);
49
dns_udp.sin_addr.s_addr = htonl(localhost);
50
if(dns_udp.sin_addr.s_addr == INADDR_NONE) {
51
printf("htonl error\n");exit(0);}
52
len_inet = sizeof(dns_udp);
53
if(bind(sock,(struct sockaddr *)&dns_udp,len_inet) == -1) {
54
printf("bind error\n");exit(0);}
56
/* Linux kernel bug */
57
/* fcntl(sock, F_SETFL, O_NONBLOCK); */
60
/* Get data from UDP port 53 */
61
len_inet = recvfrom(sock,in,255,0,(struct sockaddr *)&dns_udp,&foo);
62
/* Roy Arends check: We only answer questions */
64
printf("Packet not sent\n");
67
printf("Why are we here?\n");