Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<netlink/netlink.h>
- #define NETLINK_TEST 17
- #define MSG_STR 0x11
- int funkcja(struct nl_sock** ns, char msg[14])
- {
- int result = nl_connect(*ns,NETLINK_TEST);
- if(result<0) {
- fprintf(stderr,"Blad wczytywania gniazda netlink: %s\t%d\t%d.\n",__FILE__,__LINE__-2,result);
- nl_socket_free(*ns);
- return -2;
- }
- return result;
- }
- void funkcja1(struct nl_sock** ns, char msg[14])
- {
- printf("Moj port: %u\n",nl_socket_get_local_port(*ns));
- printf("Port odbiorcy: %u\n",nl_socket_get_peer_port(*ns));
- printf("Dlugosc wiadomosci: %u\n",sizeof(msg));
- nl_socket_disable_seq_check(*ns);
- nl_socket_disable_auto_ack(*ns);
- nl_socket_disable_msg_peek(*ns);
- }
- int main(void)
- {
- struct nl_sock *ns;
- char msg[] = "Hello netlink";
- ns = nl_socket_alloc();
- if(!ns) {
- fprintf(stderr,"Blad tworzenia gniazda netlink: %s\t%d.\n",__FILE__,__LINE__-2);
- return -1;
- }
- funkcja1(&ns, msg);
- int result = funkcja(&ns, msg);
- if (result < 0)
- return -2;
- result = nl_send_simple(ns,MSG_STR,NLM_F_REQUEST,(void *)msg,sizeof(msg));
- if(result<0)
- fprintf(stderr,"Blad wysylania wiadomosci: %s\t%d\t%d\n",__FILE__,__LINE__,result);
- else
- printf("Wyslano %d bajtow wiadomosci.\n",result);
- nl_socket_free(ns);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement