Пример #1
0
int
mlvpn_tuntap_read(struct tuntap_s *tuntap)
{
    ssize_t ret;
    u_char data[DEFAULT_MTU];

    ret = read(tuntap->fd, &data, DEFAULT_MTU);
      
    if (ret<0 && (errno==EAGAIN || errno==EWOULDBLOCK)) {
      return -1;
    }
    
    if (ret < 0) {
        /* read error on tuntap is not recoverable. We must die. */
        fatal("tuntap", "unrecoverable read error");
    } else if (ret == 0) { /* End of file */
        fatalx("tuntap device closed");
    } else if (ret > tuntap->maxmtu)  {
        log_warnx("tuntap",
            "cannot send packet: too big %d/%d. truncating",
            (uint32_t)ret, tuntap->maxmtu);
        ret = tuntap->maxmtu;
    }
    return mlvpn_tuntap_generic_read(data, ret);
}
Пример #2
0
int
mlvpn_tuntap_read(struct tuntap_s *tuntap)
{
    ssize_t ret;
    u_char data[DEFAULT_MTU];
    ret = read(tuntap->fd, &data, tuntap->maxmtu);
    if (ret < 0) {
        if (errno != EAGAIN && errno != EWOULDBLOCK) {
            /* read error on tuntap is not recoverable. We must die. */
            fatal("tuntap", "unrecoverable read error");
        } else {
            /* false reading from libev read would block, we can't read */
            return 0;
        }
    } else if (ret == 0) { /* End of file */
        fatalx("tuntap device closed");
    } else if (ret > tuntap->maxmtu)  {
        log_warnx("tuntap",
            "cannot send packet: too big %d/%d. truncating",
            (uint32_t)ret, tuntap->maxmtu);
        ret = tuntap->maxmtu;
    }
    return mlvpn_tuntap_generic_read(data, ret);
}