# /* in_read.c */ /* EMACS_MODES: c !fill */ /* Internet protocol layer for the MIT network system. The following * routines are included: * in_read Read the next available packet from an internet conn. * * Note that use of this package requires the use of the standard I/O * library. */ #include #include #include #include #include in_read (fd, buf, len) /* Read the next available internet packet for the specified connection from * the net into the specified buffer. Return the length of the received * packet in bytes. * The macro in_data may be called to obtain a pointer to the start * of the data area of the packet. * If no packet is available (read returns NULL) or if the specified * buffer is too small, return 0. * Note: bad packets are simply dropped, and the dropped * packet count is incremented. * * Arguments: */ int fd; /* file descriptor for this conn. */ reg caddr_t buf; /* buffer for received data */ int len; /* buffer size */ { reg int rcvlen; /* length of actual received pkt */ reg int maxlen; /* max. inet packet length */ if ((rcvlen = read (fd, buf, len)) <= (lnhsiz + IPHSIZ)) { ip_dropped++; return (0); } ip_rcvd++; return (rcvlen); }