bdf0d928   
   From: philip+usenet@paeps.cx   
      
   dbtouch wrote:   
   > I am evaluating raw udp performance with a simple program   
      
   How do you define "raw udp performance"? What are you trying to measure?   
      
   > my question is that when I set ip header, what is iph->ip_len I should set   
   > if my packet size is 1024.   
      
   The length field in the header is the total length of your datagram, including   
   the header.   
      
   > How about iph->ip_off, what value I need set?   
      
   Unless you are fragmenting, it should be set to 0.   
      
   > Since I send raw udp packet, I think I do not need to set TCP header (am I   
   > right?)   
      
   What do you mean with a "raw udp packet"? What is raw about it? You do not   
   need a TCP header for a UDP datagram. You need a UDP header. Unless you want   
   to encapsulate UDP in TCP, which is unlikely.   
      
   > In my box, sizeof(struct ip) is 20(dec), so I hardcoded iph->ip_sum.   
      
   The size of the IPv4 header without options is 20 bytes so this makes sense.   
   It's fairly simple to compute the header checksum though. Most network stacks   
   will also happily do this for you.   
      
   > int s = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);   
      
   This does not make much sense. Why are you using a raw socket to send UDP?   
   You can save a lot of trouble by using SOCK_DGRAM with IPPROTO_UDP. I also   
   can't imagine why you would pass IPPROTO_TCP to a SOCK_RAW. I've not checked   
   any network stacks, but I don't think the protocol field is checked at all   
   when creating a raw socket. I may be wrong about that though.   
      
   > char datagram[1024];   
   > struct ip *iph = (struct ip *)datagram;   
   > struct sockaddr_in sin;   
   > int *pSequence = (int *)(datagram + sizeof(struct ip));   
      
   Why are you putting a kilobyte of data on the stack if you're only going to   
   actually use what looks like 24 bytes of it? You're writing your this int   
   right behind your IP header, leaving no room for a UDP header. You're not   
   adding a UDP header anywhere either and since you're using a raw socket,   
   neither is the network stack.   
      
   > iph->ip_p = 6;   
      
   Protocol 6 is TCP. You're not adding a TCP header though, so any receiving   
   network stack is likely to drop this packet rather than pushing it up to any   
   listening sockets. The correct protocol for UDP is 17. You'll have to add a   
   UDP header between your IP header and your payload if you want other network   
   stacks to take your packet though.   
      
   > iph->ip_sum = 0xfff6;   
      
   I've not checked the correctness of this. Why don't you just calculate it?   
      
   > rc = sendto(s, datagram, iph->ip_len, 0, (struct   
   > sockaddr *) &sin, sizeof(sin));   
      
   Depending on your network stack, you'll need to set the HEADER_INCL socket   
   option before sending a raw datagram, otherwise the network stack will prepend   
   an IP header. So if you're seeing any data on the wire at all, it's probably   
   not the data you wrote.   
      
   I think you need to find a copy of Richard Stevens' "TCP/IP Illustrated vol.1"   
   or a similarly thorough introduction to the Internet Protocol before you write   
   more code. Once you understand the Internet Protocols beter, you'll find the   
   socket interface will make a lot more sense.   
      
    - Philip   
      
   --   
   Philip Paeps Please don't email any replies   
   philip@paeps.cx I follow the newsgroup.   
      
    BOFH Excuse #441:   
    Hash table has woodworm   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|