diff options
Diffstat (limited to 'src/net-proxy-udp.c')
-rw-r--r-- | src/net-proxy-udp.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/net-proxy-udp.c b/src/net-proxy-udp.c index 996b793..70230fd 100644 --- a/src/net-proxy-udp.c +++ b/src/net-proxy-udp.c @@ -10,7 +10,7 @@ static int init_fd(struct tsnif_handle *h, struct tsnif_np_args *args, int server) { struct tsnif_np_handle *nph = &h->np; - struct sockaddr_in sa; + struct sockaddr_in *sa = &args->sa; int fd; fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); @@ -22,15 +22,9 @@ static int init_fd(struct tsnif_handle *h, struct tsnif_np_args *args, int serve nph->fd_udp = fd; if (server) { - memset((char *) &sa, 0, sizeof(sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons(args->port); - /* XXX finish given host resolving */ - sa.sin_addr.s_addr = htonl(INADDR_ANY); - - if (-1 == bind(fd, &sa, sizeof(sa))) { + if (-1 == bind(fd, sa, sizeof(*sa))) { close(fd); - TSNIF_DEBUG(NP, "failed to bind to %d\n", args->port); + TSNIF_DEBUG(NP, "failed to bind\n"); return -1; } } @@ -80,11 +74,12 @@ int udp_send(struct tsnif_handle *h, struct trans_msg *msg) if (TSNIF_CMD_DATA == msg->cmd) memcpy(m->data, msg->data.ptr, msg->data.len); - if (TSNIF_NP_UDP_SERVER & nph->flags) + if (TSNIF_NP_UDP_SERVER & TSNIF_NP_FLAGS(nph)) return sendto(nph->fd_udp, m, size, 0, &nph->udp_client.sa, sizeof(nph->udp_client.sa)); - return send(nph->fd_udp, m, size, 0); + return sendto(nph->fd_udp, m, size, 0, + &nph->args->sa, sizeof(nph->args->sa)); } int udp_process(struct tsnif_handle *h) |