Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<netlink/netlink.h>
- #include<linux/netlink.h>
- #include<netlink/socket.h>
- #include<netlink/msg.h>
- #include<netlink/attr.h>
- #define NETLINK_TEST 17
- int main(void)
- {
- struct nl_sock *ns;
- struct nl_msg *msg;
- char *wartosc ="9";
- ns = nl_socket_alloc();
- if(!ns) {
- fprintf(stderr,"Błąd tworzenia gniazda netlink: %s\t%d.\n",__FILE__,__LINE__-2);
- return -1;
- }
- printf("Mój port: %u\n",nl_socket_get_local_port(ns));
- printf("Port odbiorcy: %u\n",nl_socket_get_peer_port(ns));
- printf("Długość wiadomości: %lu\n",sizeof(msg));
- nl_socket_disable_seq_check(ns);
- nl_socket_disable_auto_ack(ns);
- nl_socket_disable_msg_peek(ns);
- int result = nl_connect(ns,NETLINK_TEST);
- if(result<0) {
- fprintf(stderr,"Błąd łączenia gniazda netlink: %s\t%d\t%d.\n",__FILE__,__LINE__-2,result);
- nl_socket_free(ns);
- return -2;
- }
- msg = nlmsg_alloc();
- if(nlmsg_put(msg, nl_socket_get_local_port(ns),0, NLA_U8, sizeof(msg), NLM_F_REQUEST ) ==NULL){
- fprintf(stderr, "blad przy tworzeniu naglowka");
- return -1;
- }
- nla_put(msg, NLA_U8, sizeof(NLA_U8), (void*)wartosc);
- result = nl_send_auto(ns, msg);
- if(result<0)
- fprintf(stderr,"Błąd wysyłania wiadomości: %s\t%d\t%d\n",__FILE__,__LINE__,result);
- else
- printf("Wysłano %d bajtów wiadomości.\n",result);
- nl_socket_free(ns);
- nlmsg_free(msg);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement