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