Linux - KernelThis forum is for all discussion relating to the Linux kernel.
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.
I am new with programming for networking in Linux. I know about the basics of making kernel modules and some of the concepts of related to my work (recently studied). I am working on a project where i don't have any experience but i am trying and looking from forums.
My supervisor asked me to make a program to send IP packet to the other network.
I want to struct a packet and send it from source to destination.
I have no idea about how to do this. any body can suggest me any sample program for this? I searched on internet but may be i am not well known of this field so i couldn't use the proper terms for searching. if you guys can suggest me some links related to this work than this will be great help for me..
As this is my startup in new field, so i would prefer to follow a a complete example that i can get whats going on each step. It would be better for my future work in this project.
thanks
Do you have to do this in kernel mode? It would be simpler to use user mode socket programming. There's lots of good documentation to do it there.
I don't know much about kernel level network programming, so I'd advise checking out the networking chapters of a Linux kernel book -- I've been partial to Robert Love's books, personally.
and i have found a way to struct ip header and udp header and to send the packet from source to destination, for starting i think it is a good step. but i am facing a problem, after i send packet to loopback i dont receive it using sniffer.c. I am worried that either it is possible to receive sent packets on loop back or not!? if it is possible to send then why i am not receiving packet count there.
////////////////////here is my code///////////////////
//Create the IP header
struct ipheader {
unsigned char iph_ihl:4, iph_ver:4;
unsigned char iph_tos;
unsigned short int iph_len;
unsigned short int iph_ident;
unsigned char iph_flags;
unsigned short int iph_offset;
unsigned char iph_ttl;
unsigned char iph_protocol;
unsigned short int iph_chksum;
unsigned int iph_sourceip;
unsigned int iph_destip;
};
//Create the UDP Header
struct udpheader {
unsigned short int udph_srcport;
unsigned short int udph_destport;
unsigned short int udph_len;
unsigned short int udph_chksum;
}; /* total udp header length: 8 bytes (= 64 bits) */
// Function for checksum calculation
unsigned short csum(unsigned short *buf, int nwords)
{ //
unsigned long sum;
for(sum=0; nwords>0; nwords--)
sum += *buf++;
sum = (sum >> 16) + (sum &0xffff);
sum += (sum >> 16);
return (unsigned short)(~sum);
}
// Source IP, source port, target IP, target port from command line
int main(int argc, char *argv[]){
int sd;
char buffer[PCKT_LEN];
struct ipheader *ip = (struct ipheader *) buffer;
struct udpheader *udp = (struct udpheader *) (buffer + sizeof(struct ipheader));
// Source and destination addresses: IP and port
struct sockaddr_in sin, din;
int one = 1;
const int *val = &one;
memset(buffer, 0, PCKT_LEN);
// Inform the kernel do not fill up the packet structure
if(setsockopt(sd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0)
{
perror("socketpot() error");
exit (-1);
}
This is perfectly fine, and sending 20 packets. But unfortunately in monitoring the packet reception i don't receive any packet for loopback.
NOTE: I am using this format for loopback correct me if i am wrong anywhere:
Quote:
# ./myProgram 127.0.0.1 22 127.127.0.0.1 8008
i have also tried give same port number for both also but its not working in that way which i want.
I am newbie if i am making some stupid mistake then please make me correct..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.