Advertisement
Guest User

l

a guest
Jun 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<netlink/netlink.h>
  4. #include<linux/netlink.h>
  5. #include<netlink/socket.h>
  6. #include<netlink/msg.h>
  7. #include<netlink/attr.h>
  8.  
  9. #define NETLINK_TEST 17
  10.  
  11. int main(void)
  12. {
  13.     struct nl_sock *ns;
  14.     struct nl_msg *msg;
  15.     char *wartosc ="9";
  16.  
  17.     ns = nl_socket_alloc();
  18.     if(!ns) {
  19.         fprintf(stderr,"Błąd tworzenia gniazda netlink: %s\t%d.\n",__FILE__,__LINE__-2);
  20.         return -1;
  21.     }
  22.     printf("Mój port: %u\n",nl_socket_get_local_port(ns));
  23.     printf("Port odbiorcy: %u\n",nl_socket_get_peer_port(ns));
  24.     printf("Długość wiadomości: %lu\n",sizeof(msg));
  25.  
  26.     nl_socket_disable_seq_check(ns);
  27.     nl_socket_disable_auto_ack(ns);
  28.     nl_socket_disable_msg_peek(ns);
  29.    
  30.     int result = nl_connect(ns,NETLINK_TEST);
  31.     if(result<0) {
  32.         fprintf(stderr,"Błąd łączenia gniazda netlink: %s\t%d\t%d.\n",__FILE__,__LINE__-2,result);
  33.         nl_socket_free(ns);
  34.         return -2;
  35.     }
  36.  
  37.     msg = nlmsg_alloc();
  38.     if(nlmsg_put(msg, nl_socket_get_local_port(ns),0, NLA_U8, sizeof(msg), NLM_F_REQUEST ) ==NULL){
  39.         fprintf(stderr, "blad przy tworzeniu naglowka");  
  40.         return -1;    
  41.     }
  42.     nla_put(msg, NLA_U8, sizeof(NLA_U8), (void*)wartosc);
  43.  
  44.     result = nl_send_auto(ns, msg);
  45.     if(result<0)
  46.         fprintf(stderr,"Błąd wysyłania wiadomości: %s\t%d\t%d\n",__FILE__,__LINE__,result);
  47.     else
  48.         printf("Wysłano %d bajtów wiadomości.\n",result);
  49.  
  50.     nl_socket_free(ns);
  51.     nlmsg_free(msg);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement