-
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(err < 0 )
printk(KERN_ALERT "ERROR: cannot create a socket");
printk(KERN_ALERT "SUCCESS: socket created\n");
raddr.sin_family = AF_INET;
raddr.sin_addr.s_addr = htonl("10.44.10.255");//broadcast address
raddr.sin_port = htons(30);
err= sock1->ops->connect(sock1 , (struct sockaddr *)&raddr , sizeof(struct sockaddr),0);
if(err < 0 )
printk(KERN_ALERT "ERROR: cannot connect the socket\n");
else printk(KERN_ALERT "SUCCESS: socket connected\n");
iov.iov_base = (void *)buffer;
iov.iov_len = strlen(buffer);
udpmsg.msg_name = &raddr; udpmsg.msg_namelen = sizeof(struct sockaddr_in);
udpmsg.msg_iov = &iov; udpmsg.msg_iovlen = 1;
udpmsg.msg_control = NULL; udpmsg.msg_controllen =0;
udpmsg.msg_flags = MSG_DONTWAIT;
err = sock_sendmsg(sock1 , &udpmsg , strlen(buffer));
if(err<0)
printk(KERN_ALERT "ERROR: message cannot be sent\n");
else
printk(KERN_ALERT "SUCCESS: message sent\n");
return 0;
}
-
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.
-
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??????