LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-17-2004, 09:36 AM   #1
linfreak
LQ Newbie
 
Registered: Oct 2003
Posts: 14

Rep: Reputation: 0
Raw socket creation error (IPPROTO_IP not supported)


hi all,

I tried creating a raw socket in Redhat Advanced server 3.0 . Problem is socket creation fails if the protocol family is IPPROTO_IP or IPPROTO_RAW. I checked out the values for these macros in the header file . They are

IPPROTO_IP ---> 0
IPPROTO_IP ---> 255

I am interested in creating a RAW SOCKET (SOCK_RAW) only

. Socket creation succeeds for other protocol family like IPPROTO_TCP of IPPROTO_ICMP .. etc. The following is the code snippet .

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Code Starts here ^^^^^^^^^^^^^^^^^^^^^^^^

#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#include <iostream.h>


int main()
{
int fd;
struct sockaddr_in serv_sock,cli_sock;

if ((fd = socket(AF_INET,SOCK_RAW,0)) < 0)
{
cout<<"error "<<errno<<endl;
}

//raw sockets dont require binding .. do they ??

listen(fd,5);
fd_set fdset;

while(1)
{
FD_ZERO(&fdset);
FD_SET(fd,&fdset);
int ret = select(fd+1,&fdset,NULL,NULL,NULL);
if (FD_ISSET(fd,&fdset))
{
cout<<"hello"<<endl;
break;
}

}

printf("program terminates");
return 0;
}

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Code Ends here ^^^^^^^^^^^^^^^^^^^^^^^^

My problem is only with socket creation using IPPROTO_IP or IPPROTO_RAW ... the value of errno after the call is 94 which is # defined in <asm/errno.h> as

#define ESOCKTNOSUPPORT 94 /* Socket type not supported */

Does redhat AS 3.0 not allow creation of IPPROTO_IP or IPPROTO_RAW type sockets.
or
do i have to enable the support in kernel.

Thanks a ton in advance !!!

Warm Regards

N.Harris ur rahman
 
Old 06-17-2004, 12:37 PM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
u need to use _TCP/_UDP/_ICMP , those others won't work. but u can do everything that u need with the above mentioned. if u want to see outgoing packets, u need to do:
Code:
    struct sockaddr_ll     sa;
    sa.sll_family = PF_PACKET;  //always this 
    sa.sll_protocol = htons(ETH_P_ALL); //must set this to ALL if we want copy of outgoing packets, read below

        //make the socket; ETH_P_ALL must be set regardless of the packets we want
        //please see the pf_main.c source file for an explanation of this
        if( (sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) <= 1) //create socket
                return 0;

        //in order to recieve outgoing packets we need to bind to ETH_P_ALL
        if( (bind(sock, (struct sockaddr *)&sa, salen)) != 0 )
                err_quit();
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
socket: Socket type not supported monindra Fedora - Installation 4 01-14-2008 07:25 AM
error: conflicting types for `IPPROTO_IP' Anastasia Linux - Software 0 07-14-2005 06:12 AM
Raw socket creation error (IPPROTO_IP not supported) linfreak Linux - Networking 1 06-17-2004 10:53 AM
Socket Raw linuxanswer Programming 1 04-01-2004 09:43 PM
raw ipv6 socket example Steave Programming 0 06-27-2003 03:55 PM


All times are GMT -5. The time now is 03:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration