# /* in_alloc.c */ /* EMACS_MODES: c !fill */ /* Internet protocol layer for the MIT network system. The following * routines are included: * in_alloc Allocate an internet packet buffer * in_free Free an internet packet buffer * * Note that use of this package requires the use of the standard I/O * library. */ #include #include #include #include #include caddr_t in_alloc (datalen, optlen) /* Allocate the storage for a packet with data area of size datalen, * and including space for an option string of length optlen, * including space for local net header and trailer and for internet * header. The length will be increased to an even number of bytes * if needed. Set up the internet header length fields so in_data() * will work properly. Return a pointer to the allocated packet, * or NULL if unable to allocate one. * * Arguments: */ reg int datalen; /* length of data area in bytes */ int optlen; /* option string length in bytes */ { caddr_t pkt; /* ptr. to allocated packet */ reg struct ip *pip; /* ptr. to internet header */ reg int len; /* total packet length */ optlen = (optlen + 3) & ~3; /* round option len up */ len = lnhsiz + IPHSIZ + optlen + datalen + lntsiz; len = (len + 1) & ~1; /* round up to even byte size */ if ((pkt = calloc (1, len)) == NULL) return (NULL); pip = in_head(pkt); pip->ip_ihl = IP_IHL + (optlen >> 2); return (pkt); } in_free (pkt) /* Free the packet pointed to by pkt. Just call down to the C free * routine. * * Arguments: */ caddr_t pkt; /* ptr. to pkt to free */ { cfree (pkt); }