/* * $Id: tap.c,v 1.1.1.1 2008/10/15 03:28:31 james26_jang Exp $ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. */ #include #include #include #include #include #include #include #include #include #include #define MAXREMOTE 128 struct sockaddr_in6 localaddr; int numremote; struct sockaddr_in6 remoteaddr[MAXREMOTE]; int sock; int tap; char *tapdevice; int getaddr(const char *hostname, struct sockaddr_in6 *in) { struct hostent *he; in->sin6_port = 0; if ((he = gethostbyname2(hostname, AF_INET6)) != NULL) { in->sin6_family = he->h_addrtype; memcpy(in->sin6_addr.s6_addr, he->h_addr_list[0], he->h_length); return 0; } if ((he = gethostbyname2(hostname, AF_INET)) != NULL) { in->sin6_family = AF_INET6; memset(in->sin6_addr.s6_addr, 0, 10); in->sin6_addr.s6_addr[10] = 0; in->sin6_addr.s6_addr[11] = 0; memcpy(in->sin6_addr.s6_addr + 12, he->h_addr_list[0], he->h_length); return 0; } return 1; } void handle() { struct pollfd pfd[2]; pfd[0].fd = tap; pfd[0].events = POLLIN; pfd[1].fd = sock; pfd[1].events = POLLIN; while (1) { unsigned char buf[2048]; int len; if (poll(pfd, 2, -1) <= 0) { perror("poll"); break; } if (pfd[0].revents & POLLIN) { int i; if ((len = read(pfd[0].fd, buf, 2048)) < 0) { perror("read"); break; } for (i=0;i \n", argv[0]); return 1; } tapdevice = argv[1]; numremote = argc - 2; for (i=2;i