Browse Source

minor fixes

pull/1/head
clowwindy 13 years ago
parent
commit
dd06325bdf
5 changed files with 35 additions and 21 deletions
  1. 4
      Makefile.am
  2. 22
      Makefile.in
  3. 4
      encrypt.h
  4. 24
      local.c
  5. 2
      local.h

4
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

22
Makefile.in

@ -32,7 +32,7 @@ POST_INSTALL = :
NORMAL_UNINSTALL = : NORMAL_UNINSTALL = :
PRE_UNINSTALL = : PRE_UNINSTALL = :
POST_UNINSTALL = : POST_UNINSTALL = :
bin_PROGRAMS = main$(EXEEXT)
bin_PROGRAMS = local$(EXEEXT)
subdir = . subdir = .
DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \ DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/config.h.in \ $(srcdir)/Makefile.in $(srcdir)/config.h.in \
@ -49,9 +49,9 @@ CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES = CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)" am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS) 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@ DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles am__depfiles_maybe = depfiles
@ -60,8 +60,8 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC) CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ 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 ETAGS = etags
CTAGS = ctags CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -165,7 +165,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ 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 all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-am $(MAKE) $(AM_MAKEFLAGS) all-am
@ -257,9 +257,9 @@ uninstall-binPROGRAMS:
clean-binPROGRAMS: clean-binPROGRAMS:
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) -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: mostlyclean-compile:
-rm -f *.$(OBJEXT) -rm -f *.$(OBJEXT)
@ -268,7 +268,7 @@ distclean-compile:
-rm -f *.tab.c -rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/encrypt.Po@am__quote@ @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: .c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<

4
encrypt.h

@ -1,5 +1,4 @@
#ifndef ENCRYPT_H
#define ENCRYPT_H
#pragma once
#include <sys/socket.h> #include <sys/socket.h>
#include <string.h> #include <string.h>
@ -14,4 +13,3 @@ void decrypt(char *buf, int len);
int send_encrypt(int sock, char *buf, int len, int flags); int send_encrypt(int sock, char *buf, int len, int flags);
int recv_decrypt(int sock, char *buf, int len, int flags); int recv_decrypt(int sock, char *buf, int len, int flags);
#endif // ENCRYPT_H

main.c → local.c

@ -18,9 +18,14 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#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 REPLY "HTTP/1.1 200 OK\n\nhello"
#define min(a,b) \ #define min(a,b) \
@ -72,6 +77,8 @@ int create_and_bind(char *port) {
if (s == 0) { if (s == 0) {
/* We managed to bind successfully! */ /* We managed to bind successfully! */
break; break;
} else {
perror("bind");
} }
close(listen_sock); close(listen_sock);
@ -117,6 +124,7 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) {
return; return;
} }
} }
encrypt(remote->buf, r);
int w = send(remote->fd, remote->buf, r, MSG_NOSIGNAL); int w = send(remote->fd, remote->buf, r, MSG_NOSIGNAL);
if(w == -1) { if(w == -1) {
perror("send"); perror("send");
@ -219,6 +227,7 @@ static void remote_recv_cb (EV_P_ ev_io *w, int revents) {
return; return;
} }
} }
decrypt(server->buf, r);
int w = send(server->fd, server->buf, r, MSG_NOSIGNAL); int w = send(server->fd, server->buf, r, MSG_NOSIGNAL);
// printf("after send: w=%d\n", w); // printf("after send: w=%d\n", w);
if(w == -1) { if(w == -1) {
@ -396,7 +405,7 @@ static void accept_cb (EV_P_ ev_io *w, int revents)
memset(&hints, 0, sizeof hints); memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM; 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); sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sockfd < 0) { if (sockfd < 0) {
perror("socket"); perror("socket");
@ -417,12 +426,19 @@ static void accept_cb (EV_P_ ev_io *w, int revents)
int main (void) int main (void)
{ {
fprintf(stderr, "calculating ciphers\n");
get_table(KEY);
int listenfd; int listenfd;
listenfd = create_and_bind("1090");
listenfd = create_and_bind(PORT);
if (listenfd < 0) {
return 1;
}
if (listen(listenfd, SOMAXCONN) == -1) { if (listen(listenfd, SOMAXCONN) == -1) {
perror("listen() error."); perror("listen() error.");
return 1; return 1;
} }
fprintf(stderr, "server listening at port %s\n", PORT);
setnonblocking(listenfd); setnonblocking(listenfd);
struct listen_ctx listen_ctx; struct listen_ctx listen_ctx;
listen_ctx.fd = listenfd; listen_ctx.fd = listenfd;

main.h → local.h

@ -2,7 +2,7 @@
#include <ev.h> #include <ev.h>
#define BUF_SIZE 4096
#define BUF_SIZE 1500
struct listen_ctx { struct listen_ctx {
ev_io io; ev_io io;
Loading…
Cancel
Save