On Tue, 14 May 2002, Glynn Clements wrote: > > Amit Kucheria wrote: > > > I have set some IP options for my sockets (IP_HDRINCL & IP_ROUTER_ALERT) > > using setsockopt(), but when I do a getsockopt(), nothing is reflected. > > I know I am forgetting something very elementary here, but cant put my > > finger on it. Any pointers are welcome. > > IP_HDRINCL and IP_ROUTER_ALERT aren't "options", in the sense of > IP_OPTIONS. So what you mean is that they are not _IP_ options; they are more of _raw_ socket options? > Calling getsockopt() on any of the above options should return > whatever value was set by a preceding setsockopt() call. However, each > of these options is independent; setting one of them won't change any > of the others. > > Also, if you set both IP_HDRINCL and IP_OPTIONS, IP_OPTIONS is > ignored. Then I guess the right question to ask here is: How can I create an IP packet using raw sockets with the IP_ROUTER_ALERT option set? Once I allocate a buffer and fill out the IP and TCP headers, HOW then should i add the IP_ROUTER_ALERT option and change the length of the IP header (ip->ihl and ip->tot_len) corresponding to this option. ------ sample code of what i am doing currently ----------- iph = (struct iphdr *)buffer; tcph = (struct tcphdr *) buffer + sizeof(struct iphdr); printf("Set pointer to IP and TCP headers!\n"); memset(buffer, 0, PACKET_SIZE); /* zero out the buffer */ /* fill in the ip header */ iph->ihl = 5; iph->version = 4; iph->tos = 0; iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr); /* no payload */ iph->id = htonl(23456); /* some value..not imp */ iph->frag_off = 0; iph->ttl = 255; iph->protocol = 48; /* protocol: 6 = TCP, 48 = new */ iph->check = 0; /* compute checksum later */ iph->saddr = inet_addr("1.2.3.4"); /* some spoofed src address */ iph->daddr = dest.sin_addr.s_addr; printf("IP header filled\n"); /* fill in the tcp header */ tcph->source = htons(23456); /* arbit src port */ tcph->dest = htons(P); tcph->seq = random(); /* random sequence no. */ tcph->ack_seq = 0; /* ack sequence is 0 on first packet */ tcph->res1 = 0; /* unused..reserved */ tcph->doff = 0; /* data offset...used for fragmentation ????? */ tcph->fin = 0; tcph->syn = 1; /* initial connection request */ tcph->rst = 0; tcph->psh = 0; tcph->ack = 0; tcph->urg = 0; tcph->res2 = 0; /* unused */ tcph->window = htonl(65535); /* max window size */ tcph->check = 0; /* if set to zero, kernel will fill in correct value */ tcph->urg_ptr = 0; /* urgent pointer */ printf("TCP header filled\n"); iph->check = csum((unsigned short *)buffer, iph->tot_len >> 1); -- I'm an angel!!! Honest! The horns are just there to hold the halo up straight. ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^ Amit Kucheria EECS Grad. Research Assistant University of Kansas @ Lawrence (R): +1-785-830-8521 ||| (C): +1-785-760-2871 ____________________________________________________ - : send the line "unsubscribe linux-net" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html