Return to BSD News archive
#! rnews 2072 bsd Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.Hawaii.Edu!news.caldera.com!enews.sgi.com!news.mathworks.com!howland.erols.net!cpk-news-hub1.bbnplanet.com!cpk-news-feed1.bbnplanet.com!news.bbnplanet.com!news1.usf.edu!news.metu.edu.tr!zambak.bcc.bilkent.edu.tr!usenet From: Khaled Benfatma <khaled@ee.bilkent.edu.tr> Newsgroups: comp.unix.bsd.misc Subject: How can I use Sockets at the IP level (SOCK_RAW) ?? Date: Wed, 21 May 1997 09:10:54 +0400 Organization: Bilkent University Lines: 50 Message-ID: <338283DE.41C67EA6@ee.bilkent.edu.tr> NNTP-Posting-Host: kandil.ee.bilkent.edu.tr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.01 (X11; I; SunOS 4.1.3 sun4m) Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:3361 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. Thanks!