1
/* Copyright (c) 2007-2010 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.
22
#include "DwTcpSocket.h"
26
extern int32_t key_n[];
29
void windows_socket_start() {
31
WORD wVersionRequested = MAKEWORD(2,2);
32
WSAStartup( wVersionRequested, &wsaData);
35
ipv6_not_supported_on_windows_build;
40
printf("Usage: Deadwood [-f dwood3rc]\n");
44
/* Show the name of the program */
45
void dw_show_programname() {
48
"Deadwood: A DNS UDP non-recursive cache (IPv6 supported)",1);
51
"Deadwood: A DNS UDP non-recursive cache (IPv4-only)",1);
55
/* Parse command-line arguments given to server */
56
void dw_parse_args(int argc, char **argv) {
57
if(argc != 1 && argc != 3) {
59
} else if(argc == 3) {
60
if(argv[1] == 0 || argv[2] == 0) {
62
} if(*(argv[1]) != '-' || *(argv[1] + 1) != 'f' ||
63
*(argv[1] + 2) != 0) {
66
process_mararc(argv[2]);
69
process_mararc("/etc/dwood3rc");
71
process_mararc("dwood3rc.txt");
76
/* DNS non-recursive caching server */
77
int dw_udp_main(int argc, char **argv) {
78
int bind_count = 0; /* Number of IPs we bound to */
79
set_add_constant(); /* Has to be done before processing mararc */
80
dw_parse_args(argc,argv);
81
dw_show_programname();
82
process_mararc_params();
84
windows_socket_start();
87
signal(SIGPIPE, SIG_IGN); /* *NIX security bug workaround */
89
dw_log_number("Verbose_level set to ",key_n[DWM_N_verbose_level]
91
/* Bind to all UDP sockets */
92
bind_count = bind_all_udp();
94
dw_log_number("We bound to ",bind_count," addresses",1);
96
dw_fatal("Unable to bind to any IP addresses (UDP)");
98
/* Bind to all TCP sockets */
99
bind_count = bind_all_tcp();
100
if(bind_count <= 0 && key_n[DWM_N_tcp_listen] == 1) {
101
dw_fatal("Unable to bind to any IP addresses (TCP)");
103
/* Initialize "inflight" hash */
104
init_inflight_hash();
111
process_root_upstream();
119
/* Make -Wall happy */
120
extern int dw_tcp_main(int argc, char **argv);
121
/* Combined binary: Have DwUdp and DwTcp be the same program */
124
int main(int argc, char **argv) {
126
int dw_svc_main(int argc, char **argv) {
130
dw_alog_3strings("Deadwood version ",VERSION,"");
132
dw_alog_3strings("Don't invoke this program without ",
138
/* Have 'a' point to the first character in the basename */
139
while(*a != 0 && c < 250) {
140
if(*a == '/' || *a == '\\') {
152
if((*a == 'D' || *a == 'd') && *(a+1) == 'w' && (*(a+2) == 'T' ||
154
printf("Deadwood now has TCP support; DwTcp isn't needed\n");
157
dw_udp_main(argc,argv);