*BSD News Article 95941


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!uunet!in3.uu.net!207.172.3.52!feed1.news.erols.com!howland.erols.net!news.mathworks.com!rill.news.pipex.net!pipex!tank.news.pipex.net!pipex!news.utell.co.uk!usenet
From: brian@shift.utell.net (Brian Somers)
Newsgroups: comp.unix.bsd.misc
Subject: Re: How can I use Sockets at the IP level (SOCK_RAW) ??
Date: 22 May 1997 10:55:47 GMT
Organization: Awfulhak Ltd.
Lines: 61
Message-ID: <5m18nj$aq7@ui-gate.utell.co.uk>
References: <338283DE.41C67EA6@ee.bilkent.edu.tr>
Reply-To: brian@awfulhak.org, brian@utell.co.uk
NNTP-Posting-Host: shift.utell.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Newsreader: knews 0.9.8
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:3372

In article <338283DE.41C67EA6@ee.bilkent.edu.tr>,
	Khaled Benfatma <khaled@ee.bilkent.edu.tr> writes:
> I am trying to write a C program on SunOS which sends and a receives
> data between two different machines using 'SOCKET'. 
> 
> This worked pretty well for both TCP (SOCK_STREAM) and UDP (SOCK_DGRAM),
> but I need to work at the IP level, that is, I want to use a raw socket:
> 
> socket(AF_INET, SOCK_RAW, proto)
> 
> I already got the super-user previlege but I can only create this type
> of sockets, I could not transmit any data thru it. I tried to use the
> following code, but I couldn't get any result.
> 
> 
> 
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
> #include <netdb.h>
> #include <stdio.h>
> 
> #define DATA "The sea is calm tonight, the tide is full . . ."
> 
> main()
> {
>   int sock;
>   struct sockaddr_in receiver;  
> 
>   sock = socket(AF_INET,SOCK_RAW, 0);
>   if (sock < 0) {
>     perror("opening socket");
>     exit(1);
>   }
> 
>   receiver.sin_family = AF_INET;
>   receiver.sin_port = htons(2000);
>   receiver.sin_addr.s_addr = inet_addr("139.179.12.18");
> 
>   if (sendto(sock,DATA,sizeof(DATA),0,&receiver,sizeof(receiver)) < 0)
>     perror("sending datagram message");
>   close(sock);
> 
> }
> 
> 
> And I used a pretty similar code for the receiver program, it didn't
> work. 
> If you have any idea about this please help me, I need it very urgently.

You're going to have to write a valid IP packet into a SOCK_RAW.
Have a browse through the /usr/include/net*/*.h, starting with
struct ip.

> 
> Thanks!

-- 
Brian <brian@awfulhak.org> <brian@freebsd.org>
      <http://www.awfulhak.org>
Don't _EVER_ lose your sense of humour !