/* * Copyright (C) 1997-2000 SpellCaster Telecommunications Inc. * $Id: simple_bundle.c,v 1.1 2004/03/11 03:59:32 bcrl Exp $ * Released under the GNU Public License. See LICENSE file for details. */ #include #include #include #include #include #include #include #include #include #include typedef unsigned long long u64; #include "../include/aps_if.h" void setup_ipv6(char *arg) { u64 eui = atoi(arg); int sockfd; struct ifreq ifr; struct in6_ifreq ifr6; int index; sockfd = socket(AF_INET6, SOCK_DGRAM, 0); if (sockfd < 0) perror("socket(AF_INET6)"); memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, "aps0"); if (ioctl(sockfd, SIOCGIFINDEX, &ifr) < 0) perror("ioctl(SIOGIFINDEX)"); index = ifr.ifr_ifindex; ifr.ifr_flags = IFF_UP | IFF_POINTOPOINT; if (0 != ioctl(sockfd, SIOCSIFFLAGS, &ifr)) perror("error setting interface flags"); ifr.ifr_mtu = 1500; if (0 != ioctl(sockfd, SIOCSIFMTU, &ifr)) perror("error setting interface mtu"); memset(&ifr6, 0, sizeof(ifr6)); ifr6.ifr6_ifindex = index; ifr6.ifr6_prefixlen = 10; ifr6.ifr6_addr.s6_addr16[0] = htons(0xfe80); ifr6.ifr6_addr.s6_addr16[7] = htons(eui); if (ioctl(sockfd, SIOCSIFADDR, &ifr6) < 0) perror("ioctl(SIOCSIFADDR)"); } int main ( int argc, char *argv[] ) { int fd, len, num; printf("Opening...\n"); fd = open(argv[1], O_RDWR | (argc >= 3 ? O_NONBLOCK : 0)); if (-1 == fd) { fprintf(stderr, "Error opening %s: %s\n", argv[1], strerror(errno)); return 1; } if (argc >= 3) { int fl = fcntl(fd, F_GETFL, 0); fl &= ~O_NONBLOCK; fcntl(fd, F_SETFL, fl); printf("Dialing %s...\n", argv[2]); if ((len = ioctl(fd, BIOCDIAL, argv[2])) < 0) { perror("Dial failed:"); return 1; } if (len > 0) { fprintf(stderr, "Dial failed cause 0x%02x\n", len); return 1; } } printf("Waiting for packets...\n"); num = 0; if (0 != ioctl(fd, BIOCCREATEBUNDLE, &num)) perror("create bundle"); printf("created device aps%d\n", num); if (0 != ioctl(fd, BIOCJOINBUNDLE, 0/*num*/)) perror("join bundle"); printf("joined bundle.\n"); if (0 != ioctl(fd, BIOC_SETLBFL, BF_PPP | BF_PASS_IPV6)) perror("setlbfl(0x11)"); if (0 != ioctl(fd, BIOC_SETRBFL, BF_PPP | BF_PASS_IPV6)) perror("setrbfl(0x11)"); if (0 != ioctl(fd, BIOC_SETLCFL, BF_PPP | BF_PASS_IPV6)) perror("setlcfl(0x11)"); if (0 != ioctl(fd, BIOC_SETRCFL, BF_PPP | BF_PASS_IPV6)) perror("setrcfl(0x11)"); printf("flags set.\n"); setup_ipv6(argv[3]); getchar(); #if 0 if (0 != ioctl(fd, BIOC_SETCFL, 0x00)) perror("setcfl(0x00)"); #endif printf("leaving bundle...\n"); if (0 != ioctl(fd, BIOCLEAVEBUNDLE, 0)) perror("join bundle"); if (0 != ioctl(fd, BIOCDESTROYBUNDLE, num)) perror("destroy bundle"); printf("bundle destroyed.\n"); return 0; }