From dd06325bdf67b31c3409d2f88a0ad11ac611d2bd Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 24 May 2012 16:22:04 +0800 Subject: [PATCH] minor fixes --- Makefile.am | 4 ++-- Makefile.in | 22 +++++++++++----------- encrypt.h | 4 +--- main.c => local.c | 24 ++++++++++++++++++++---- main.h => local.h | 2 +- 5 files changed, 35 insertions(+), 21 deletions(-) rename main.c => local.c (95%) rename main.h => local.h (98%) diff --git a/Makefile.am b/Makefile.am index 29e5729c..91ddeb8a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,3 @@ -bin_PROGRAMS = main -main_SOURCES = encrypt.c encrypt.h main.c main.h +bin_PROGRAMS = local +local_SOURCES = encrypt.c encrypt.h local.c local.h diff --git a/Makefile.in b/Makefile.in index 30f0070e..a20dcf4d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -32,7 +32,7 @@ POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : -bin_PROGRAMS = main$(EXEEXT) +bin_PROGRAMS = local$(EXEEXT) subdir = . DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in $(srcdir)/config.h.in \ @@ -49,9 +49,9 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) -am_main_OBJECTS = encrypt.$(OBJEXT) main.$(OBJEXT) -main_OBJECTS = $(am_main_OBJECTS) -main_LDADD = $(LDADD) +am_local_OBJECTS = encrypt.$(OBJEXT) local.$(OBJEXT) +local_OBJECTS = $(am_local_OBJECTS) +local_LDADD = $(LDADD) DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -60,8 +60,8 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(main_SOURCES) -DIST_SOURCES = $(main_SOURCES) +SOURCES = $(local_SOURCES) +DIST_SOURCES = $(local_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -165,7 +165,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -main_SOURCES = encrypt.c encrypt.h main.c main.h +local_SOURCES = encrypt.c encrypt.h local.c local.h all: config.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -257,9 +257,9 @@ uninstall-binPROGRAMS: clean-binPROGRAMS: -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) -main$(EXEEXT): $(main_OBJECTS) $(main_DEPENDENCIES) $(EXTRA_main_DEPENDENCIES) - @rm -f main$(EXEEXT) - $(LINK) $(main_OBJECTS) $(main_LDADD) $(LIBS) +local$(EXEEXT): $(local_OBJECTS) $(local_DEPENDENCIES) $(EXTRA_local_DEPENDENCIES) + @rm -f local$(EXEEXT) + $(LINK) $(local_OBJECTS) $(local_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -268,7 +268,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/encrypt.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/local.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/encrypt.h b/encrypt.h index e997d9d9..20ad3ede 100755 --- a/encrypt.h +++ b/encrypt.h @@ -1,5 +1,4 @@ -#ifndef ENCRYPT_H -#define ENCRYPT_H +#pragma once #include #include @@ -14,4 +13,3 @@ void decrypt(char *buf, int len); int send_encrypt(int sock, char *buf, int len, int flags); int recv_decrypt(int sock, char *buf, int len, int flags); -#endif // ENCRYPT_H diff --git a/main.c b/local.c similarity index 95% rename from main.c rename to local.c index 6b75c21c..8fa9a087 100644 --- a/main.c +++ b/local.c @@ -18,9 +18,14 @@ #include #include -#include "main.h" +#include "local.h" +#include "encrypt.h" + +#define SERVER "127.0.0.1" +#define REMOTE_PORT "8499" +#define PORT "1080" +#define KEY "foobar!" -#define PORT 1090 #define REPLY "HTTP/1.1 200 OK\n\nhello" #define min(a,b) \ @@ -72,6 +77,8 @@ int create_and_bind(char *port) { if (s == 0) { /* We managed to bind successfully! */ break; + } else { + perror("bind"); } close(listen_sock); @@ -117,6 +124,7 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) { return; } } + encrypt(remote->buf, r); int w = send(remote->fd, remote->buf, r, MSG_NOSIGNAL); if(w == -1) { perror("send"); @@ -219,6 +227,7 @@ static void remote_recv_cb (EV_P_ ev_io *w, int revents) { return; } } + decrypt(server->buf, r); int w = send(server->fd, server->buf, r, MSG_NOSIGNAL); // printf("after send: w=%d\n", w); if(w == -1) { @@ -396,7 +405,7 @@ static void accept_cb (EV_P_ ev_io *w, int revents) memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - getaddrinfo("www.sina.com.cn", "80", &hints, &res); + getaddrinfo(SERVER, REMOTE_PORT, &hints, &res); sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (sockfd < 0) { perror("socket"); @@ -417,12 +426,19 @@ static void accept_cb (EV_P_ ev_io *w, int revents) int main (void) { + fprintf(stderr, "calculating ciphers\n"); + get_table(KEY); + int listenfd; - listenfd = create_and_bind("1090"); + listenfd = create_and_bind(PORT); + if (listenfd < 0) { + return 1; + } if (listen(listenfd, SOMAXCONN) == -1) { perror("listen() error."); return 1; } + fprintf(stderr, "server listening at port %s\n", PORT); setnonblocking(listenfd); struct listen_ctx listen_ctx; listen_ctx.fd = listenfd; diff --git a/main.h b/local.h similarity index 98% rename from main.h rename to local.h index 34f3980d..bae4a19a 100644 --- a/main.h +++ b/local.h @@ -2,7 +2,7 @@ #include -#define BUF_SIZE 4096 +#define BUF_SIZE 1500 struct listen_ctx { ev_io io;