summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main2.c45
-rw-r--r--test/connect.c41
2 files changed, 79 insertions, 7 deletions
diff --git a/main2.c b/main2.c
index 5847c2c..3efd604 100644
--- a/main2.c
+++ b/main2.c
@@ -151,9 +151,18 @@ enum SOCKS5_CMD {
SOCKS_UDP
};
-struct next_req {
- enum SOCKS5_CMD cmd;
- char* dest;
+enum SOCKS5_ADDRTYPE {
+ SOCKS_IN,
+ SOCKS_IN6,
+ SOCKS_DOMAIN
+};
+
+struct next_req_ipv4 {
+ u_int8_t version;
+ u_int8_t cmd;
+ u_int8_t reserved;
+ u_int8_t atyp;
+ u_int8_t dest[4];
uint16_t port;
};
@@ -473,7 +482,7 @@ static int start_unpack_packet(int fd, void* reserved, struct socks5_session *so
} else {
// return 1;
u_int8_t buf[4096];
- struct next_req req_to;
+ // struct next_req req_to;
memset(buf, 0, 4096);
memset(buf, 0, 4096);
@@ -555,14 +564,36 @@ static int start_unpack_packet_no_epl(int fd, void* reserved, struct socks5_sess
if (socks5_session->is_auth == 0) {
socks5_handshake(fd, buf, socks5_session);
} else {
- u_int8_t test = 128;
+
+
+
+
+ if (buf[3] == 1) {
+ struct next_req_ipv4 *next_req = (struct next_req_ipv4*)buf;
+
+
+ printf("SOCKS_REQ ver: %c; CMD: %s; type: %s; ip: %u.%u.%u.%u:%u\n", buf[0],
+ cmd2str(next_req->cmd), ip2str(buf[3]), next_req->dest[0], next_req->dest[1], next_req->dest[2], next_req->dest[3],
+ (uint16_t)next_req->port);
+ }
+
+ // if1
+ // u_int8_t test = 128;
- printf("SOCKS_REQ ver: %c; CMD: %s; type: %s; ip: %u.%u.%u.%u\n", buf[0],
- cmd2str(buf[1]), ip2str(buf[3]), buf[4], buf[5], buf[6], (u_int8_t)buf[7]);
+
}
}while (ret != 0);
}
+static int create_server2server_conn(int fdptr)
+{
+ int ret = 0;
+
+ int tcpfd = socket(AF_INET, SOCK_STREAM, 0);
+ struct sockaddr_in serv_addr;
+ memset(&serv_addr, 0, sizeof(struct sockaddr_in));
+}
+
static void* start_private_conn_no_epl(void *priv_conn_detailsptr)
{
struct start_private_conn_details *priv_conn_details = (struct start_private_conn_details*)priv_conn_detailsptr;
diff --git a/test/connect.c b/test/connect.c
new file mode 100644
index 0000000..01e2d2c
--- /dev/null
+++ b/test/connect.c
@@ -0,0 +1,41 @@
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <string.h>
+/* create connection in C */
+
+int main(int argc, char *argv)
+{
+ int ret = 0;
+
+ int tcpfd = socket(AF_INET, SOCK_STREAM, 0);
+ struct sockaddr_in serv_addr;
+ memset(&serv_addr, 0, sizeof(struct sockaddr_in));
+
+ serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
+ serv_addr.sin_port = htons(8000);
+ serv_addr.sin_family = AF_INET;
+
+ socklen_t len = sizeof(struct sockaddr_in);
+ ret = connect(tcpfd, (struct sockaddr*)&serv_addr, len);
+
+ if (ret == -1) {
+ perror("connect()");
+ return -1;
+ }
+
+ char buf[4096];
+ static const char sendbuf[] = "GET / HTTP/1.1\r\n\r\n";
+
+ int buflen = strlen(sendbuf);
+
+ write(tcpfd, sendbuf, buflen);
+ recv(tcpfd, buf, 4096, 0);
+
+ printf("%s\n", buf);
+
+ close(tcpfd);
+ return -1;
+} \ No newline at end of file