Annotation of researchv9/sys/inet/udp_output.c, revision 1.1

1.1     ! root        1: /*     udp_output.c    6.1     83/07/29        */
        !             2: #include "udp.h"
        !             3: #if NUDP > 0
        !             4: 
        !             5: #include "../h/param.h"
        !             6: #include "../h/systm.h"
        !             7: #include "../h/stream.h"
        !             8: #include "../h/inet/mbuf.h"
        !             9: 
        !            10: #include "../h/inet/in.h"
        !            11: #include "../h/inet/ip.h"
        !            12: #include "../h/inet/ip_var.h"
        !            13: #include "../h/inet/udp.h"
        !            14: #include "../h/inet/udp_var.h"
        !            15: 
        !            16: #define        IPPROTO_UDP     17
        !            17: #define        UDP_DATA_LEN    (1500-sizeof(struct udpiphdr))
        !            18: 
        !            19: udp_output(bp, udp)
        !            20: register struct block *bp;
        !            21: register struct udp *udp;
        !            22: {
        !            23:        register struct block *head;
        !            24:        register struct udpiphdr *ui;
        !            25:        register int len = 0;
        !            26: 
        !            27:        /*
        !            28:         * Calculate data length and get a mbuf
        !            29:         * for UDP and IP headers.
        !            30:         */
        !            31: 
        !            32:        head = bp;
        !            33:        while(bp) {
        !            34:                len += BLEN(bp);
        !            35:                bp = bp->next;
        !            36:        }
        !            37: 
        !            38:        if (NULL == (bp = allocb(sizeof(struct udpiphdr)))) {
        !            39:                printf("Can't allocate block for udpiphdr\n");
        !            40:                bp_free(head);
        !            41:                return;
        !            42:        }
        !            43:        bp->wptr += sizeof(struct udpiphdr);
        !            44: /*
        !            45:  * point "next" of allocated block containing udpiphdr to data
        !            46:  * point head to this block
        !            47:  */
        !            48:        bp->next = head;
        !            49: 
        !            50:        /*
        !            51:         * Fill in mbuf with extended UDP header
        !            52:         * and addresses and length put into network format.
        !            53:         */
        !            54:        ui = mtod(bp, struct udpiphdr *);
        !            55:        ui->ui_next = ui->ui_prev = 0;
        !            56:        ui->ui_x1 = 0;
        !            57:        ui->ui_pr = IPPROTO_UDP;
        !            58:        ui->ui_len = (u_short)len + sizeof (struct udphdr);
        !            59:        ui->ui_len = htons(ui->ui_len);
        !            60:        ui->ui_src = htonl(udp->src);
        !            61:        ui->ui_dst = htonl(udp->dst);
        !            62:        ui->ui_sport = htons(udp->sport);
        !            63:        ui->ui_dport = htons(udp->dport);
        !            64:        ui->ui_ulen = ui->ui_len;
        !            65: 
        !            66:        /* Stuff checksum and output datagram. */
        !            67:        ui->ui_sum = 0;
        !            68:        if ((ui->ui_sum = in_cksum(bp, sizeof(struct udpiphdr)+len)) == 0)
        !            69:                ui->ui_sum = -1;
        !            70: 
        !            71: 
        !            72:        /* Put length and timeout time into the `real' ip header. */
        !            73:        ((struct ip *)ui)->ip_len = sizeof(struct udpiphdr)+len;
        !            74:        ((struct ip *)ui)->ip_ttl = MAXTTL;
        !            75: 
        !            76:        /* Ip expects internet addresses in host order. */
        !            77:        ui->ui_src = ntohl(ui->ui_src);
        !            78:        ui->ui_dst = ntohl(ui->ui_dst);
        !            79:        udp_ldout(bp);
        !            80: }
        !            81: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.