Find the answer to your Linux question:
Results 1 to 3 of 3
hi all i am new to linux network programming and all the sockets stuff i wrote this code but it doesnot work the message is always not sent can anyone ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    6

    PLZ HELP WITH THIS CODE


    hi all
    i am new to linux network programming and all the sockets stuff
    i wrote this code but it doesnot work the message is always not sent can anyone help me please??


    Code:
    struct socket *sock1;
    
    void cleanup_module(void) 
    {
    	sock_release(sock1);	   
    } 
    
    int init_module(void)
    {
    int err;
    struct sockaddr_in raddr;
    struct msghdr udpmsg;
    struct iovec iov;
    char buffer[] = "This is my first LINUX C program";
    /*//////SOCKET CREATION/////////////////////*/
    err = sock_create(AF_INET , SOCK_DGRAM , 0 , &sock1);
    if&#40;err < 0 &#41;
    	printk&#40;KERN_ALERT "ERROR&#58; cannot create a socket"&#41;;
    printk&#40;KERN_ALERT "SUCCESS&#58; socket created\n"&#41;;
    
    raddr.sin_family = AF_INET;
    raddr.sin_addr.s_addr = htonl&#40;"10.44.10.255"&#41;;//broadcast address
    raddr.sin_port = htons&#40;30&#41;;
    
    err= sock1->ops->connect&#40;sock1 , &#40;struct sockaddr *&#41;&raddr , sizeof&#40;struct sockaddr&#41;,0&#41;;
    if&#40;err < 0 &#41;
     	printk&#40;KERN_ALERT "ERROR&#58; cannot connect the socket\n"&#41;;
    else printk&#40;KERN_ALERT "SUCCESS&#58; socket connected\n"&#41;;
    		
    iov.iov_base = &#40;void *&#41;buffer;
    iov.iov_len = strlen&#40;buffer&#41;;
    udpmsg.msg_name = &raddr; udpmsg.msg_namelen = sizeof&#40;struct sockaddr_in&#41;;
    udpmsg.msg_iov = &iov;	udpmsg.msg_iovlen = 1;
    udpmsg.msg_control = NULL;	udpmsg.msg_controllen =0;
    udpmsg.msg_flags = MSG_DONTWAIT;
    
    err = sock_sendmsg&#40;sock1 , &udpmsg , strlen&#40;buffer&#41;&#41;;
    if&#40;err<0&#41;
    	printk&#40;KERN_ALERT "ERROR&#58; message cannot be sent\n"&#41;;
    else
    printk&#40;KERN_ALERT "SUCCESS&#58; message sent\n"&#41;;
    return 0;
    &#125;

  2. #2
    Just Joined!
    Join Date
    Jul 2005
    Location
    Wakefield / England
    Posts
    36

    code help

    your first 'If' statement doesnt have an 'else' statement maybe there is confusion there, not had much experience in C i program in Python.

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    Posts
    6
    no i figured out this mistake after i posted the thread and it is not the error but thanks anyway
    what really happens is that the socket is created, connected but the message is never sent the return value of sock_sendmsg is -22 which i think is invalid arguments but i donot know why??????

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •