ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language 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.
unsigned short checksum(unsigned short *addr, int len)
{
register int sum = 0;
u_short answer = 0;
register u_short *w = addr;
register int nleft = len;
while (nleft > 1)
{
sum += *w++;
nleft -= 2;
}
if (nleft == 1)
{
*(u_char *) (&answer) = *(u_char *) w;
sum += answer;
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
answer = ~sum;
return (answer);
}
int
main(int agrc, char * agrv[])
{
socklen_t size;
hostent *host;
icmphdr *icmp, *icmpRecv;
iphdr *ip;
in_addr a;
int sock, lenght;
int ttl=0;
sockaddr_in sendSockAddr;
char *addrString;
const char *adres="192.168.8.9";
int i;
char *packet;
unsigned short int pid=getpid();
why?... no why, but how
Imagine situation:
I want send icmp (request) packet with ip address of xy(for example my chief ) to router and my chief get icmp (replay) from router. How do i do
sockaddr_in soc;
iphdr *ip;
.
.
.
soc.sin_addr.s_addr = inet_addr("10.0.0.2"); // this just change destination address
.
.
ip->saddr=inet_addr("10.0.0.2); // what do this ???
"destroy the stream" some bad packets can destroy connection ?
"destroy the stream" some bad packets can destroy connection ?
No, in TCP, there is no connection as such, but a stream of packages. Imagine you're downloading a pretty big file (an ISO, say) from somewhere. Of course, that file is not being sent an one lump, but instead is broken up in segments, each with (among others) a sequence numbner, a sender IP and a recipient IP. Imagine one of these being "lost" due to an altered IP address. You never have a connection, but merely send a packet with a request to some server having your IP and the server's IP. The reply is one or more packets depending on the size of the requested data. The packets arrive because they are being routed to their destination.
Upon reception, your system (one of the OSI layers in fact) strips these extra's and reassembles the whole file using the sequence numbers...
But, I agree, it is an intersting excercise...and well worth this read, I guess...
Yes I think my program is possible to do but I do not know how it wrote in c++. "Some server having you IP address" you mean DNS server or server with (ISO) or DHCP or .... ?
Hmm, okay, let's go from the start. You get an IP address from you provider. As soon as the lease is up, your PC requests a new one. Google does"nt need to request a new one; Google should NOT request a new one. It has a fixed IP addres. Somewhere in the tables of the DNS system, there is a name - IP pair for Google - but others are in there as well. Those with a fixed IP address, not people like you and me, we are just "lending" the IP address.
If you type in www.google.com - your browser requests the matching IP address and sends a packet to the IP address (and Google) with a "get" request for the main page. That packet has two IP addresses: yours and Google's.
If you want to change the destination of that packet, you could (in pure theory) extract Google's IP address and replace it with Yahoo's address. Not very productive, but very possible.
You'd have to capture these packets whizzing by first, though
Quote:
Chief and I are in one subnet
Of course, that is a requirement if you want to interact...good assessment.
That raises another question: what happens in this situation:
I get my lease from my provider for 1 hour; I do a big download of a complete linux distro but alas, slow link, so the download takes more than 1 hour. I get a new lease (with a different IP) from my provider... what happens to the stream?
The stream gets ... broken. However, in case of a torrent, the software is clever enough to pick it back up...
But...interesting question. Well, TCP/IP is clever enough to notice some bits missing, and will request (with the new IP address) the missing pieces...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.