|
我现在的接收代码如下
static int my_recvfrom(struct socket *sock, char *buff, size_t len)
{
struct msghdr msg = {NULL,};
struct kvec vec;
int revlen;
vec.iov_base = buff;
vec.iov_len = len;
memset(&msg, 0x00, sizeof(msg));
revlen = kernel_recvmsg(sock, &msg, &vec, 1, len, 0);
printk("len is %d \n",revlen);
return revlen;
}
网上找了个原装的也不行
static int
ip_vs_receive(struct socket *sock, char *buffer, const size_t buflen)
{
struct msghdr msg = {NULL,};
struct kvec iov;
int len;
/* Receive a packet */
iov.iov_base = buffer;
iov.iov_len = (size_t)buflen;
len = kernel_recvmsg(sock, &msg, &iov, 1, buflen, 0);
if (len < 0)
return -1;
printk("len is %s\n",buffer);
return len;
}
都不能取得行数,buff也没有内容,但我用nc -u 192.168.0.1 8888测试server端一切正常,有返回的,server端的sendto如下
memset(str1,0,strlen(str1));
strcpy(str1,"char is:");
strcat(str1,recvbuf);
memset(sendbuf,0,strlen(sendbuf));
memcpy(sendbuf,str1,strlen(str1));
snd = sendto(sock,sendbuf,strlen(str1),0,
(struct sockaddr *) &client,structlength);
我就搞不懂了,既然sock_create和sock_release都提供了,再提供个sock_recvfrom和sock_sendto又有何妨啊...... |
|