这篇教程C++ sysconf函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中sysconf函数的典型用法代码示例。如果您正苦于以下问题:C++ sysconf函数的具体用法?C++ sysconf怎么用?C++ sysconf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了sysconf函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: _prop_object_internalize_map_file/* * _prop_object_internalize_map_file -- * Map a file for the purpose of internalizing it. */struct _prop_object_internalize_mapped_file *_prop_object_internalize_map_file(const char *fname){ struct stat sb; struct _prop_object_internalize_mapped_file *mf; size_t pgsize = (size_t)sysconf(_SC_PAGESIZE); size_t pgmask = pgsize - 1; bool need_guard = false; int fd; mf = _PROP_MALLOC(sizeof(*mf), M_TEMP); if (mf == NULL) return (NULL); fd = open(fname, O_RDONLY, 0400); if (fd == -1) { _PROP_FREE(mf, M_TEMP); return (NULL); } if (fstat(fd, &sb) == -1) { (void) close(fd); _PROP_FREE(mf, M_TEMP); return (NULL); } mf->poimf_mapsize = ((size_t)sb.st_size + pgmask) & ~pgmask; if (mf->poimf_mapsize < (size_t)sb.st_size) { (void) close(fd); _PROP_FREE(mf, M_TEMP); return (NULL); } /* * If the file length is an integral number of pages, then we * need to map a guard page at the end in order to provide the * necessary NUL-termination of the buffer. */ if ((sb.st_size & pgmask) == 0) need_guard = true; mf->poimf_xml = mmap(NULL, need_guard ? mf->poimf_mapsize + pgsize : mf->poimf_mapsize, PROT_READ, MAP_FILE|MAP_SHARED, fd, (off_t)0); (void) close(fd); if (mf->poimf_xml == MAP_FAILED) { _PROP_FREE(mf, M_TEMP); return (NULL); } (void) madvise(mf->poimf_xml, mf->poimf_mapsize, MADV_SEQUENTIAL); if (need_guard) { if (mmap(mf->poimf_xml + mf->poimf_mapsize, pgsize, PROT_READ, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, (off_t)0) == MAP_FAILED) { (void) munmap(mf->poimf_xml, mf->poimf_mapsize); _PROP_FREE(mf, M_TEMP); return (NULL); } mf->poimf_mapsize += pgsize; } return (mf);}
开发者ID:prodigeni,项目名称:xbps,代码行数:68,
示例2: page_alignstatic inline size_tpage_align(size_t size){ size_t page_size = sysconf(_SC_PAGE_SIZE); return (size + page_size - 1) & ~(page_size - 1);}
开发者ID:MarkSymsCtx,项目名称:blktap,代码行数:6,
示例3: mainint main(void){ char c; int err, shmid; char *shm, *s; long pgsz; if ((pgsz = sysconf(_SC_PAGESIZE)) == -1) { perror("sysconf"); abort(); } else if (pgsz != PGSIZE) { fprintf(stderr, "Unsupported page size! (%ld)/n", pgsz); abort(); } /* * Open shared memory fd. */ shmid = fd_file(); /* * Size the segment. */ if (ftruncate(shmid, SHMSZ) < 0) { perror("ftruncate"); abort(); } /* * Map into address space. */ if ((shm = mmap(BASEADR, SHMSZ, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED | MAP_FIXED, shmid, 0)) == MAP_FAILED) { perror("mmap"); abort(); } if (shm != BASEADR) { printf("Address: %p/n", (void *) shm); abort(); } /* * Check if first time using region? */ if (!shm[0]) { printf("First time with memory!/n"); } else { printf("Re-using memory!/n"); struct T * tptr = (struct T *) (shm+1); printf("T1{ %d, %d, %p }/n", tptr->x, *tptr->y, tptr->t); printf("T2{ %d, %p, %p }/n", tptr->t->x, tptr->t->y, tptr->t->t); memset(shm, 0, 100); } /* * Mark region as active! */ shm[0] = 1; /* * Store structure. */ struct T * t1 = (struct T *) (shm + 1); t1->x = 10; t1->y = shm; struct T * t2 = (struct T *) t1 + 1; t2->x = 20; t2->y = shm; t2->t = NULL; t1->t = t2; /* * Loop writing. */ s = (char *) (t2 + 1); unsigned int i, j; for (i = 0; i < 1024*1024*1024; i++) { for (j = 0; j < i; j++) { s[j] = (char) i; } } /* * Close file descriptor for segment. */ if (close(shmid) < 0) { perror("close"); abort(); } return EXIT_SUCCESS;}
开发者ID:dterei,项目名称:Scraps,代码行数:95,
示例4: mainint main(int argc, char *argv[]){ char errbuf[PCAP_ERRBUF_SIZE]; char *dev; struct iface_config *ifc; int optind; int i; bzero(&cfg, sizeof(cfg)); /* Default configuration */// cfg.ratelimit = 0; cfg.hashsize = 1;// cfg.quiet = 0; cfg.promisc_flag = 1;// cfg.ratelimit = 0;// cfg.sqlite_file = NULL;// cfg.uname = NULL;#if HAVE_LIBSQLITE3 cfg.sqlite_table = PACKAGE;#endif#if HAVE_LIBMYSQLCLIENT// cfg.mysql_db = NULL; cfg.mysql_table = PACKAGE;#endif argp_parse(&argp, argc, argv, 0, &optind, 0); if (!cfg.hostname) { cfg.hostname_len = sysconf(_SC_HOST_NAME_MAX); cfg.hostname = (char *)calloc(cfg.hostname_len, sizeof(char)); gethostname(cfg.hostname, cfg.hostname_len); } daemonize(); save_pid(); log_open(); libevent_init(); if (cfg.ratelimit > 0) log_msg(LOG_DEBUG, "Ratelimiting duplicate entries to 1 per %d seconds", cfg.ratelimit); else if (cfg.ratelimit == -1) log_msg(LOG_DEBUG, "Duplicate entries supressed indefinitely"); else log_msg(LOG_DEBUG, "Duplicate entries ratelimiting disabled"); if (cfg.promisc_flag) log_msg(LOG_DEBUG, "PROMISC mode enabled"); else log_msg(LOG_DEBUG, "PROMISC mode disabled"); if (argc > optind) { for (i = optind; i < argc; i++) add_iface(argv[i]); } else { dev = pcap_lookupdev(errbuf); if (dev != NULL) add_iface(dev); } if (!cfg.interfaces) log_msg(LOG_ERR, "No suitable interfaces found!"); if (cfg.uname) drop_root(cfg.uname); output_flatfile_init(); output_sqlite_init(); output_mysql_init(); /* main loop */#if HAVE_LIBEVENT2 event_base_dispatch(cfg.eb);#else event_dispatch();#endif output_mysql_close(); output_sqlite_close(); output_flatfile_close(); for (ifc = cfg.interfaces; ifc != NULL; ifc = del_iface(ifc)); libevent_close(); log_close(); del_pid(); blacklist_free(); free(cfg.hostname); return 0;}
开发者ID:dwhoop55,项目名称:addrwatch,代码行数:97,
示例5: pageinout_testint pageinout_test(int test_runs, unsigned long long file_size) { int fd; char tmpname[] = "pageinoutXXXXXX"; unsigned char *vec; int i; long long j; volatile char *buf; int ret = -1; int rc; struct timeval begin_time, end_time, elapsed_time, total_time_in, total_time_out; long pagesize = sysconf(_SC_PAGE_SIZE); timerclear(&total_time_in); timerclear(&total_time_out); fd = create_tmp_file(tmpname, file_size); if (fd < 0) { return -1; } vec = alloc_mincore_vec(file_size); if (vec == NULL) { goto err_alloc; } buf = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, fd, 0); if (buf == ((void *)-1)) { fprintf(stderr, "Failed to mmap file: %s/n", strerror(errno)); goto err_mmap; } if (!check_caching((void *)buf, vec, file_size, false)) { goto err; } for (i = 0; i < test_runs; i++) { gettimeofday(&begin_time, NULL); //Read backwards to prevent mmap prefetching for (j = ((file_size - 1) & ~(pagesize - 1)); j >= 0; j -= pagesize) { buf[j]; } gettimeofday(&end_time, NULL); timersub(&end_time, &begin_time, &elapsed_time); timeradd(&total_time_in, &elapsed_time, &total_time_in); if (!check_caching((void *)buf, vec, file_size, true)) { goto err; } gettimeofday(&begin_time, NULL); rc = madvise((void *)buf, file_size, MADV_DONTNEED) || posix_fadvise(fd, 0, file_size, POSIX_FADV_DONTNEED); gettimeofday(&end_time, NULL); if (rc) { fprintf(stderr, "posix_fadvise/madvise DONTNEED failed/n"); goto err; } timersub(&end_time, &begin_time, &elapsed_time); timeradd(&total_time_out, &elapsed_time, &total_time_out); if (!check_caching((void *)buf, vec, file_size, false)) { goto err; } } printf("page-in: %llu MB/s/n", (file_size * test_runs * USEC_PER_SEC) / (1024 * 1024 * (total_time_in.tv_sec * USEC_PER_SEC + total_time_in.tv_usec))); printf("page-out (clean): %llu MB/s/n", (file_size * test_runs * USEC_PER_SEC) / (1024 * 1024 * (total_time_out.tv_sec * USEC_PER_SEC + total_time_out.tv_usec))); ret = 0;err: munmap((void *)buf, file_size);err_mmap: free(vec);err_alloc: close(fd); return ret;}
开发者ID:AOSP-JF,项目名称:platform_system_extras,代码行数:82,
示例6: get_cpu_time_countersvoidget_cpu_time_counters(cpu_time_counters_t *res, struct timeval *timestamp, test_t *test){ int i,records; char *p = proc_stat_buf; char cpunam[64]; uint64_t nicetime; netsysstat_data_t *tsd = GET_TEST_DATA(test); double elapsed; /* well, it isn't really "elapsed" */ FILE *proc_intr_file = NULL; uint64_t irq; NETPERF_DEBUG_ENTRY(test->debug,test->where); gettimeofday(timestamp,NULL); elapsed = (double)timestamp->tv_sec + ((double)timestamp->tv_usec / (double)1000000); if (test->debug) { fprintf(test->where, "func: %s res %p timeptr %p test %p tsd %p/n", __func__, res, timestamp, test, tsd); fflush(test->where); } lseek (proc_stat_fd, 0, SEEK_SET); read (proc_stat_fd, p, proc_stat_buflen); if (test->debug) { fprintf(test->where,"proc_stat_buf %s/n",p); fflush(test->where); } /* Skip first line (total) on SMP */ if (tsd->num_cpus > 1) p = strchr (p, '/n'); for (i = 0; i < tsd->num_cpus; i++) { /* PN: * p points to a '/n'. Move to the next char for cpu info */ p = p + 1; /* records = sscanf(proc_stat_buf, */ /* PN: Scanning a few more cpu counters. */ records = sscanf(p, "%s %lld %lld %lld %lld %lld %lld %lld", cpunam, &(res[i].user), &(res[i].nice), &(res[i].kernel), &(res[i].idle), &(res[i].iowait), &(res[i].interrupt), &(res[i].softirq) ); res[i].calibrate = (uint64_t)(elapsed * (double)sysconf(_SC_CLK_TCK)); /* PN: Nothing goes into other stats. */ /* res[i].user += nicetime; res[i].interrupt = 0; res[i].other = res[i].calibrate; res[i].other -= res[i].idle; res[i].other -= res[i].user; res[i].other -= res[i].kernel; res[i].other -= res[i].interrupt; */ if (test->debug) { fprintf(test->where, "/tcalibrate[%d] = 0x%"PRIx64" ", i, res[i].calibrate); fprintf(test->where, "/tidle[%d] = 0x%"PRIx64" ", i, res[i].idle); fprintf(test->where, "user[%d] = 0x%"PRIx64" ", i, res[i].user); fprintf(test->where, "kern[%d] = 0x%"PRIx64" ", i, res[i].kernel); fflush(test->where); fprintf(test->where, "intr[%d] = 0x%"PRIx64"/n", i, res[i].interrupt); fprintf(test->where, "nice[%d] = %x"PRIx64" ", i,//.........这里部分代码省略.........
开发者ID:ezhangle,项目名称:netperf4,代码行数:101,
示例7: TestSuite_PrintJsonSystemHeaderstatic voidTestSuite_PrintJsonSystemHeader (FILE *stream){#ifdef _WIN32# define INFO_BUFFER_SIZE 32767 SYSTEM_INFO si; DWORD version = 0; DWORD major_version = 0; DWORD minor_version = 0; DWORD build = 0; GetSystemInfo(&si); version = GetVersion(); major_version = (DWORD)(LOBYTE(LOWORD(version))); minor_version = (DWORD)(HIBYTE(LOWORD(version))); if (version < 0x80000000) { build = (DWORD)(HIWORD(version)); } fprintf (stream, " /"host/": {/n" " /"sysname/": /"Windows/",/n" " /"release/": /"%ld.%ld (%ld)/",/n" " /"machine/": /"%ld/",/n" " /"memory/": {/n" " /"pagesize/": %ld,/n" " /"npages/": %d/n" " }/n" " },/n", major_version, minor_version, build, si.dwProcessorType, si.dwPageSize, 0 );#else struct utsname u; uint64_t pagesize; uint64_t npages = 0; if (uname (&u) == -1) { perror ("uname()"); return; } pagesize = sysconf (_SC_PAGE_SIZE);# if defined(_SC_PHYS_PAGES) npages = sysconf (_SC_PHYS_PAGES);# endif fprintf (stream, " /"host/": {/n" " /"sysname/": /"%s/",/n" " /"release/": /"%s/",/n" " /"machine/": /"%s/",/n" " /"memory/": {/n" " /"pagesize/": %"PRIu64",/n" " /"npages/": %"PRIu64"/n" " }/n" " },/n", u.sysname, u.release, u.machine, pagesize, npages );#endif}
开发者ID:tuzcsaba,项目名称:mongo-c-driver,代码行数:70,
示例8: mainint main(int argc, char * argv[]){ pid_t child; pthread_mutex_t mtx; pthread_mutexattr_t ma[4]; pthread_mutexattr_t *pma[5]; int ret=0; int i; int retini[5] = {-1,-1,-1,-1,-1}; int retdtr[5]= {-1,-1,-1,-1,-1}; void * ptr, *ptr_prev=NULL; int sz = 0; struct rlimit rl; int status=0; output_init(); child = fork(); if (child == (pid_t)-1) { UNRESOLVED(errno, "Fork failed"); } if (child != 0) /* We are the father */ { if (child != waitpid(child, &status, 0)) { UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { UNRESOLVED(WTERMSIG(status), "The child process was killed."); } if (WIFEXITED(status)) return WEXITSTATUS(status); UNRESOLVED(0, "Child process neither returned nor was killed."); } /* Only the child goes further */ /* We initialize the different mutex attributes */ for (i=0; (i<4) && (ret == 0); i++) { pma[i] = &ma[i]; ret = pthread_mutexattr_init(pma[i]); } if (ret) { UNRESOLVED(ret, "Mutex attribute init failed"); } pma[4] = (pthread_mutexattr_t *) NULL; if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_NORMAL))) { UNRESOLVED(ret, "Mutex attribute NORMAL failed"); } if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_DEFAULT))) { UNRESOLVED(ret, "Mutex attribute DEFAULT failed"); } if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_RECURSIVE))) { UNRESOLVED(ret, "Mutex attribute RECURSIVE failed"); } if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_ERRORCHECK))) { UNRESOLVED(ret, "Mutex attribute ERRORCHECK failed"); } sz = sysconf(_SC_PAGESIZE); /* Limit the process memory to a small value (64Mb for example). */ rl.rlim_max=1024*1024*64; rl.rlim_cur=1024*1024*64; if ((ret = setrlimit(RLIMIT_AS, &rl))) { UNRESOLVED(ret, "Memory limitation failed"); } #if VERBOSE > 1 output("Ready to take over memory. Page size is %d/n", sz); #endif /* Allocate all available memory */ while (1) { ptr = malloc( sz ); /* Allocate one page of memory */ if (ptr == NULL) break; #if VERBOSE > 1 ret++; #endif *(void **)ptr = ptr_prev; /* Write into the allocated page */ ptr_prev = ptr; } #if VERBOSE > 1 output("%d pages were allocated before failure/n", ret); ret = 0; #endif while (1) { ptr = malloc( sizeof(void*) ); /* Allocate every remaining bits of memory */ if (ptr == NULL) break;//.........这里部分代码省略.........
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:101,
示例9: MapPhysAddressstatic void *MapPhysAddress(unsigned long address, unsigned long size){ unsigned long offset, delta; int pagesize = -1; void *vaddr; MapPtr mp;#if defined(ISC) && defined(HAS_SVR3_MMAP) struct kd_memloc mloc;#elif defined(__EMX__) APIRET rc; ULONG action; HFILE hfd;#endif if ((mp = FindMap(address, size))) { mp->refcount++; return (void *)((unsigned long)mp->vaddr + mp->delta); }#if defined(_SC_PAGESIZE) && defined(HAS_SC_PAGESIZE) pagesize = sysconf(_SC_PAGESIZE);#endif#ifdef _SC_PAGE_SIZE if (pagesize == -1) pagesize = sysconf(_SC_PAGE_SIZE);#endif#ifdef HAS_GETPAGESIZE if (pagesize == -1) pagesize = getpagesize();#endif#ifdef PAGE_SIZE if (pagesize == -1) pagesize = PAGE_SIZE;#endif if (pagesize == -1) pagesize = 4096; delta = address % pagesize; offset = address - delta;#if defined(ISC) && defined(HAS_SVR3_MMAP) if (mapFd < 0) { if ((mapFd = open("/dev/mmap", O_RDWR)) < 0) return NULL; } mloc.vaddr = (char *)0; mloc.physaddr = (char *)offset; mloc.length = size + delta; mloc.ioflg=1; if ((vaddr = (void *)ioctl(mapFd, MAP, &mloc)) == (void *)-1) return NULL;#elif defined (__EMX__) /* * Dragon warning here! /dev/pmap$ is never closed, except on progam exit. * Consecutive calling of this routine will make PMAP$ driver run out * of memory handles. Some umap/close mechanism should be provided */ rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2)NULL); if (rc != 0) return NULL; { struct map_ioctl { union { ULONG phys; void* user; } a; ULONG size; } pmap,dmap; ULONG plen,dlen;#define XFREE86_PMAP 0x76#define PMAP_MAP 0x44 pmap.a.phys = offset; pmap.size = size + delta; rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP, (PULONG)&pmap, sizeof(pmap), &plen, (PULONG)&dmap, sizeof(dmap), &dlen); if (rc == 0) { vaddr = dmap.a.user; } } if (rc != 0) return NULL;#elif defined (Lynx) vaddr = (void *)smem_create("XF86DGA", (char *)offset, size + delta, SM_READ|SM_WRITE);#else#ifndef MAP_FILE#define MAP_FILE 0#endif if (mapFd < 0) { if ((mapFd = open(DEV_MEM, O_RDWR)) < 0) return NULL; } vaddr = (void *)mmap(NULL, size + delta, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, mapFd, (off_t)offset);//.........这里部分代码省略.........
开发者ID:infertux,项目名称:SDL-1.2.7,代码行数:101,
示例10: _CreateProcessExABOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags, LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation){ pid_t pid; int flags; int numArgs; LPSTR* pArgs = NULL; char** envp = NULL; char* filename = NULL; HANDLE thread; HANDLE process; WINPR_ACCESS_TOKEN* token; LPTCH lpszEnvironmentBlock; BOOL ret = FALSE; pid = 0; numArgs = 0; lpszEnvironmentBlock = NULL; pArgs = CommandLineToArgvA(lpCommandLine, &numArgs); flags = 0; token = (WINPR_ACCESS_TOKEN*) hToken; if (lpEnvironment) { envp = EnvironmentBlockToEnvpA(lpEnvironment); } else { lpszEnvironmentBlock = GetEnvironmentStrings(); envp = EnvironmentBlockToEnvpA(lpszEnvironmentBlock); } filename = FindApplicationPath(pArgs[0]); if (NULL == filename) goto finish; /* fork and exec */ pid = fork(); if (pid < 0) { /* fork failure */ goto finish; } if (pid == 0) { /* child process */#ifdef __sun closefrom(3);#else int maxfd;#ifdef F_MAXFD // on some BSD derivates maxfd = fcntl(0, F_MAXFD);#else maxfd = sysconf(_SC_OPEN_MAX);#endif int fd; for(fd=3; fd<maxfd; fd++) close(fd);#endif // __sun if (token) { if (token->GroupId) { int rc = setgid((gid_t) token->GroupId); if (rc < 0) { } else { initgroups(token->Username, (gid_t) token->GroupId); } } if (token->UserId) setuid((uid_t) token->UserId); /* TODO: add better cwd handling and error checking */ if (lpCurrentDirectory && strlen(lpCurrentDirectory) > 0) chdir(lpCurrentDirectory); } if (execve(filename, pArgs, envp) < 0) { /* execve failed - end the process */ _exit(1); } } else { /* parent process */ }//.........这里部分代码省略.........
开发者ID:AMV007,项目名称:FreeRDP,代码行数:101,
示例11: INET_setroute//.........这里部分代码省略......... continue; } if (k == KW_IPVx_GATEWAY) { if (rt.rt_flags & RTF_GATEWAY) { bb_show_usage(); } isnet = INET_resolve(args_m1, (struct sockaddr_in *) &rt.rt_gateway, 1); rt.rt_flags |= RTF_GATEWAY; if (isnet) { if (isnet < 0) { bb_error_msg_and_die("resolving %s", args_m1); } bb_error_msg_and_die("gateway %s is a NETWORK", args_m1); } continue; } if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */ rt.rt_flags |= RTF_MSS; rt.rt_mss = bb_xgetularg10_bnd(args_m1, 64, 32768); continue; } if (k == KW_IPVx_WINDOW) { /* Check valid window bounds. */ rt.rt_flags |= RTF_WINDOW; rt.rt_window = bb_xgetularg10_bnd(args_m1, 128, INT_MAX); continue; }#ifdef RTF_IRTT if (k == KW_IPVx_IRTT) { rt.rt_flags |= RTF_IRTT; rt.rt_irtt = bb_xgetularg10(args_m1); rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */#if 0 /* FIXME: do we need to check anything of this? */ if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { bb_error_msg_and_die("bad irtt"); }#endif continue; }#endif /* Device is special in that it can be the last arg specified * and doesn't requre the dev/device keyword in that case. */ if (!rt.rt_dev && ((k == KW_IPVx_DEVICE) || (!k && !*++args))) { /* Don't use args_m1 here since args may have changed! */ rt.rt_dev = args[-1]; continue; } /* Nothing matched. */ bb_show_usage(); }#ifdef RTF_REJECT if ((rt.rt_flags & RTF_REJECT) && !rt.rt_dev) { rt.rt_dev = "lo"; }#endif /* sanity checks.. */ if (mask_in_addr(rt)) { unsigned long mask = mask_in_addr(rt); mask = ~ntohl(mask); if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) { bb_error_msg_and_die("netmask %.8x and host route conflict", (unsigned int) mask); } if (mask & (mask + 1)) { bb_error_msg_and_die("bogus netmask %s", netmask); } mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr; if (mask & ~mask_in_addr(rt)) { bb_error_msg_and_die("netmask and route address conflict"); } } /* Fill out netmask if still unset */ if ((action == RTACTION_ADD) && (rt.rt_flags & RTF_HOST)) { mask_in_addr(rt) = 0xffffffff; } /* Create a socket to the INET kernel. */ if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { bb_perror_msg_and_die("socket"); } if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) { bb_perror_msg_and_die("SIOC[ADD|DEL]RT"); } /* Don't bother closing, as we're exiting after we return anyway. */ /* close(skfd); */}
开发者ID:cmtsij,项目名称:Vizio_XWR100_GPL,代码行数:101,
|