int main(int argc, char **argv) { int sockfd, n, npend; char recvline[MAXLINE + 1]; socklen_t len; struct sockaddr_storage ss; if (argc != 3) err_quit("usage: a.out <hostname or IPaddress> <service or port#>"); sockfd = Tcp_connect(argv[1], argv[2]); len = sizeof(ss); Getpeername(sockfd, (SA *)&ss, &len); printf("connected to %s\n", Sock_ntop_host((SA *)&ss, len)); for ( ; ; ) { if ( (n = Recv(sockfd, recvline, MAXLINE, MSG_PEEK)) == 0) break; /* server closed connection */ Ioctl(sockfd, FIONREAD, &npend); /* check FIONREAD support */ printf("%d bytes from PEEK, %d bytes pending\n", n, npend); n = Read(sockfd, recvline, MAXLINE); recvline[n] = 0; /* null terminate */ Fputs(recvline, stdout); } exit(0); }
int main(int argc, char **argv) { int n, flags; char buff[NREAD+1]; /* +1 for null at end */ if (argc == 2) listenfd = Tcp_listen(NULL, argv[1], NULL); else if (argc == 3) listenfd = Tcp_listen(argv[1], argv[2], NULL); else err_quit("usage: tcprecv02 [ <host> ] <port#>"); connfd = Xti_accept(listenfd, NULL, NULL); Signal(SIGPOLL, sig_poll); Ioctl(connfd, I_SETSIG, S_RDNORM); for ( ; ; ) { flags = 0; if ( (n = t_rcv(connfd, buff, NREAD, &flags)) < 0) { if (t_errno == TLOOK) { if ( (n = T_look(connfd)) == T_ORDREL) { printf("received T_ORDREL\n"); exit(0); } else err_quit("unexpected event after t_rcv: %d", n); } err_xti("t_rcv error"); } buff[n] = 0; /* null terminate */ printf("read %d bytes: %s, flags = %s\n", n, buff, Xti_flags_str(flags)); } }
int main(int argc, char **argv) { int sockfd, n, nq; char recvline[MAXLINE + 1]; socklen_t len; struct sockaddr_storage ss; if (argc != 3) err_quit("usage: a.out <hostname or IPaddress> <service or port#>"); sockfd = Udp_connect(argv[1], argv[2]); len = sizeof(ss); Getpeername(sockfd, (SA *)&ss, &len); printf("connected to %s\n", Sock_ntop_host((SA *)&ss, len)); Write(sockfd, "", 2); /* send 1-byte datagram */ n = Recv(sockfd, recvline, MAXLINE, MSG_PEEK); Ioctl(sockfd, FIONREAD, &nq); /* check FIONREAD support */ printf("%d bytes from PEEK, %d bytes pending\n", n, nq); n = Read(sockfd, recvline, MAXLINE); recvline[n] = 0; /* null terminate */ Fputs(recvline, stdout); exit(0); }
bool UsbDkRedirectorAccess::IoctlSync(DWORD Code, bool ShortBufferOk, LPVOID InBuffer, DWORD InBufferSize, LPVOID OutBuffer, DWORD OutBufferSize, LPDWORD BytesReturned) { UsbDkHandleHolder<HANDLE> Event(CreateEvent(nullptr, FALSE, FALSE, nullptr)); if (!Event) { throw UsbDkDriverFileException(TEXT("CreateEvent failed")); } OVERLAPPED Overlapped; Overlapped.hEvent = Event; auto res = Ioctl(Code, ShortBufferOk, InBuffer, InBufferSize, OutBuffer, OutBufferSize, BytesReturned, &Overlapped); switch (res) { case TransferSuccessAsync: DWORD NumberOfBytesTransferred; if (!GetOverlappedResult(m_hDriver, &Overlapped, &NumberOfBytesTransferred, TRUE)) { throw UsbDkDriverFileException(TEXT("GetOverlappedResult failed")); } return true; case TransferSuccess: return true; case TransferFailure: return false; } return false; }
int main(int argc, char **argv) { int sockfd, n, nq; char recvline[MAXLINE + 1]; socklen_t salen; struct sockaddr *sa; if (argc != 3) err_quit("usage: a.out <hostname or IPaddress> <service or port#>"); sockfd = Udp_client(argv[1], argv[2], (void **) &sa, &salen); printf("sending to %s\n", Sock_ntop_host(sa, salen)); Sendto(sockfd, "", 1, 0, sa, salen); /* send 1-byte datagram */ n = Recvfrom(sockfd, recvline, MAXLINE, MSG_PEEK, NULL, NULL); Ioctl(sockfd, FIONREAD, &nq); /* check FIONREAD support */ printf("%d bytes from PEEK, %d bytes pending\n", n, nq); n = Recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL); recvline[n] = 0; /* null terminate */ Fputs(recvline, stdout); exit(0); }
/* include dgecho2 */ void dg_echo(int sockfd_arg, SA *pcliaddr, socklen_t clilen_arg) { int i; const int on = 1; sigset_t zeromask, newmask, oldmask; sockfd = sockfd_arg; clilen = clilen_arg; for (i = 0; i < QSIZE; i++) { /* init queue of buffers */ dg[i].dg_data = Malloc(MAXDG); dg[i].dg_sa = Malloc(clilen); dg[i].dg_salen = clilen; } iget = iput = nqueue = 0; Signal(SIGHUP, sig_hup); Signal(SIGIO, sig_io); Fcntl(sockfd, F_SETOWN, getpid()); Ioctl(sockfd, FIOASYNC, &on); Ioctl(sockfd, FIONBIO, &on); Sigemptyset(&zeromask); /* init three signal sets */ Sigemptyset(&oldmask); Sigemptyset(&newmask); Sigaddset(&newmask, SIGIO); /* the signal we want to block */ Sigprocmask(SIG_BLOCK, &newmask, &oldmask); for ( ; ; ) { while (nqueue == 0) sigsuspend(&zeromask); /* wait for a datagram to process */ /* 4unblock SIGGIO */ Sigprocmask(SIG_SETMASK, &oldmask, NULL); Sendto(sockfd, dg[iget].dg_data, dg[iget].dg_len, 0, dg[iget].dg_sa, dg[iget].dg_salen); if (++iget >= QSIZE) iget = 0; /* 4block SIGIO */ Sigprocmask(SIG_BLOCK, &newmask, &oldmask); nqueue--; } }
bool SocketImpl::SetBlocking(bool flag) { int arg = flag ? 1 : 0; if (!Ioctl(FIONBIO, &arg)) return false; m_bBlocking = flag; return true; }
void str_cli(FILE* fp, int sockfd) { int stdineof; char buf[MAXLINE]; int n; int wfd; struct pollfd pollfd[2]; struct dvpoll dopoll; int i; int result; wfd = Open("/dev/poll", O_RDWR, 0); pollfd[0].fd = fileno(fp); pollfd[0].events = POLLIN; pollfd[0].revents = 0; pollfd[1].fd = sockfd; pollfd[1].events = POLLIN; pollfd[1].revents = 0; Write(wfd, pollfd, sizeof(struct pollfd) * 2); stdineof = 0; for (;;) { /* block until /dev/poll says something is ready */ dopoll.dp_timeout = -1; dopoll.dp_nfds = 2; dopoll.dp_fds = pollfd; result = Ioctl(wfd, DP_POLL, &dopoll); /* loop through ready file descriptors */ for (i = 0; i < result; i++) { if (dopoll.dp_fds[i].fd == sockfd) { /* socket is readable */ if ((n = Read(sockfd, buf, MAXLINE)) == 0) { if (stdineof == 1) return; /* normal termination */ else err_quit("str_cli: server terminated prematurely"); } Write(fileno(stdout), buf, n); } else { /* input is readable */ if ((n = Read(fileno(fp), buf, MAXLINE)) == 0) { stdineof = 1; Shutdown(sockfd, SHUT_WR); /* send FIN */ continue; } Writen(sockfd, buf, n); } } } }
TransferResult UsbDkRedirectorAccess::TransactPipe(USB_DK_TRANSFER_REQUEST &Request, DWORD OpCode, LPOVERLAPPED Overlapped) { static DWORD BytesTransferredDummy; auto res = Ioctl(OpCode, false, &Request, sizeof(Request), &Request.Result.GenResult, sizeof(Request.Result.GenResult), &BytesTransferredDummy, Overlapped); return res; }
int main(int argc, char *argv[]) { int fd, i, nmods; struct str_list list; if (argc != 2) err_quit("usage: a.out <pathname>"); fd = T_open(argv[1], O_RDWR, NULL); if (isastream(fd) == 0) err_quit("%s is not a stream", argv[1]); list.sl_nmods = nmods = Ioctl(fd, I_LIST, (void *) 0); printf("%d modules\n", nmods); list.sl_modlist = Calloc(nmods, sizeof(struct str_mlist)); Ioctl(fd, I_LIST, &list); for (i = 1; i <= nmods; i++) printf(" %s: %s\n", (i == nmods) ? "driver" : "module", list.sl_modlist++); exit(0); }
void select(TUint &bits0) { TRequestStatus rs; io.Wait(); int newbits = 0; TUint bits = bits0; if ((bits & KSockSelectRead) != 0) { ++select_reqs[0]; if (select_reqs[0] == 1) { newbits = 1; } } if ((bits & KSockSelectWrite) != 0) { ++select_reqs[1]; if (select_reqs[1] == 1) { newbits = 1; } } if ((bits & KSockSelectExcept) != 0) { ++select_reqs[2]; if (select_reqs[2] == 1) { newbits = 1; } } if (in_wait && newbits) { CancelIoctl(); } io.Signal(); do { int done = 0; TUint nbits = 0; io.Wait(); if (select_reqs[0]) { nbits |= KSockSelectRead; } if (select_reqs[1]) { nbits |= KSockSelectWrite; } if (select_reqs[2]) { nbits |= KSockSelectExcept; } TPckg<TUint> bits1(nbits); Ioctl(KIOctlSelect, rs, &bits1, KSOLSocket); // Ioctl(KIOctlSelect, rs, (TDes8 *)&x, KSOLSocket); in_wait = 1; io.Signal(); User::WaitForRequest(rs); if (rs == KErrNone) { assert(nbits == bits1()); if ((nbits & bits) != 0) { bits0 = nbits; done = 1; } } io.Wait(); in_wait = 0; io.Signal(); } while (rs == KErrCancel); io.Wait(); newbits = 0; if ((bits & KSockSelectRead) != 0) { --select_reqs[0]; if (select_reqs[0] == 0) { newbits = 1; } } if ((bits & KSockSelectWrite) != 0) { --select_reqs[1]; if (select_reqs[1] == 0) { newbits = 1; } } if ((bits & KSockSelectExcept) != 0) { --select_reqs[2]; if (select_reqs[2] == 0) { newbits = 1; } } if (in_wait && newbits) { CancelIoctl(); } io.Signal(); }
struct ifi_info * get_ifi_info(int family, int doaliases) { struct ifi_info *ifi, *ifihead, **ifipnext; int sockfd, len, lastlen, flags, myflags, idx = 0, hlen = 0; char *ptr, *buf, lastname[IFNAMSIZ], *cptr, *haddr, *sdlname; struct ifconf ifc; struct ifreq *ifr, ifrcopy; struct sockaddr_in *sinptr; struct sockaddr_in6 *sin6ptr; sockfd = my_socket(AF_INET, SOCK_DGRAM, 0); lastlen = 0; len = 100 * sizeof(struct ifreq); /* initial buffer size guess */ for ( ; ; ) { buf = my_malloc(len); ifc.ifc_len = len; ifc.ifc_buf = buf; if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) { if (errno != EINVAL || lastlen != 0) err_sys("ioctl error"); } else { if (ifc.ifc_len == lastlen) break; /* success, len has not changed */ lastlen = ifc.ifc_len; } len += 10 * sizeof(struct ifreq); /* increment */ free(buf); } ifihead = NULL; ifipnext = &ifihead; lastname[0] = 0; sdlname = NULL; /* end get_ifi_info1 */ /* include get_ifi_info2 */ for (ptr = buf; ptr < buf + ifc.ifc_len; ) { ifr = (struct ifreq *) ptr; #ifdef HAVE_SOCKADDR_SA_LEN len = max(sizeof(struct sockaddr), ifr->ifr_addr.sa_len); #else switch (ifr->ifr_addr.sa_family) { #ifdef IPV6 case AF_INET6: len = sizeof(struct sockaddr_in6); break; #endif case AF_INET: default: len = sizeof(struct sockaddr); break; } #endif /* HAVE_SOCKADDR_SA_LEN */ ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ #ifdef HAVE_SOCKADDR_DL_STRUCT /* assumes that AF_LINK precedes AF_INET or AF_INET6 */ if (ifr->ifr_addr.sa_family == AF_LINK) { struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr; sdlname = ifr->ifr_name; idx = sdl->sdl_index; haddr = sdl->sdl_data + sdl->sdl_nlen; hlen = sdl->sdl_alen; } #endif if (ifr->ifr_addr.sa_family != family) continue; /* ignore if not desired address family */ myflags = 0; if ( (cptr = strchr(ifr->ifr_name, ':')) != NULL) *cptr = 0; /* replace colon with null */ if (strncmp(lastname, ifr->ifr_name, IFNAMSIZ) == 0) { if (doaliases == 0) continue; /* already processed this interface */ myflags = IFI_ALIAS; } memcpy(lastname, ifr->ifr_name, IFNAMSIZ); ifrcopy = *ifr; my_ioctl(sockfd, SIOCGIFFLAGS, &ifrcopy); flags = ifrcopy.ifr_flags; if ((flags & IFF_UP) == 0) continue; /* ignore if interface not up */ /* end get_ifi_info2 */ /* include get_ifi_info3 */ ifi = my_calloc(1, sizeof(struct ifi_info)); *ifipnext = ifi; /* prev points to this new one */ ifipnext = &ifi->ifi_next; /* pointer to next one goes here */ ifi->ifi_flags = flags; /* IFF_xxx values */ ifi->ifi_myflags = myflags; /* IFI_xxx values */ #if defined(SIOCGIFMTU) && defined(HAVE_STRUCT_IFREQ_IFR_MTU) Ioctl(sockfd, SIOCGIFMTU, &ifrcopy); ifi->ifi_mtu = ifrcopy.ifr_mtu; #else ifi->ifi_mtu = 0; #endif memcpy(ifi->ifi_name, ifr->ifr_name, IFI_NAME); ifi->ifi_name[IFI_NAME-1] = '\0'; /* If the sockaddr_dl is from a different interface, ignore it */ if (sdlname == NULL || strcmp(sdlname, ifr->ifr_name) != 0) idx = hlen = 0; ifi->ifi_index = idx; ifi->ifi_hlen = hlen; if (ifi->ifi_hlen > IFI_HADDR) ifi->ifi_hlen = IFI_HADDR; if (hlen) memcpy(ifi->ifi_haddr, haddr, ifi->ifi_hlen); /* end get_ifi_info3 */ /* include get_ifi_info4 */ switch (ifr->ifr_addr.sa_family) { case AF_INET: sinptr = (struct sockaddr_in *) &ifr->ifr_addr; ifi->ifi_addr = my_calloc(1, sizeof(struct sockaddr_in)); memcpy(ifi->ifi_addr, sinptr, sizeof(struct sockaddr_in)); #ifdef SIOCGIFBRDADDR if (flags & IFF_BROADCAST) { my_ioctl(sockfd, SIOCGIFBRDADDR, &ifrcopy); sinptr = (struct sockaddr_in *) &ifrcopy.ifr_broadaddr; ifi->ifi_brdaddr = my_calloc(1, sizeof(struct sockaddr_in)); memcpy(ifi->ifi_brdaddr, sinptr, sizeof(struct sockaddr_in)); } #endif #ifdef SIOCGIFDSTADDR if (flags & IFF_POINTOPOINT) { my_ioctl(sockfd, SIOCGIFDSTADDR, &ifrcopy); sinptr = (struct sockaddr_in *) &ifrcopy.ifr_dstaddr; ifi->ifi_dstaddr = my_calloc(1, sizeof(struct sockaddr_in)); memcpy(ifi->ifi_dstaddr, sinptr, sizeof(struct sockaddr_in)); } #endif break; case AF_INET6: sin6ptr = (struct sockaddr_in6 *) &ifr->ifr_addr; ifi->ifi_addr = my_calloc(1, sizeof(struct sockaddr_in6)); memcpy(ifi->ifi_addr, sin6ptr, sizeof(struct sockaddr_in6)); #ifdef SIOCGIFDSTADDR if (flags & IFF_POINTOPOINT) { my_ioctl(sockfd, SIOCGIFDSTADDR, &ifrcopy); sin6ptr = (struct sockaddr_in6 *) &ifrcopy.ifr_dstaddr; ifi->ifi_dstaddr = my_calloc(1, sizeof(struct sockaddr_in6)); memcpy(ifi->ifi_dstaddr, sin6ptr, sizeof(struct sockaddr_in6)); } #endif break; default: break; } } free(buf); return(ifihead); /* pointer to first structure in linked list */ }
/* analyze a file descriptor */ int filan_fd(int fd, FILE *outfile) { #if HAVE_STAT64 struct stat64 buf = {0}; #else struct stat buf = {0}; #endif /* !HAVE_STAT64 */ int result; Debug1("checking file descriptor %u", fd); #if HAVE_STAT64 result = Fstat64(fd, &buf); #else result = Fstat(fd, &buf); #endif /* !HAVE_STAT64 */ if (result < 0) { if (errno == EBADF) { Debug2("fstat(%d): %s", fd, strerror(errno)); } else { Warn2("fstat(%d): %s", fd, strerror(errno)); } return -1; } Debug2("fd %d is a %s", fd, getfiletypestring(buf.st_mode)); result = filan_stat(&buf, fd, fd, outfile); if (result >= 0) { /* even more dynamic info */ { /* see if data is available */ struct pollfd ufds; ufds.fd = fd; ufds.events = POLLIN|POLLPRI|POLLOUT #ifdef POLLRDNORM |POLLRDNORM #endif #ifdef POLLRDBAND |POLLRDBAND #endif |POLLWRNORM #ifdef POLLWRBAND |POLLWRBAND #endif #ifdef POLLMSG |POLLMSG #endif ; if (Poll(&ufds, 1, 0) < 0) { Warn4("poll({%d, %hd, %hd}, 1, 0): %s", ufds.fd, ufds.events, ufds.revents, strerror(errno)); } else { fputs("poll: ", outfile); if (ufds.revents & POLLIN) fputs("IN,", outfile); if (ufds.revents & POLLPRI) fputs("PRI,", outfile); if (ufds.revents & POLLOUT) fputs("OUT,", outfile); if (ufds.revents & POLLERR) fputs("ERR,", outfile); if (ufds.revents & POLLNVAL) fputs("NVAL,", outfile); #ifdef FIONREAD if (ufds.revents & POLLIN) { size_t sizet; if ((result = Ioctl(fd, FIONREAD, &sizet) >= 0)) { fprintf (outfile, "; FIONREAD="F_Zu, sizet); } } #endif /* defined(FIONREAD) */ #if _WITH_SOCKET && defined(MSG_DONTWAIT) if ((ufds.revents & POLLIN) && isasocket(fd)) { char _peername[SOCKADDR_MAX]; struct sockaddr *pa = (struct sockaddr *)_peername; struct msghdr msgh = {0}; char peekbuff[1]; /* [0] fails with some compilers */ #if HAVE_STRUCT_IOVEC struct iovec iovec; #endif char ctrlbuff[5120]; ssize_t bytes; fputs("; ", outfile); msgh.msg_name = pa; msgh.msg_namelen = sizeof(*pa); #if HAVE_STRUCT_IOVEC iovec.iov_base = peekbuff; iovec.iov_len = sizeof(peekbuff); msgh.msg_iov = &iovec; msgh.msg_iovlen = 1; #endif #if HAVE_STRUCT_MSGHDR_MSGCONTROL msgh.msg_control = ctrlbuff; #endif #if HAVE_STRUCT_MSGHDR_MSGCONTROLLEN msgh.msg_controllen = sizeof(ctrlbuff); #endif #if HAVE_STRUCT_MSGHDR_MSGFLAGS msgh.msg_flags = 0; #endif if ((bytes = Recvmsg(fd, &msgh, MSG_PEEK|MSG_DONTWAIT)) < 0) { Warn1("recvmsg(): %s", strerror(errno)); } else { fprintf(outfile, "recvmsg="F_Zd", ", bytes); } } #endif /* _WITH_SOCKET && defined(MSG_DONTWAIT) */ } } } fputc('\n', outfile); return 0; }
int SocketImpl::GetAvailableBytes() { int value; Ioctl(FIONREAD, &value); return value; }
struct hwa_info * get_hw_addrs() { struct hwa_info *hwa, *hwahead, **hwapnext; int sockfd, len, lastlen, alias; char *ptr, *buf, lastname[IF_NAME], *cptr; struct ifconf ifc; struct ifreq *ifr, ifrcopy; struct sockaddr *sinptr; sockfd = Socket(AF_INET, SOCK_DGRAM, 0); lastlen = 0; len = 100 * sizeof(struct ifreq); /* initial buffer size guess */ for ( ; ; ) { buf = (char*) Malloc(len); ifc.ifc_len = len; ifc.ifc_buf = buf; if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) { if (errno != EINVAL || lastlen != 0) err_sys("ioctl error"); } else { if (ifc.ifc_len == lastlen) break; /* success, len has not changed */ lastlen = ifc.ifc_len; } len += 10 * sizeof(struct ifreq); /* increment */ free(buf); } hwahead = NULL; hwapnext = &hwahead; lastname[0] = 0; for (ptr = buf; ptr < buf + ifc.ifc_len; ) { ifr = (struct ifreq *) ptr; len = sizeof(struct sockaddr); ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ alias = 0; hwa = (struct hwa_info *) Calloc(1, sizeof(struct hwa_info)); memcpy(hwa->if_name, ifr->ifr_name, IF_NAME); /* interface name */ hwa->if_name[IF_NAME-1] = '\0'; /* start to check if alias address */ if ( (cptr = (char *) strchr(ifr->ifr_name, ':')) != NULL) *cptr = 0; /* replace colon will null */ if (strncmp(lastname, ifr->ifr_name, IF_NAME) == 0) { alias = IP_ALIAS; } memcpy(lastname, ifr->ifr_name, IF_NAME); ifrcopy = *ifr; *hwapnext = hwa; /* prev points to this new one */ hwapnext = &hwa->hwa_next; /* pointer to next one goes here */ hwa->ip_alias = alias; /* alias IP address flag: 0 if no; 1 if yes */ sinptr = &ifr->ifr_addr; hwa->ip_addr = (struct sockaddr *) Calloc(1, sizeof(struct sockaddr)); memcpy(hwa->ip_addr, sinptr, sizeof(struct sockaddr)); /* IP address */ Ioctl(sockfd, SIOCGIFHWADDR, &ifrcopy); /* get hw address */ memcpy(hwa->if_haddr, ifrcopy.ifr_hwaddr.sa_data, IF_HADDR); Ioctl(sockfd, SIOCGIFINDEX, &ifrcopy); /* get interface index */ memcpy(&hwa->if_index, &ifrcopy.ifr_ifindex, sizeof(int)); } free(buf); return(hwahead); /* pointer to first structure in linked list */ }
static int xioopen_tun(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xfd, unsigned groups, int dummy1, int dummy2, int dummy3) { char *tundevice = NULL; char *tunname = NULL, *tuntype = NULL; int pf = /*! PF_UNSPEC*/ PF_INET; struct xiorange network; bool no_pi = false; const char *namedargv[] = { "tun", NULL, NULL }; int rw = (xioflags & XIO_ACCMODE); bool exists; struct ifreq ifr; int sockfd; char *ifaddr; int result; if (argc > 2 || argc < 0) { Error2("%s: wrong number of parameters (%d instead of 0 or 1)", argv[0], argc-1); } if (retropt_string(opts, OPT_TUN_DEVICE, &tundevice) != 0) { tundevice = strdup("/dev/net/tun"); } /*! socket option here? */ retropt_socket_pf(opts, &pf); namedargv[1] = tundevice; /* open the tun cloning device */ if ((result = _xioopen_named_early(2, namedargv, xfd, groups, &exists, opts)) < 0) { return result; } /*========================= the tunnel interface =========================*/ Notice("creating tunnel network interface"); if ((result = _xioopen_open(tundevice, rw, opts)) < 0) return result; xfd->stream.fd = result; /* prepare configuration of the new network interface */ memset(&ifr, 0,sizeof(ifr)); if (retropt_string(opts, OPT_TUN_NAME, &tunname) == 0) { strncpy(ifr.ifr_name, tunname, IFNAMSIZ); /* ok */ free(tunname); } else { ifr.ifr_name[0] = '\0'; } ifr.ifr_flags = IFF_TUN; if (retropt_string(opts, OPT_TUN_TYPE, &tuntype) == 0) { if (!strcmp(tuntype, "tap")) { ifr.ifr_flags = IFF_TAP; } else if (strcmp(tuntype, "tun")) { Error1("unknown tun-type \"%s\"", tuntype); } } if (retropt_bool(opts, OPT_IFF_NO_PI, &no_pi) == 0) { if (no_pi) { ifr.ifr_flags |= IFF_NO_PI; #if 0 /* not neccessary for now */ } else { ifr.ifr_flags &= ~IFF_NO_PI; #endif } } if (Ioctl(xfd->stream.fd, TUNSETIFF, &ifr) < 0) { Error3("ioctl(%d, TUNSETIFF, {\"%s\"}: %s", xfd->stream.fd, ifr.ifr_name, strerror(errno)); Close(xfd->stream.fd); } /*===================== setting interface properties =====================*/ /* we seem to need a socket for manipulating the interface */ if ((sockfd = Socket(PF_INET, SOCK_DGRAM, 0)) < 0) { Error1("socket(PF_INET, SOCK_DGRAM, 0): %s", strerror(errno)); sockfd = xfd->stream.fd; /* desparate fallback attempt */ } /*--------------------- setting interface address and netmask ------------*/ if (argc == 2) { if ((ifaddr = strdup(argv[1])) == NULL) { Error1("strdup(\"%s\"): out of memory", argv[1]); return STAT_RETRYLATER; } if ((result = xioparsenetwork(ifaddr, pf, &network)) != STAT_OK) { /*! recover */ return result; } socket_init(pf, (union sockaddr_union *)&ifr.ifr_addr); ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr = network.netaddr.ip4.sin_addr; if (Ioctl(sockfd, SIOCSIFADDR, &ifr) < 0) { Error4("ioctl(%d, SIOCSIFADDR, {\"%s\", \"%s\"}: %s", sockfd, ifr.ifr_name, ifaddr, strerror(errno)); } ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr = network.netmask.ip4.sin_addr; if (Ioctl(sockfd, SIOCSIFNETMASK, &ifr) < 0) { Error4("ioctl(%d, SIOCSIFNETMASK, {\"0x%08u\", \"%s\"}, %s", sockfd, ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr, ifaddr, strerror(errno)); } free(ifaddr); } /*--------------------- setting interface flags --------------------------*/ applyopts_single(&xfd->stream, opts, PH_FD); if (Ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) { Error3("ioctl(%d, SIOCGIFFLAGS, {\"%s\"}: %s", sockfd, ifr.ifr_name, strerror(errno)); } Debug2("\"%s\": system set flags: 0x%hx", ifr.ifr_name, ifr.ifr_flags); ifr.ifr_flags |= xfd->stream.para.tun.iff_opts[0]; ifr.ifr_flags &= ~xfd->stream.para.tun.iff_opts[1]; Debug2("\"%s\": xio merged flags: 0x%hx", ifr.ifr_name, ifr.ifr_flags); if (Ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) { Error4("ioctl(%d, SIOCSIFFLAGS, {\"%s\", %hd}: %s", sockfd, ifr.ifr_name, ifr.ifr_flags, strerror(errno)); } ifr.ifr_flags = 0; if (Ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) { Error3("ioctl(%d, SIOCGIFFLAGS, {\"%s\"}: %s", sockfd, ifr.ifr_name, strerror(errno)); } Debug2("\"%s\": resulting flags: 0x%hx", ifr.ifr_name, ifr.ifr_flags); #if LATER applyopts_named(tundevice, opts, PH_FD); #endif applyopts(xfd->stream.fd, opts, PH_FD); applyopts_cloexec(xfd->stream.fd, opts); applyopts_fchown(xfd->stream.fd, opts); if ((result = _xio_openlate(&xfd->stream, opts)) < 0) return result; return 0; }
// PlayTask - output some sounds void PlayTask(void* pdata) { INT8U err; HANDLE hSpi; //handle to SPI driver HANDLE hMp3; //handle to MP3 driver INT32U length; const INT8U SineWave[] = {0x53, 0xEF, 0x6E, 0x44, 0x00, 0x00, 0x00, 0x00}; const INT8U Deact[] = {0x45, 0x78, 0x69, 0x74, 0x00, 0x00, 0x00, 0x00}; const INT8U ModeTest[] = {0x02, 0x00, 0x08, 0x20}; const INT8U ModePlay[] = {0x02, 0x00, 0x08, 0x00}; const INT8U SoftReset[] = {0x02, 0x00, 0x08, 0x04}; INT32U DataMode = 1; INT32U ii; BOOLEAN start; OSSemPend(SemPrint, 0, &err); DEBUGMSG(1,("PlayTask: begin\n\r")); OSSemPost(SemPrint); //set states as we go along so we track CPU uasge better State = 1; //get a handles to the SPI and MP3 drivers hSpi = Open(SPI_DRV1, OSDRV_WRITE |OSDRV_EXCLUSIVE); if (hSpi == OS_DRV_INVALID_HANDLE) { DEBUGMSG(1,("PlayTask: failed to open SPI driver\n\r")); OSTaskDel(OS_PRIO_SELF); } hMp3 = Open(MP3_DRV0, OSDRV_WRITE |OSDRV_EXCLUSIVE); if (hMp3 == OS_DRV_INVALID_HANDLE) { DEBUGMSG(1,("PlayTask: failed to open MP3 driver\n\r")); OSTaskDel(OS_PRIO_SELF); } //tell the MP3 driver which SPI port driver to use length = sizeof(HANDLE); err = Ioctl(hMp3, IOCTL_MP3_SET_SPI, &hSpi, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed to set SPI port to open MP3 driver, err: %d\n\r", err)); OSTaskDel(OS_PRIO_SELF); } //reset the MP3 chip length = sizeof(SoftReset); memcpy(buffer, SoftReset, length); err = Write(hMp3, buffer, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed write, err: %d\n\r", err)); OSTaskDel(OS_PRIO_SELF); } #if PLAY_SINE_TEST //allow tests length = sizeof(ModeTest); memcpy(buffer, ModeTest, length); err = Write(hMp3, buffer, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed write, err: %d\n\r", err)); OSTaskDel(OS_PRIO_SELF); } //set to data mode DataMode = 1; length = sizeof(DataMode); err = Ioctl(hMp3, IOCTL_MP3_SET_DATA_MODE, &DataMode, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed to set data mode, err: %d\n\r", err)); OSTaskDel(OS_PRIO_SELF); } State = 2; OSSemPend(SemPrint, 0, &err); DEBUGMSG(1,("PlayTask: playing\n\r")); OSSemPost(SemPrint); for(ii = 0; ii < 3; ii++) { State = 3; //play test sound (note, first time through the chip may not play) length = sizeof(SineWave); memcpy(buffer, SineWave, length); err = Write(hMp3, buffer, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed write, err: %d\n\r", err)); OSTaskDel(OS_PRIO_SELF); } SetLED(0); OSTimeDlyHMSM(0, 0, 10, 000); OSSemPend(SemPrint, 0, &err); DEBUGMSG(1,("PlayTask: stopping\n\r")); OSSemPost(SemPrint); //stop length = sizeof(Deact); memcpy(buffer, Deact, length); err = Write(hMp3, buffer, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed write, err: %d\n\r", err)); OSTaskDel(OS_PRIO_SELF); } SetLED(1); OSTimeDlyHMSM(0, 0, 4, 000); } #endif //PLAY_SINE_TEST State = 4; //set to cmd mode DataMode = 0; length = sizeof(DataMode); err = Ioctl(hMp3, IOCTL_MP3_SET_DATA_MODE, &DataMode, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed to set data mode, err: %d\n\r", err)); OSTaskDel(OS_PRIO_SELF); } //set to play mode length = sizeof(ModePlay); memcpy(buffer, ModePlay, length); err = Write(hMp3, buffer, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed write, err: %d\n\r", err)); OSTaskDel(OS_PRIO_SELF); } //set to data mode DataMode = 1; length = sizeof(DataMode); err = Ioctl(hMp3, IOCTL_MP3_SET_DATA_MODE, &DataMode, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed to set data mode, err: %d\n\r", err)); OSTaskDel(OS_PRIO_SELF); } //loop though the data until done start = TRUE; while(TRUE) { INT32U len; State = 5; len = GetMP3(buffer, MP3BUFFERSIZE, start); start = FALSE; SetLED(1); if (len > 0) { length = len; err = Write(hMp3, buffer, &length); if (err != OS_DRV_NO_ERR) { DEBUGMSG(1,("PlayTask: failed write, err: %d\n\r", err)); while(TRUE); //park here on error } } SetLED(0); if (len < MP3BUFFERSIZE) { //we are done with file #ifdef CONTINUOUS start = TRUE; OSSemPend(SemPrint, 0, &err); DEBUGMSG(1,("PlayTask: restarting\n\r")); OSSemPost(SemPrint); #else //CONTINUOUS break; #endif //CONTINUOUS } } State = 6; OSSemPend(SemPrint, 0, &err); DEBUGMSG(1,("PlayTask: exiting\n\r")); OSSemPost(SemPrint); OSTaskDel(OS_PRIO_SELF); }
TVerdict CTestSyscalls::doTestStepL() { int err; if(TestStepName() == KCreat) { INFO_PRINTF1(_L("Creat():")); err = Creat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen1) { INFO_PRINTF1(_L("open1():")); err = open1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen2) { INFO_PRINTF1(_L("open2():")); err = open2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen3) { INFO_PRINTF1(_L("open3():")); err = open3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen4) { INFO_PRINTF1(_L("open4():")); err = open4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen5) { INFO_PRINTF1(_L("open5():")); err = open5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen6) { INFO_PRINTF1(_L("open6():")); err = open6(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenTruncate1) { INFO_PRINTF1(_L("OpenTruncate1:")); err = OpenTruncate1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenTruncate2) { INFO_PRINTF1(_L("OpenTruncate2:")); err = OpenTruncate2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen7) { INFO_PRINTF1(_L("open7():")); err = open7(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenInAppendMode) { INFO_PRINTF1(_L("OpenInAppendMode():")); err = OpenInAppendMode(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite1) { INFO_PRINTF1(_L("write1():")); err = write1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite2) { INFO_PRINTF1(_L("write2():")); err = write2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite3) { INFO_PRINTF1(_L("write3():")); err = write3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite5) { INFO_PRINTF1(_L("write5():")); err = write5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread1) { INFO_PRINTF1(_L("read1():")); err = read1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread2) { INFO_PRINTF1(_L("read2():")); err = read2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread3) { INFO_PRINTF1(_L("read3():")); err = read3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread4) { INFO_PRINTF1(_L("read4():")); err = read4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpendir) { INFO_PRINTF1(_L("Opendir():")); err = Opendir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClosedir) { INFO_PRINTF1(_L("Closedir():")); err = Closedir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReaddir) { INFO_PRINTF1(_L("Readdir():")); err = Readdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseek) { INFO_PRINTF1(_L("Lseek():")); err = Lseek(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseek1) { INFO_PRINTF1(_L("Lseek1():")); err = Lseek1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KAccess) { INFO_PRINTF1(_L("Access():")); err = Access(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KAccess1) { INFO_PRINTF1(_L("Access1():")); err = Access1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KDup) { INFO_PRINTF1(_L("Dup():")); err = Dup(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KDup2) { INFO_PRINTF1(_L("Dup2():")); err = Dup2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename) { INFO_PRINTF1(_L("Rename():")); err = Rename(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename1) { INFO_PRINTF1(_L("Rename1():")); err = Rename1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod) { INFO_PRINTF1(_L("Chmod():")); err = Chmod(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod1) { INFO_PRINTF1(_L("Chmod1():")); err = Chmod1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod_dir) { INFO_PRINTF1(_L("Chmod_dir():")); err = Chmod_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFChmod) { INFO_PRINTF1(_L("FChmod():")); err = FChmod(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFChmod_dir) { INFO_PRINTF1(_L("FChmod_dir():")); err = FChmod_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KExit) { INFO_PRINTF1(_L("Exit():")); err = Exit(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClose) { INFO_PRINTF1(_L("Close():")); err = Close(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir) { INFO_PRINTF1(_L("Mkdir():")); err = Mkdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMk_dir) { INFO_PRINTF1(_L("Mk_dir():")); err = Mk_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir) { INFO_PRINTF1(_L("Rmdir():")); err = Rmdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRm_dir) { INFO_PRINTF1(_L("Rm_dir():")); err = Rm_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir1) { INFO_PRINTF1(_L("Rmdir1():")); err = Rmdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir_Chdir) { INFO_PRINTF1(_L("Rmdir_Chdir():")); err = Rmdir_Chdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFsync) { INFO_PRINTF1(_L("Fsync():")); err = Fsync(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes) { INFO_PRINTF1(_L("Utimes():")); err = Utimes(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtime) { INFO_PRINTF1(_L("Utime():")); err = Utime(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir) { INFO_PRINTF1(_L("Chdir():")); err = Chdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFcntl) { INFO_PRINTF1(_L("Fcntl():")); err = Fcntl(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KIoctl) { INFO_PRINTF1(_L("Ioctl():")); err = Ioctl(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFstat) { INFO_PRINTF1(_L("Fstat():")); err = Fstat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat) { INFO_PRINTF1(_L("Stat():")); err = Stat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat1) { INFO_PRINTF1(_L("Stat1():")); err = Stat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat2) { INFO_PRINTF1(_L("Stat2():")); err = Stat2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat3) { INFO_PRINTF1(_L("Stat3():")); err = Stat3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KGetpid) { INFO_PRINTF1(_L("Getpid():")); err = Getpid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClock) { INFO_PRINTF1(_L("Clock():")); err = Clock(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTime) { INFO_PRINTF1(_L("Time():")); err = Time(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaitPid) { INFO_PRINTF1(_L("WaitPid():")); err = WaitPid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReadV) { INFO_PRINTF1(_L("ReadV():")); err = ReadV(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWriteV) { INFO_PRINTF1(_L("WriteV():")); err = WriteV(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KSleep) { INFO_PRINTF1(_L("Sleep():")); err = Sleep(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KSeekDir) { INFO_PRINTF1(_L("SeekDir():")); err = SeekDir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRewindDir) { INFO_PRINTF1(_L("RewindDir():")); err = RewindDir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTelldir) { INFO_PRINTF1(_L("Telldir():")); err = Telldir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTestClock) { INFO_PRINTF1(_L("TestClock():")); err = TestClock(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KCreat2) { INFO_PRINTF1(_L("Creat2():")); err = Creat2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen8) { INFO_PRINTF1(_L("open8():")); err = open8(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTestStat) { INFO_PRINTF1(_L("KTestStat():")); err = TestStat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseekttytest1) { INFO_PRINTF1(_L("Lseekttytest1():")); err = Lseekttytest1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseekttytest2) { INFO_PRINTF1(_L("Lseekttytest2():")); err = Lseekttytest2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaitPidtest) { INFO_PRINTF1(_L("WaitPidtest():")); err = WaitPidtest(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaittest) { INFO_PRINTF1(_L("Waittest():")); err = Waittest(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpen_FileDes_Test) { INFO_PRINTF1(_L("Open_FileDes_Test():")); err = Open_FileDes_Test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopenuid) { INFO_PRINTF1(_L("openuid():")); err = openuid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir1) { INFO_PRINTF1(_L("Mkdir1():")); err = Mkdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir2) { INFO_PRINTF1(_L("Mkdir2():")); err = Mkdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename2) { INFO_PRINTF1(_L("Rename2():")); err = Rename2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestfsync) { INFO_PRINTF1(_L("testfsync():")); err = testfsync(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestrename) { INFO_PRINTF1(_L("testrename():")); err = testrename(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestopenvalidate) { INFO_PRINTF1(_L("testopenvalidate():")); err = testopenvalidate(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ksync_safe) { INFO_PRINTF1(_L("sync_safe():")); err = sync_safe(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFstat1) { INFO_PRINTF1(_L("Fstat1():")); err = Fstat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes1) { INFO_PRINTF1(_L("Utimes1():")); err = Utimes1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir_test1) { INFO_PRINTF1(_L("Mkdir_test1():")); err = Mkdir_test1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod_test) { INFO_PRINTF1(_L("Chmod_test():")); err = Chmod_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir1) { INFO_PRINTF1(_L("Chdir1():")); err = Chdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir2) { INFO_PRINTF1(_L("Rmdir2():")); err = Rmdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename_test) { INFO_PRINTF1(_L("Rename_test():")); err = Rename_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename3) { INFO_PRINTF1(_L("Rename3():")); err = Rename3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KCreat1) { INFO_PRINTF1(_L("Creat1():")); err = Creat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReadV1) { INFO_PRINTF1(_L("ReadV1():")); err = ReadV1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes2) { INFO_PRINTF1(_L("Utimes2():")); err = Utimes2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat_test) { INFO_PRINTF1(_L("Stat_test():")); err = Stat_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir_test2) { INFO_PRINTF1(_L("Mkdir_test2():")); err = Mkdir_test2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod2) { INFO_PRINTF1(_L("Chmod2():")); err = Chmod2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir2) { INFO_PRINTF1(_L("Chdir2():")); err = Chdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename4) { INFO_PRINTF1(_L("Rename4():")); err = Rename4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename5) { INFO_PRINTF1(_L("Rename5():")); err = Rename5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir3) { INFO_PRINTF1(_L("Rmdir3():")); err = Rmdir3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread5) { INFO_PRINTF1(_L("read5():")); err = read5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } return TestStepResult(); }
struct myinfo * get_myinfo() { struct myinfo *ifi, *ifihead, **ifipnext; int sockfd, len, lastlen, flags; char *ptr, *buf, lastname[IFNAMSIZ], *cptr; struct ifconf ifc; struct ifreq *ifr, ifrcopy; struct sockaddr_in *sinptr; //, servaddr; char *maddr, *iaddr, *sbaddr; struct in_addr tmpaddr, tmpaddr1, tmpaddr2; sockfd = Socket(AF_INET, SOCK_DGRAM, 0); lastlen = 0; len = 100 * sizeof(struct ifreq); /* initial buffer size guess */ for ( ; ; ) { buf = Malloc(len); ifc.ifc_len = len; ifc.ifc_buf = buf; if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) { if (errno != EINVAL || lastlen != 0) err_sys("ioctl error"); } else { if (ifc.ifc_len == lastlen) break; /* success, len has not changed */ lastlen = ifc.ifc_len; } len += 10 * sizeof(struct ifreq); /* increment */ free(buf); } ifihead = NULL; ifipnext = &ifihead; lastname[0] = 0; /* include get_ifi_info2 */ for (ptr = buf; ptr < buf + ifc.ifc_len; ) { ifr = (struct ifreq *) ptr; #ifdef HAVE_SOCKADDR_SA_LEN len = max(sizeof(struct sockaddr), ifr->ifr_addr.sa_len); #else switch (ifr->ifr_addr.sa_family) { #ifdef IPV6 case AF_INET6: len = sizeof(struct sockaddr_in6); break; #endif case AF_INET: default: len = sizeof(struct sockaddr); break; } #endif /* HAVE_SOCKADDR_SA_LEN */ ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ if (ifr->ifr_addr.sa_family != AF_INET) continue; /* ignore if not desired address family */ if ( (cptr = strchr(ifr->ifr_name, ':')) != NULL) *cptr = 0; /* replace colon with null */ memcpy(lastname, ifr->ifr_name, IFNAMSIZ); ifrcopy = *ifr; Ioctl(sockfd, SIOCGIFFLAGS, &ifrcopy); flags = ifrcopy.ifr_flags; if ((flags & IFF_UP) == 0) continue; /* ignore if interface not up */ /* end get_ifi_info2 */ /* include get_ifi_info3 */ ifi = Calloc(1, sizeof(struct myinfo)); *ifipnext = ifi; /* prev points to this new one */ ifipnext = &ifi->next; /* pointer to next one goes here */ sinptr = (struct sockaddr_in *) &ifr->ifr_addr; ifi->ipaddr = Calloc(1, sizeof(struct sockaddr_in)); memcpy(ifi->ipaddr, sinptr, sizeof(struct sockaddr_in)); ////////////////////bind socket /* bzero(&servaddr,sizeof(servaddr)); saddr= inet_ntoa(((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr); ifi->udpfd = Socket(AF_INET, SOCK_DGRAM, 0); servaddr.sin_family= AF_INET; Inet_pton(AF_INET, saddr, &servaddr.sin_addr); servaddr.sin_port= htons(1234); Bind(ifi->udpfd, (SA *) &servaddr, sizeof(servaddr));*/ //////////////////////////////////////////////////////// #ifdef SIOCGIFNETMASK Ioctl(sockfd, SIOCGIFNETMASK, &ifrcopy); sinptr = (struct sockaddr_in *) &ifrcopy.ifr_addr; ifi->maskaddr = Calloc(1, sizeof(struct sockaddr_in)); memcpy(ifi->maskaddr, sinptr, sizeof(struct sockaddr_in)); #endif //get subnet address tmpaddr.s_addr= NULL; iaddr= Sock_ntop_host(ifi->ipaddr, sizeof(*ifi->ipaddr)); maddr=inet_ntoa(((struct sockaddr_in *) ifi->maskaddr)->sin_addr); inet_aton(iaddr, &tmpaddr1); //string to in_addr inet_aton(maddr, &tmpaddr2); tmpaddr.s_addr= tmpaddr1.s_addr & tmpaddr2.s_addr; sbaddr= inet_ntoa(tmpaddr); strcpy(ifi->subnetaddr, sbaddr); } free(buf); return(ifihead); /* pointer to first structure in linked list */ }