netdev
[Top] [All Lists]

Re: IPv6 Raw socket problem in Linux 7.2

To: "Hossain, Mohammad" <m_hossain@xxxxxxxxxxxx>
Subject: Re: IPv6 Raw socket problem in Linux 7.2
From: Heikki Kallasjoki <fizban@xxxxxx>
Date: Fri, 8 Mar 2002 02:17:38 +0200
Cc: netdev@xxxxxxxxxxx
In-reply-to: <AA70E30319FAD411AC6E00A0C95D7ABD01EE75F4@xxxxxxxxxxxxxxxxxxxxx>; from m_hossain@xxxxxxxxxxxx on Thu, Mar 07, 2002 at 03:09:58PM -0800
Mail-followup-to: "Hossain, Mohammad" <m_hossain@xxxxxxxxxxxx>, netdev@xxxxxxxxxxx
References: <AA70E30319FAD411AC6E00A0C95D7ABD01EE75F4@xxxxxxxxxxxxxxxxxxxxx>
Sender: owner-netdev@xxxxxxxxxxx
User-agent: Mutt/1.2.5.1i
On Thu, Mar 07, 2002 at 03:09:58PM -0800, Hossain, Mohammad wrote:
>  Problem:
>   I am opening am raw ipv6 socket. Then trying to send and receive data
> using it. But I get invalid argument(EINVAL) from both sendmsg() 
> and recvfrom() system call when trying to send data. Why is this happening? 

Not sure, but trying to answer the first question..

>      Q: What is wrong in following code? 

By simply looking, can't spot any errors. The following code runs
without any error messages on my system, you might want to check if it
works there - if it doesn't, the problem is most probably in your system
setup, not in the code:

--- test.c ---
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/uio.h>

int main(void) {
        struct sockaddr_in6 addr6;
        int size, sd, enable = 1, i;
        struct msghdr msg; struct iovec io; char buf[100];

        sd = socket(AF_INET6, SOCK_RAW, IPPROTO_RAW);
        if(sd == -1) { perror("socket()"); exit(1); }

        if(ioctl(sd, FIONBIO, &enable) == -1) { perror("ioctl()"); exit(1); }
        if(setsockopt(sd, SOL_SOCKET, SO_BSDCOMPAT, &enable, sizeof(enable)) == 
-1) { perror("setsockopt()"); exit(1); }
        if(setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) == 
-1) { perror("setsockopt()"); exit(1); }

        memset(&addr6, 0, sizeof(addr6));
        size = sizeof(struct sockaddr_in6);
        addr6.sin6_family = AF_INET6; addr6.sin6_port = htons(42);
        memcpy(&addr6.sin6_addr, &in6addr_loopback, sizeof(struct in6_addr));
        if(bind(sd, (struct sockaddr *)&addr6, size) == -1) { perror("bind()"); 
exit(1); }
        
        io.iov_base = buf; io.iov_len = 100;
        msg.msg_name = &addr6; msg.msg_namelen = sizeof(struct sockaddr_in6);
        msg.msg_iov = &io; msg.msg_iovlen = 1;
        msg.msg_control = NULL; msg.msg_controllen = 0; msg.msg_flags = 0;
        i = sendmsg(sd, &msg, 0);
        if(i == -1) { perror("sendmsg()"); exit(1); }

        exit(0);
--- test.c ---

It should be essentially equivalent to what you posted.

>      Q: Kernel missing some module???? 
>           How to know if my machine has raw IPv6 support or raw6 module in
> the kernel is installed or not. I see
>           raw6 module is there in /proc/net dir.

/proc/net/raw6 should be a list of opened raw sockets, AFAIK. Kernel
version numbers (output of 'uname -a') might be helpful, my system is
"Linux <hostname> 2.4.18 #21 Tue Feb 26 13:02:07 EET 2002 i586 unknown"
and raw v6 sockets seem to work well on this.


-- 
>#v1&#:<-1<-1\0\_.@  "You cannot escape from window 0!"
>2-!#v_:2\^fibre^-<    fizban at iki dot fi
^:_  >$1>\#+:#$!_1^  PGP key fp 657AF64968F12E6ECBE5F90E421C1FDF9EC09E94

<Prev in Thread] Current Thread [Next in Thread>