help! creating socket in kernel

From: Nelson (tanginhw@comp.nus.edu.sg)
Date: Wed Jun 07 2000 - 06:34:31 EST


hi all,

i am trying to create a socket in the bridge module so that
the bridge module can talk to a user-space program via the socket.

however, i had been struck for days and is driving me crazy with
all the kernel oops :(

i am appealing for help as i am new to kernel hacking. assistance
and advice is greatly appreciated (and needed ;p). this mail is
slightly long. do bear with me :)

the kernel i'm using is 2.3.99-pre9.

================================
typedef struct {
        unsigned char code;
        unsigned char name[8];
        unsigned char passwd[8];
        unsigned char portId;
} rad_request; // 18 bytes

int sendRespToServer(struct net_bridge_port *p)
{
        struct sockaddr_in sap, server;
        rad_request radreq;
        int cc = 0;
        struct socket *msock;
            char name[9];
        char passwd[9];
                
            memcpy(name, <some user's name>, 8);
            memcpy(passwd, <some passwd>, 8);
        name[8] = '\0';
        passwd[8] = '\0';

        /* filling in the rad_request structure */
        radreq.code = Request;
        memcpy(radreq.name,name,8);
        memcpy(radreq.passwd,passwd,8);
            radreq.portId = p->port_no;

            memset(&sap, 0, sizeof(sap));
            sap.sin_family = AF_INET;
            sap.sin_port = 13571;
            sap.sin_addr.s_addr = 0x100007f; // loopback

        memset(&server, 0, sizeof(server));
        server.sin_family = AF_INET;
        server.sin_port = 13570;
        server.sin_addr.s_addr = 0x100007f; // loopback
        
        cc = sock_create(PF_INET, SOCK_DGRAM, 0, &msock);
        printk("sendRespToServer: Port %d: msock is %d\n"
                        ,p->port_no,cc);
        
        cc = msock->ops->bind(msock, (struct sockaddr *)&sap,
                                                sizeof(sap));
            printk("Port %d: bind is %d\n",p->port_no,cc);
    
            cc = sendto(msock, &radreq, sizeof(radreq), 0,
                        (struct sockaddr*)&server, sizeof(server));
        
        printk("sendRespToServer: data sent to port %d is %d\n",
                p->port_no,cc);
        return 0;
}

int sendto(struct socket *sock, void * buff, size_t len, unsigned
flags, struct sockaddr *addr, int addr_len)
{
    char address[128];
    int err = 0;
    struct msghdr msg;
    struct iovec iov;
    mm_segment_t oldfs;

    iov.iov_base=buff;
    iov.iov_len=len;
    msg.msg_name=NULL;
    msg.msg_namelen=0;
    msg.msg_iov=&iov;
    msg.msg_iovlen=1;
    msg.msg_control=NULL;
    msg.msg_controllen=0;
    msg.msg_flags = flags;

/* portion 1 */
    if(addr)
    {
        move_addr_to_kernel(addr, addr_len, address);
        msg.msg_name=(void *)address;
            msg.msg_namelen=addr_len;
    }
/* end of portion 1 */

    oldfs = get_fs(); set_fs(KERNEL_DS);
    err = sock_sendmsg(sock, &msg, len);
    set_fs(oldfs);
    return err;
}

if the code in portion 1 is removed, there is no kernel oops, but
it will return me a 'end-point not connected' error. however, if
the code remains, then the oops appear. i suspect that the code is
needed for the udp header, but i don't know why it is producing the
oops or is there any things that i have done wrongly?

pls advice. thanx.

Nelson
-------------------------------------------
"You will never walk alone"

-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.rutgers.edu



This archive was generated by hypermail 2b29 : Wed Jun 07 2000 - 21:00:33 EST