Question: Problem with socket, socket system call returns 0

Question: Problem with socket, socket system call returns 0

Post by Cristiano Ghirard » Thu, 22 Apr 1999 04:00:00



Hi,
   Ok my problem is this I have tried to bind a socket but the bind
system call
return -1 and errno is set to 88 (it is not a valid socket descriptor).
Debugging my piece of code I have discovered that before the socket
system call returns 0. Is this a valid socket
descriptor ? I' m working as not root user and I have tried to bind the
socket on different ports for example 6969 etc..
The piece of code is something like this:

#include<stdio.h>
......
.....
sockaddr_in addr;

int main() {
    .......
    ........

    if ((sock = (AF_INET, SOCK_STREAM, 0))  ==  -1) {
       fprintf(stderr, "Socket creation error errno is %i\n", errno);
       return -1;
   }
   /* from now sock is = 0 */

   addr.sin_family = AF_INET;
   addr.sin_port = htons(6969);
   addr.sin_addr.s_addr = INADDR_ANY;
   bzero(&(addr.sin_zero), 8);

   if ((bind(sock, (struct sockaddr *)&addr, sizeof(sockaddr_in))) ==
-1) {
       fprintf(stderr, "Binding error errno is %i\n", errno);
       return -1;
     /* Here the program exit with errno set to 88 */
   }

    return 0;

Quote:}

Thanks to everyone can help me

            Cris

 
 
 

Question: Problem with socket, socket system call returns 0

Post by George MacDonal » Thu, 22 Apr 1999 04:00:00



> Hi,
>    Ok my problem is this I have tried to bind a socket but the bind
> system call
> return -1 and errno is set to 88 (it is not a valid socket descriptor).
> Debugging my piece of code I have discovered that before the socket
> system call returns 0. Is this a valid socket
> descriptor ? I' m working as not root user and I have tried to bind the
> socket on different ports for example 6969 etc..
> The piece of code is something like this:

> #include<stdio.h>
> ......
> .....
> sockaddr_in addr;

> int main() {
>     .......
>     ........

>     if ((sock = (AF_INET, SOCK_STREAM, 0))  ==  -1) {

                  ^

Missing function call?

--
We stand on the shoulders of those giants who coded before.
Build a good layer, stand strong, and prepare for the next wave.
Guide those who come after you, give them your shoulder, lend them your code.


 
 
 

Question: Problem with socket, socket system call returns 0

Post by Erwin S. Andreas » Thu, 22 Apr 1999 04:00:00



>Debugging my piece of code I have discovered that before the socket
>system call returns 0. Is this a valid socket

Your socket system call, eh? :)

Quote:>    if ((sock = (AF_INET, SOCK_STREAM, 0))  ==  -1) {

Something rather vital is missing from this line.

--
==============================================================================

<URL:http://www.andreasen.org>              <*>         (not speaking for) DDE
==============================================================================

 
 
 

Question: Problem with socket, socket system call returns 0

Post by Cristiano Ghirard » Thu, 22 Apr 1999 04:00:00




> > Hi,
> >    Ok my problem is this I have tried to bind a socket but the bind
> > system call
> > return -1 and errno is set to 88 (it is not a valid socket descriptor).
> > Debugging my piece of code I have discovered that before the socket
> > system call returns 0. Is this a valid socket
> > descriptor ? I' m working as not root user and I have tried to bind the
> > socket on different ports for example 6969 etc..
> > The piece of code is something like this:

> > #include<stdio.h>
> > ......
> > .....
> > sockaddr_in addr;

> > int main() {
> >     .......
> >     ........

> >     if ((sock = (AF_INET, SOCK_STREAM, 0))  ==  -1) {

>                   ^

> Missing function call?

Yes sorry,actually the code  is this one:

if ((sock = socket(AF_INET, SOCK_STREAM, 0))  ==  -1) {

- Show quoted text -

> --
> We stand on the shoulders of those giants who coded before.
> Build a good layer, stand strong, and prepare for the next wave.
> Guide those who come after you, give them your shoulder, lend them your code.


 
 
 

1. Sockets so_XXX system calls question

Hi,

We're trying to reduce the memory used by a process that is a sockets
client. One strategy is to try to build the code using the sockets
kernel routines directly, instead of socket(), connect(), etc. This
would reduce process heap usage as we wouldn't have to link with the
sockets and nsl shared libraries.

We've found information on the underlying so_socket(), etc calls, which
we assume are system calls, but in a simple example can't link to these.

Does anyone have any ideas? Are we doing something sensible/possible? If
so, does anyone know how to achieve this on Solaris 2.6?

all help greatly appreciated,

cheers

Ian

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Booting problems with SCSI Seagate Medalist

3. calling socket protocol family from another socket protocol family ?

4. RH6.0 Install Problem: no initrd and SCSI trouble

5. A call to socket() never returns...

6. Device Driver How-to

7. recv() socket call returns ENOENT

8. Backup options for SunOS 4 and 5

9. Problem with socket system call on a Linux box

10. why does socket() call return 0 for FD

11. Sockets, system calls and wait() interaction problem

12. Sockets sockets and more sockets

13. Socket, Socket, whose got the socket?