Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
unsigned short in_cksum(unsigned short *addr, int len)
{
int nleft = len;
int sum = 0;
unsigned short *w = addr;
unsigned short answer = 0;
while (nleft > 1)
{
sum += *w++;
nleft -= 2;
}
if (nleft == 1)
{
*(unsigned char *) (&answer) = *(unsigned char *) w;
sum += answer;
}
sum = (sum >> 16) + (sum & 0xFFFF);
sum += (sum >> 16);
answer = ~sum;
return (answer);
}
/*UDP Checksum*/
unsigned short in_cksum_udp(int src, int dst, unsigned short *addr, int len)
{
struct psd_udp buf;
First: Check the link in my signature on how to use [code][/code] tags.
I compiled your program and see the same error. The manual page doesn't help much.
I went for a brief search for a sendto() example and found one here. Check that out because it is very simple.
One issue may be that you've chosen to do SOCK_RAW versus SOCK_DGRAM which is the normal socket type for UDP.
I don't think you need to fully create the packet unless you're modifying the content from a standard UDP data frame. You can see in the example that you can choose the port and then send a data stream via UDP without worrying about constructing the packet, nor setting any socket options.
I'd start with the equivalent of that example and then modify as you see fit.
Note also that I do NOT need to be root to run that example, but because (I believe) you're using SOCK_RAW, then you need to be sudo or root to run what you've coded.
Thank you rtmistler for a very nice explanation. Very much appreciated.
@norobro your analysis is spot on, that's where the problem was. I gave the size of u_char * but not the size of packet which was the root cause. I changed that to sizeof(ip_hdr)+sizeof(udp_hdr)+sizeof(data) and it worked like charm.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.