socket(2) segmentation fault

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

socket(2) segmentation fault

Mikola Akbal
Hi!

I try to create socket, code compiles without problems, but when i run
program, i receive "Segmentation fault".

Code is following:

int result = socket(AF_INET, SOCK_STREAM, 0);
int result = socket(AF_INET, SOCK_STREAM, 6);
int result = socket(AF_INET, SOCK_DGRAM, 17);

All of it gives segmentation fault. Maybe, i need to call some
initialization function like in Windows Sockets? Maybe i need to link my
program with additinal sockets library? Now, i link it with "-lpthread"
only, and clang gives no errors/warnings during compiling/linking. It's
OpenBSD 6.3 amd64 - stable from iso, i did not update nothing.

Call to bind(2) does not give segmentation fault.

dmesg.boot (9K) Download Attachment
dmesg (1).boot (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: socket(2) segmentation fault

Martijn van Duren-8
On 10/30/18 1:50 PM, Mikola Akbal wrote:

> Hi!
>
> I try to create socket, code compiles without problems, but when i run
> program, i receive "Segmentation fault".
>
> Code is following:
>
> int result = socket(AF_INET, SOCK_STREAM, 0);
> int result = socket(AF_INET, SOCK_STREAM, 6);
> int result = socket(AF_INET, SOCK_DGRAM, 17);
>
> All of it gives segmentation fault. Maybe, i need to call some
> initialization function like in Windows Sockets? Maybe i need to link my
> program with additinal sockets library? Now, i link it with "-lpthread"
> only, and clang gives no errors/warnings during compiling/linking. It's
> OpenBSD 6.3 amd64 - stable from iso, i did not update nothing.
>
> Call to bind(2) does not give segmentation fault.
>
Works as expected:
$ cat test.c
#include <sys/socket.h>

#include <stdio.h>

int
main(int argc, char *argv[])
{
        printf("%d\n", socket(AF_INET, SOCK_STREAM, 0));
        return 0;
}
$ cc test.c && ./a.out
3

Reply | Threaded
Open this post in threaded view
|

Re: socket(2) segmentation fault

Jonathan de Boyne Pollard
In reply to this post by Mikola Akbal
Martijn van Duren:
 > Works as expected:

M. Akbal did not give you the whole picture.  Enjoy
https://unix.stackexchange.com/questions/478688/ .