[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Regarding IPV6_RECVPKTINFO.



Hi ,

    Can anybody please help me in finding out a solution to my problem
    related to IPV6_RECVPKTINFO.

    I am setting IPV6_RECVPKTINFO and when I do a recvmsg ( ),
    it is returning MSG_CTRUNC in the 'flags' parameter. That means
    I am not giving enough buffer to return the ancillary data.

    My question is ... how much should I set the buffer space ?? I am doing
    recvmsg ( ) in the following way :

        char   buf[256] ;
        ssize_t n;
        int len;
        struct msghdr msg;
        struct iovec iov[1];
        struct sockaddr_in6 sa;
        struct cmsghdr *cmptr, *cmsgptr;

        union {
                struct cmsghdr cm;
                char control[CMSG_SPACE(sizeof(struct in6_addr)) +
                             CMSG_SPACE(sizeof(struct in6_pktinfo))];
        } control_un;

        memset (pktp, 0, sizeof(struct in6_pktinfo));

        len = sizeof(sa);

        msg.msg_control = control_un.control;
        msg.msg_controllen = sizeof(control_un.control);
        msg.msg_flags = 0;
        msg.msg_name = &sa;
        msg.msg_namelen = len;
        iov[0].iov_base = buf;
        iov[0].iov_len = 256;
        msg.msg_iov = iov;
        msg.msg_iovlen = 1;

        if ((n = recvmsg(sfd, &msg, flags) < 0)) {
                printf ("recvmsg : %m ");
                return -1;
        }

        if (msg.msg_controllen < sizeof(struct cmsghdr) ||
                        (msg.msg_flags & MSG_CTRUNC)) {
                return -1;
        }

        for (cmptr = CMSG_FIRSTHDR(&msg); cmptr != NULL;
                        cmptr = CMSG_NXTHDR(&msg, cmptr)) {
                printf ("   ancillary data, len=%d, level=%d, type=%d ",
                        cmptr->cmsg_len, cmptr->cmsg_level,
cmptr->cmsg_type);
                if (cmptr->cmsg_level == IPPROTO_IPV6 &&
                        cmptr->cmsg_type == IPV6_RECVPKTINFO) {
                        memcpy(pktp, CMSG_DATA(cmptr), sizeof(struct
in6_pktinfo
));
                        continue;
                }
        }

    Please let me know, if I am wrong in any place.

    Thanks in advance.

Best regards,
Anil.







--------------------------------------------------------------------
IETF IPng Working Group Mailing List
IPng Home Page:                      http://playground.sun.com/ipng
FTP archive:                      ftp://playground.sun.com/pub/ipng
Direct all administrative requests to majordomo@sunroof.eng.sun.com
--------------------------------------------------------------------