1

I am trying following simple program on ClearOS 7.3, 64 bit

#include <sys/socket.h>
#include <linux/netlink.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>

int main()
{
    int flags =0;
    int bus = NETLINK_NETFILTER;

    int sock_fd = socket(AF_NETLINK, SOCK_RAW | flags, bus);
    if(sock_fd<0)
    {
        printf("\nsocket failed with error no = %d and error msg = %s\n",
                                errno, strerror(errno));

        return -1;
    }

    printf("\nOP completed successfully..!\n");
    return 0;
}

I am getting following error:

socket failed with error no = 93 and error msg = Protocol not supported

My OS details are:

  • ClearOS release 7.3.0 (Final)
  • Linux 3.10.0-514.26.2.v7.x86_64 #1 SMP Wed Jul 5 10:37:54 MDT 2017 x86_64 x86_64 x86_64 GNU/Linux

Please help.

JustBaron
  • 2,319
  • 7
  • 25
  • 37
Vikram
  • 11
  • 2

1 Answers1

0

Works for me.

The NETLINK_NETFILTER protocol is registered by the nfnetlink module.

In my case, the kernel registers the module automatically since this code uses it, but if yours doesn't, try inserting it manually:

$ sudo modprobe nfnetlink

And then try opening the socket again.

Yd Ahhrk
  • 1,088
  • 12
  • 24
  • Great. It worked. can you please help me in understanding the theory behind? I thought, it should automatically load nfnetlink module, once the program is invoked. This issue specifically occurred on ClearOS release 7.3.0 (Final) – Vikram Oct 03 '17 at 06:21
  • Sorry, but I don't really know what it depends on. I imagine there's some flag your kernel was compiled with that prevents the module from being loaded automatically for security purposes or something like that. – Yd Ahhrk Oct 10 '17 at 18:51