diff options
author | Christian Pointner <equinox@anytun.org> | 2008-12-28 03:01:38 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2008-12-28 03:01:38 +0000 |
commit | 699f04dc754ef3545ae217ab1879731f2595ae0d (patch) | |
tree | f80e29d197eedc2a1569a9ff35b43e47000e32ef /src | |
parent | added enpoint to string functions (diff) |
some memory erros fixed
added udp_read and udp_write
Diffstat (limited to 'src')
-rw-r--r-- | src/uanytun.c | 9 | ||||
-rw-r--r-- | src/udp.c | 10 | ||||
-rw-r--r-- | src/udp.h | 2 |
3 files changed, 12 insertions, 9 deletions
diff --git a/src/uanytun.c b/src/uanytun.c index 881ba5b..ae052f8 100644 --- a/src/uanytun.c +++ b/src/uanytun.c @@ -71,7 +71,7 @@ int main(int argc, char* argv[]) exit(-1); } - udp_set_remote(sock, "anycast.anytun.org", "4444"); + udp_set_remote(sock, "1.2.3.4", "4444"); char* remote_string = udp_get_remote_end_string(sock); log_printf(INFO, "set remote end to: %s", remote_string); free(remote_string); @@ -81,9 +81,10 @@ int main(int argc, char* argv[]) int len = 0; unsigned int cnt = 0; while(cnt < 5) { - len = tun_read(dev, buf, 1600); - printf("read %d bytes from device\n", len); -// tun_write(dev, buf, len); + struct sockaddr_storage remote; + len = udp_read(sock, buf, 1600, &remote); + printf("read %d bytes from socket\n", len); + udp_write(sock, buf, len); cnt++; } tun_close(&dev); @@ -66,6 +66,7 @@ void udp_init(udp_socket_t** sock, const char* local_addr, const char* port) return; } + memset(&((*sock)->remote_end_), 0, sizeof((*sock)->local_end_)); memcpy(&((*sock)->local_end_), res->ai_addr, sizeof(*(res->ai_addr))); (*sock)->fd_ = socket(res->ai_family, SOCK_DGRAM, 0); if((*sock)->fd_ < 0) { @@ -162,12 +163,13 @@ char* udp_get_remote_end_string(udp_socket_t* sock) return udp_endpoint_to_string(sock->remote_end_); } -int udp_read(udp_socket_t* sock, u_int8_t* buf, u_int32_t len, struct sockaddr_storage* remote_end_) +int udp_read(udp_socket_t* sock, u_int8_t* buf, u_int32_t len, struct sockaddr_storage* remote_end) { - if(!sock || !remote_end_) + if(!sock || !remote_end) return -1; - return 0; + int socklen = sizeof(*remote_end); + return recvfrom(sock->fd_, buf, len, 0, (struct sockaddr *)remote_end, &socklen); } int udp_write(udp_socket_t* sock, u_int8_t* buf, u_int32_t len) @@ -175,6 +177,6 @@ int udp_write(udp_socket_t* sock, u_int8_t* buf, u_int32_t len) if(!sock) return -1; - return 0; + return sendto(sock->fd_, buf, len, 0, (struct sockaddr *)&(sock->remote_end_), sizeof(sock->remote_end_));; } @@ -52,7 +52,7 @@ char* udp_endpoint_to_string(struct sockaddr_storage ss); char* udp_get_local_end_string(udp_socket_t* sock); char* udp_get_remote_end_string(udp_socket_t* sock); -int udp_read(udp_socket_t* sock, u_int8_t* buf, u_int32_t len, struct sockaddr_storage* remote_end_); +int udp_read(udp_socket_t* sock, u_int8_t* buf, u_int32_t len, struct sockaddr_storage* remote_end); int udp_write(udp_socket_t* sock, u_int8_t* buf, u_int32_t len); |