Networking Forums

Networking Forums > Computer Networking > Linux Networking > Problems with setsocket options at IP level for RECVTTL and RECVTOS

Reply
Thread Tools Display Modes

Problems with setsocket options at IP level for RECVTTL and RECVTOS

 
 
bhaskar.borthakur@gmail.com
Guest
Posts: n/a

 
      08-12-2005, 05:45 PM
Hi all,

I am trying to get the TOS and TTL values for a received multicast UDP
packet. The code I have written (pasted below) works well if I try to
get just the TTL or try to get just the TOS. However, if I try to get
both the TTL and TOS it does not work. The length of the control
message (msghdr. msg_controllen) comes out to be 0 in this case.

I am assuming that once I do setsockopt with the IP_RECVTOS option and
IP_RECVTTL option, and then I do a recvmsg on the socket, I should be
able to get the TTL and TOS as control message in the structure msghdr.
Am I correct? I would guess so since they work individually but not
together.


Please let me know if I am doing anything wrong or if anyone else had
faced this problem before.

Thanks
bhaskar

Linux version: GV 2.3.4 Linux/RedHat Enterprise 3 AS
Compiler version: gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20)




// setting the RECVTTL option
unsigned char tos = 1;
int tosSize = sizeof(tos);
if(setsockopt(sd,IPPROTO_IP, IP_RECVTOS, &tos,tosSize)<0)
{
printf("cannot set RECV_TOS \n");
exit(1);
}

// setting the RECVTOS option
unsigned char ttl = 1;
int ttlSize = sizeof(ttl);
if(setsockopt(sd,IPPROTO_IP, IP_RECVTTL, &ttl,ttlSize)<0)
{
printf("cannot set RECV_TTL \n");
exit(1);
}

/* infinite server loop */
while(1) {
struct msghdr ttlHdr;

ttlHdr.msg_control = (struct cmsghdr*)malloc (10*sizeof(struct
cmsghdr));

// Peek at message header to get the TTL and TOS
if ( recvmsg (sd, &ttlHdr, MSG_PEEK) == -1 )
{
printf("Error in recvmsg");
exit(0);
}
printf("The lenght of control message = %d\n",
ttlHdr.msg_controllen);

struct cmsghdr *cmsg;
int *ttlptr;
unsigned char *tosptr;
int received_ttl;
unsigned char received_tos;

int found = 0;

/* Receive auxiliary data in msgh */
for (cmsg = CMSG_FIRSTHDR(&ttlHdr);
cmsg != NULL;
cmsg = CMSG_NXTHDR(&ttlHdr,cmsg))
{
printf("type = %d \n", cmsg->cmsg_type);

if (cmsg->cmsg_level == IPPROTO_IP
&& cmsg->cmsg_type == IP_TTL)
{
ttlptr = (int *) CMSG_DATA(cmsg);
received_ttl = *ttlptr;
printf ("------------>The ttl received is %d\n", received_ttl);
found = 1;
}


if (cmsg->cmsg_level == IPPROTO_IP
&& cmsg->cmsg_type == IP_TOS)
{
tosptr = (unsigned char*) CMSG_DATA(cmsg);
received_tos = *tosptr;
printf ("------------>The tos received is %x\n", received_tos);
found = 1;
}

}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with setsocket options at IP level for RECVTTL and RECVTOS bhaskar.borthakur@gmail.com Linux Networking 0 08-12-2005 05:45 PM
network actual bitrate (application level, tcp packet level) nirnimesh@gmail.com Linux Networking 1 01-24-2005 11:24 PM
Firewalling at the domain users level instead of network level Santos Linux Networking 1 07-18-2004 02:16 PM
Noise level Richard Rollins Broadband 18 07-13-2004 08:30 PM
Trigger level met. Sean McConkey Broadband 4 02-05-2004 07:17 AM



1 2 3 4 5 6 7 8 9 10 11