-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
851 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.vscode | ||
*.o | ||
*.so | ||
*.swp. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
# Copyright (C) 2018-2024 Ruilin Peng (Nick) <[email protected]>. | ||
# | ||
# smartdns is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# smartdns is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
BIN=smartdns-demo.so | ||
OBJS_MAIN=$(patsubst %.c,%.o,$(wildcard *.c)) | ||
OBJS=$(OBJS_MAIN) | ||
|
||
# cflags | ||
ifndef CFLAGS | ||
ifdef DEBUG | ||
CFLAGS = -g -DDEBUG | ||
else | ||
CFLAGS = -O2 | ||
endif | ||
CFLAGS +=-fPIC -Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing -funwind-tables -Wmissing-prototypes -Wshadow -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough | ||
endif | ||
|
||
override CFLAGS +=-Iinclude -I../../src/include -I../../src | ||
override CFLAGS += -DBASE_FILE_NAME='"$(notdir $<)"' | ||
override CFLAGS += $(EXTRA_CFLAGS) | ||
|
||
override LDFLAGS += -lpthread -shared | ||
|
||
.PHONY: all clean | ||
|
||
all: $(BIN) | ||
|
||
$(BIN) : $(OBJS) | ||
$(CC) $(OBJS) -o $@ $(LDFLAGS) | ||
|
||
clean: | ||
$(RM) $(OBJS) $(BIN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "demo.h" | ||
#include "dns_server.h" | ||
#include "util.h" | ||
#include <arpa/inet.h> | ||
#include <netinet/in.h> | ||
#include <stdio.h> | ||
#include <sys/socket.h> | ||
#include <tlog.h> | ||
|
||
static int demo_server_recv(struct dns_packet *packet, unsigned char *inpacket, int inpacket_len, | ||
struct sockaddr_storage *local, socklen_t local_len, struct sockaddr_storage *from, | ||
socklen_t from_len) | ||
{ | ||
char hostname[256] = {0}; | ||
tlog(TLOG_INFO, "recv packet from %s", get_host_by_addr(hostname, sizeof(hostname), (struct sockaddr *)from)); | ||
return 0; | ||
} | ||
|
||
static void demo_server_request_complete(struct dns_request *request) | ||
{ | ||
tlog(TLOG_INFO, "server complete request, request domain is %s", dns_server_request_get_domain(request)); | ||
} | ||
|
||
struct smartdns_operations demo_ops = { | ||
.server_recv = demo_server_recv, | ||
.server_query_complete = demo_server_request_complete, | ||
}; | ||
|
||
int dns_plugin_init(struct dns_plugin *plugin) | ||
{ | ||
char options[4096] = {0}; | ||
int argc = dns_plugin_get_argc(plugin); | ||
const char **argv = dns_plugin_get_argv(plugin); | ||
|
||
for (int i = 0; i < argc; i++) { | ||
snprintf(options + strlen(options), sizeof(options) - strlen(options), "%s ", argv[i]); | ||
} | ||
|
||
tlog(TLOG_INFO, "demo plugin init, options: %s", options); | ||
smartdns_operations_register(&demo_ops); | ||
return 0; | ||
} | ||
|
||
int dns_plugin_exit(struct dns_plugin *plugin) | ||
{ | ||
tlog(TLOG_INFO, "demo plugin exit."); | ||
smartdns_operations_unregister(&demo_ops); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
#ifndef SMART_DNS_PLUGIN_DEMO_H | ||
#define SMART_DNS_PLUGIN_DEMO_H | ||
|
||
#include "dns_plugin.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif /*__cplusplus */ | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif /*__cplusplus */ | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.