PR_Socket does not allow opening a Raw-IP socket for ICMP operations

ASSIGNED
Assigned to

Status

NSPR
NSPR
--
enhancement
ASSIGNED
13 years ago
12 years ago

People

(Reporter: Alfred Reibenschuh, Assigned: Wan-Teh Chang)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

13 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6

the invokation of:

icmpFd = PR_Socket(PR_AF_INET, SOCK_RAW, IPPROTO_ICMP);

returns NULL

Reproducible: Always

Steps to Reproduce:
compile and execute:

#include <stdio.h>
#include "nspr.h"
#include "private/pprio.h"
#include "netinet/ip.h"
#include "netinet/icmp.h"

int main(int argc, char **argv)
{
        PRFileDesc *icmpFH;
        PRThreadType thrType=PR_SYSTEM_THREAD;
        PRThreadPriority thrPrio=PR_PRIORITY_NORMAL;

        PR_Init(thrType,thrPrio,0);

        icmpFH = PR_Socket(PR_AF_INET, SOCK_RAW, IPPROTO_ICMP); 

        if(icmpFH!=NULL)
        {
            printf("Socket open.\n");
            PR_Close(icmpFH);
        }
        else
        {
            printf("Socket creation failed.\n");
        }
        return(0);
}

Actual Results:  
test code above returned:

Socket creation failed.

Expected Results:  
test code should return:

Socket open.
(Reporter)

Comment 1

13 years ago
Created attachment 201413 [details] [diff] [review]
patch to enable Raw-IP Sockets and add ICMPSocket API

this is a patch against cvs-trunk. 

it will enable the creation of Raw-IP sockets via PR_Socket.

i have also taken the liberty of adding the following new API functions:

 - PR_NewICMPSocket
 - PR_OpenICMPSocket

similar to TCP/UDP with IPv6 support.
(Assignee)

Comment 2

13 years ago
Thanks for the patch.  Did you test this patch?
It is incomplete because PR_Socket needs to be modified
to handle SOCK_RAW.
Severity: normal → enhancement
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
(Reporter)

Comment 3

13 years ago
(In reply to comment #2)
> Thanks for the patch.  Did you test this patch?

yes, but only under linux, win32/aix/solaris will follow soon.


> It is incomplete because PR_Socket needs to be modified
> to handle SOCK_RAW.

no, PR_Socket simply passes the parameter further down which is
then correctly handled by the kernel implementation.



(Assignee)

Comment 4

13 years ago
You must have built NSPR incorrectly on Linux.
On Linux, NSPR should use the PR_Socket function defined here:
http://lxr.mozilla.org/nspr/source/nsprpub/pr/src/pthreads/ptio.c#3411

That function fails with the PR_ADDRESS_NOT_SUPPORTED_ERROR error
if 'type' is not SOCK_STREAM or SOCK_DGRAM.
(Reporter)

Comment 5

13 years ago
(In reply to comment #4)
> You must have built NSPR incorrectly on Linux.
> On Linux, NSPR should use the PR_Socket function defined here:
> http://lxr.mozilla.org/nspr/source/nsprpub/pr/src/pthreads/ptio.c#3411
> 
> That function fails with the PR_ADDRESS_NOT_SUPPORTED_ERROR error
> if 'type' is not SOCK_STREAM or SOCK_DGRAM.

please look more closely at the proposed patch, since it will modify the following files:

mozilla/nsprpub/pr/src/pthreads/ptio.c -- pthread socket io
mozilla/nsprpub/pr/src/nspr_symvec.opt -- symbol vectors ?
mozilla/nsprpub/pr/src/nspr.def        -- win32 dll entries
mozilla/nsprpub/pr/src/io/prsocket.c   -- non-pthread socket io
mozilla/nsprpub/pr/include/prio.h      -- header file

and as i said previously -- if nspr is build with the above patch applied,
icmp communication is working as expected under linux-2.6 (CentOS 4.1/RHE 4.0).

if there is a need i could provide code for a test-program. 
(Assignee)

Comment 6

13 years ago
I missed your change to PR_Socket in ptio.c.  (I searched
for PR_Socket in the patch, which is not the right way to
determine if PR_Socket was modified)  I am sorry.

A test program is required to prevent regressions.  Please
add it to mozilla/nsprpub/pr/tests/.  Thanks.
(might want to diff with the -p option, which shows the function names on the @@ lines)
QA Contact: wtchang → nspr
You need to log in before you can comment on or make changes to this bug.