⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppplib.c

📁 vxworks的tcpip协议栈源码
💻 C
📖 第 1 页 / 共 4 页
字号:
intr(sig)    int sig;{    MAINDEBUG((LOG_INFO, "Interrupt received: terminating link"));    adjtimeout();			/* Adjust timeouts */    die(ppp_unit, 1);			/* Close connection */}/* * alrm - Catch SIGALRM signal. * * Indicates a timeout. */static voidalrm(sig)    int sig;{    struct itimerspec itv;    struct callout *freep, *list, *last;        MAINDEBUG((LOG_DEBUG, "Alarm"));        if (ppp_if[ppp_unit]->callout == NULL)        return;    /*     * Get the first scheduled timeout and any that were scheduled     * for the same time as a list, and remove them all from callout     * list.     */    list = last = ppp_if[ppp_unit]->callout;    while (last->c_next != NULL && last->c_next->c_time == 0)        last = last->c_next;    ppp_if[ppp_unit]->callout = last->c_next;    last->c_next = NULL;    /*     * Set a new itimer if there are more timeouts scheduled.     */    if (ppp_if[ppp_unit]->callout) {        itv.it_interval.tv_sec = itv.it_interval.tv_nsec = 0;        itv.it_value.tv_nsec = 0;        itv.it_value.tv_sec = ppp_if[ppp_unit]->callout->c_time;        MAINDEBUG((LOG_DEBUG, "Setting itimer for %d seconds in alrm.",                   itv.it_value.tv_sec));        if (timer_settime(ppp_if[ppp_unit]->timer_id, CLOCK_REALTIME, &itv, NULL) < 0) {            syslog(LOG_ERR, "setitimer(ITIMER_REAL): error");            die(ppp_unit, 1);        }        if (time(&ppp_if[ppp_unit]->schedtime) == ERROR) {            syslog(LOG_ERR, "gettimeofday: error");            die(ppp_unit, 1);        }    }    /*     * Now call all the timeout routines scheduled for this time.     */    while (list) {        (*list->c_func)(list->c_arg);        freep = list;        list = list->c_next;        (void) free((char *) freep);    }  }  /* * io - Catch SIGIO signal. * * Indicates that incoming data is available. */static voidio(){    int len, i;    u_char *p;    u_short protocol;    MAINDEBUG((LOG_DEBUG, "IO signal received"));    adjtimeout();         /* Adjust timeouts */    /* Yup, this is for real */    for (;;) {                    /* Read all available packets */        p = ppp_if[ppp_unit]->inpacket_buf;/* point to beggining of packet buffer */        len = read_packet(ppp_if[ppp_unit]->inpacket_buf);        if (len < 0)            break;        if (ppp_if[ppp_unit]->debug /*&& (debugflags & DBG_INPACKET)*/)            log_packet(p, len, "rcvd ");        if (len < DLLHEADERLEN) {            MAINDEBUG((LOG_DEBUG, "io(): Received short packet."));            break;        }        p += 2;                             /* Skip address and control */        GETSHORT(protocol, p);        len -= DLLHEADERLEN;        /*         * Toss all non-LCP packets unless LCP is OPEN.         */        if (protocol != LCP && ppp_if[ppp_unit]->lcp_fsm.state != OPENED) {            MAINDEBUG((LOG_DEBUG, "io(): Received non-LCP packet and LCP not open."));            break;        }        /*         * Upcall the proper protocol input routine.         */        for (i = 0; i < sizeof (prottbl) / sizeof (struct protent); i++)            if (prottbl[i].protocol == protocol) {                (*prottbl[i].input)(ppp_unit, p, len);                break;            }        if (i == sizeof (prottbl) / sizeof (struct protent)) {	    ppp_if[ppp_unit]->unknownProto++;            syslog(LOG_WARNING, "input: Unknown protocol (%x) received!",		   protocol);            lcp_sprotrej(ppp_unit, p - DLLHEADERLEN,		         len + DLLHEADERLEN);        }    }}/* * demuxprotrej - Demultiplex a Protocol-Reject. */voiddemuxprotrej    (    int unit,    u_short protocol    ){    int i;        /*     * Upcall the proper Protocol-Reject routine.     */    for (i = 0; i < sizeof (prottbl) / sizeof (struct protent); i++)        if (prottbl[i].protocol == protocol) {            (*prottbl[i].protrej)(unit);            return;        }    syslog(LOG_WARNING,	   "demuxprotrej: Unrecognized Protocol-Reject for protocol %d!",	   protocol);}/* * incdebug - Catch SIGUSR1 signal. * * Increment debug flag. *//*ARGSUSED*/static voidincdebug(sig)    int sig;{    syslog(LOG_INFO, "Debug turned ON, Level %d", ppp_if[ppp_unit]->debug);    ppp_if[ppp_unit]->debug++;}/* * nodebug - Catch SIGUSR2 signal. * * Turn off debugging. *//*ARGSUSED*/static voidnodebug(sig)    int sig;{    ppp_if[ppp_unit]->debug = 0;}#ifdef	notyet/* * device_script - run a program to connect or disconnect the * serial device. */intdevice_script(program, in, out)    char *program;    int in, out;{    int pid;    int status;    sigset_t mask;    sigemptyset(&mask);    sigaddset(&mask, SIGINT);    sigaddset(&mask, SIGHUP);    sigprocmask(SIG_BLOCK, &mask, &mask);    pid = fork();    if (pid < 0) {        syslog(LOG_ERR, "fork: %m");        die(1);    }    if (pid == 0) {        setreuid(getuid(), getuid());        setregid(getgid(), getgid());        sigprocmask(SIG_SETMASK, &mask, NULL);        dup2(in, 0);        dup2(out, 1);        execl("/bin/sh", "sh", "-c", program, (char *)0);        syslog(LOG_ERR, "could not exec /bin/sh: %m");        _exit(99);        /* NOTREACHED */    }    while (waitpid(pid, &status, 0) < 0) {        if (errno == EINTR)            continue;        syslog(LOG_ERR, "waiting for (dis)connection process: %m");        die(1);    }    sigprocmask(SIG_SETMASK, &mask, NULL);    return (status == 0 ? 0 : -1);}/* * run-program - execute a program with given arguments, * but don't wait for it. * If the program can't be executed, logs an error unless * must_exist is 0 and the program file doesn't exist. */intrun_program(prog, args, must_exist)    char *prog;    char **args;    int must_exist;{    int pid;    pid = fork();    if (pid == -1) {        syslog(LOG_ERR, "can't fork to run %s: %m", prog);        return -1;    }    if (pid == 0) {        execv(prog, args);        if (must_exist || errno != ENOENT)            syslog(LOG_WARNING, "can't execute %s: %m", prog);        _exit(-1);    }    MAINDEBUG((LOG_DEBUG, "Script %s started; pid = %d", prog, pid));    ++n_children;    return 0;}#endif	/* notyet *//* * log_packet - format a packet and log it. */char line[256];                 /* line to be logged accumulated here */char *linep;voidlog_packet(p, len, prefix)    u_char *p;    int len;    char *prefix;{    strcpy(line, prefix);    linep = line + strlen(line);    format_packet(p, len, pr_log, NULL);    if (linep != line)        syslog(LOG_DEBUG, "%s", line);}/* * format_packet - make a readable representation of a packet, * calling `printer(arg, format, ...)' to output it. */voidformat_packet(p, len, printer, arg)    u_char *p;    int len;    void (*printer) __ARGS((void *, char *, ...));    void *arg;{    int i, n;    u_short proto;    u_char x;    if (len >= DLLHEADERLEN && p[0] == ALLSTATIONS && p[1] == UI) {        p += 2;        GETSHORT(proto, p);        len -= DLLHEADERLEN;        for (i = 0; i < N_PROTO; ++i)            if (proto == prottbl[i].protocol)                break;        if (i < N_PROTO) {            printer(arg, "[%s", prottbl[i].name);            n = (*prottbl[i].printpkt)(p, len, printer, arg);            printer(arg, "]");            p += n;            len -= n;        } else {            printer(arg, "[proto=0x%x]", proto);        }    }    for (; len > 0; --len) {        GETCHAR(x, p);        printer(arg, " %.2x", x);    }}#ifdef __STDC__#include <stdarg.h>voidpr_log(void *arg, char *fmt, ...){    int n;    va_list pvar;    char buf[256];    va_start(pvar, fmt);    vsprintf(buf, fmt, pvar);    va_end(pvar);    n = strlen(buf);    if (linep + n + 1 > line + sizeof(line)) {        syslog(LOG_DEBUG, "%s", line);        linep = line;    }    strcpy(linep, buf);    linep += n;}#else /* __STDC__ */#include <varargs.h>voidpr_log(arg, fmt, va_alist)void *arg;char *fmt;va_dcl{    int n;    va_list pvar;    char buf[256];    va_start(pvar);    vsprintf(buf, fmt, pvar);    va_end(pvar);    n = strlen(buf);    if (linep + n + 1 > line + sizeof(line)) {        syslog(LOG_DEBUG, "%s", line);        linep = line;    }    strcpy(linep, buf);    linep += n;}#endif/* * print_string - print a readable representation of a string using * printer. */voidprint_string(p, len, printer, arg)    char *p;    int len;    void (*printer) __ARGS((void *, char *, ...));    void *arg;{    int c;    printer(arg, "\"");    for (; len > 0; --len) {        c = *p++;        if (' ' <= c && c <= '~')            printer(arg, "%c", c);        else            printer(arg, "\\%.3o", c);    }    printer(arg, "\"");}/* * novm - log an error message saying we ran out of memory, and die. */voidnovm(msg)    char *msg;{    syslog(LOG_ERR, "Memory exhausted allocating %s", msg);    die(ppp_unit, 1);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -