On 10/5/06, Alan Menegotto <macnish@xxxxxxxxx> wrote:
Sandeep Mailk wrote:
> Hi...
>
> I am facing an issue while setting the tos bit in socket structure in
> the kernel space. Intially we were using Linux 2.4 kernel and
> following code used to work.
>
> void SetSockOpt( unsigned int sd )
> {
> struct socket *sock ;
> int err = 0 ;
>
> sock = sockfd_lookup(sd, &err);
> sock->sk->protinfo.af_inet.tos = 0xaa ;
> }
>
>
> But when we migrated to 2.6 kernel the code stopped compiling and
> gives error no such field in the structure. Which is because the
> socket structure has been changed.
>
> Has anyone come across with similar problem?
>
>
> --
> Regards,
> Sandeep Malik
>
Look for the TOS bit in the new structure in a last 2.6 kernel
(>2.6.18). From the head I think it's in the IP field on the iphdr
structure (look in include/linux/ip.h).
--
Best Regards
Alan Menegotto
Hi Alan,
Thanks for the comments. The tos filed is in the struct inet_sock and i went through the structure defination and have come to the following conclusion.
sockfd_llokup returns a pointer of type struct socket.
/*******linux/net.h****************/
struct socket {
.......
.......
struct sock *sk;
........
........
};
Now from this socket structure we dereference the sk and get a pointer of type struct sock which is following.
/****************net/sock.h**********************/
struct sock {
......
......
struct sk_filter *sk_filter;
void *sk_protinfo;
kmem_cache_t *sk_slab;
................
void *sk_protinfo;
kmem_cache_t *sk_slab;
................
};
Now from here we can get the pointer sk_protinfo which we type cast to a structure of type inet_sock which is following.
/***************linux/ip.h******************/
struct inet_sock {
............................
............................
int tos; /* TOS */
................................
................................
};
And here is what we are looking for. So i wrote the following code:
void SetSockOpt( unsigned int sd ){
struct inet_sock *ptrinet_sock ;
int err = 0 ;
struct sock *tempSk;
sock = sockfd_lookup(sd, &err);
ptrinet_sock = (struct inet_sock *)(sock->sk->sk_protinfo);
ptrinet_sock->tos = (int)0xb8;
}
But I am getting the error the filed is not a member of the structure.
It would be really helpful if you can tell me what is going wrong????
Regards,
Sandeep Malik