exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

ADMgetip.c

ADMgetip.c
Posted Apr 25, 2001
Authored by ADM

ADMgetip.c

SHA-256 | 4cb93903b49c02f60fab9cba73cbd8b7c9699a172e0b77e39bb982d347b02741

ADMgetip.c

Change Mirror Download

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <unistd.h>
#include "ip_icmp.h"
#include "ip.h"

#define ICMP_REPLY_TIMEOUT 15

unsigned short
in_cksum (addr, len)
u_short *addr;
int len;
{
register int nleft = len;
register u_short *w = addr;
register int sum = 0;
u_short answer = 0;

/*
* Our algorithm is simple, using a 32 bit accumulator (sum), we add
* sequential 16 bit words to it, and at the end, fold back all the
* carry bits from the top 16 bits into the lower 16 bits.
*/
while (nleft > 1)
{
sum += *w++;
nleft -= 2;
}

/* mop up an odd byte, if necessary */
if (nleft == 1)
{
*(u_char *) (&answer) = *(u_char *) w;
sum += answer;
}

/* add back carry outs from top 16 bits to low 16 bits */
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
sum += (sum >> 16); /* add carry */
answer = ~sum; /* truncate to 16 bits */
return (answer);
}


int getlocalip(unsigned long *src,unsigned long dest)
{
char try = 0;
struct sockaddr_in sin;
int icmp_sock;
int paket_len,sin_len;
char paket[1024];
short* chk;
struct timeval tm,tm1,tm2;
long sec,usec;
float ms;
fd_set fdset;
struct icmphdr* icmp=(struct icmphdr*)paket;
struct iphdr *ip =(struct iphdr *) paket;

kkk:

icmp_sock=socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

FD_ZERO(&fdset);
FD_SET(icmp_sock,&fdset);
tm.tv_sec=ICMP_REPLY_TIMEOUT;;
tm.tv_usec=0;

sin.sin_family=AF_INET;
sin.sin_port=htons(0);
sin.sin_addr.s_addr=dest;

paket_len=8;

icmp->type=8;
icmp->code=0;
icmp->checksum=0;
icmp->un.echo.id=59;
icmp->un.echo.sequence=0;
icmp->checksum=in_cksum(icmp,paket_len);

sin_len=sizeof(sin);
sendto(icmp_sock,&paket,paket_len,0,(struct sockaddr *)&sin,sin_len);

gettimeofday(&tm1,NULL);
if (select(icmp_sock+1,&fdset,NULL,NULL,&tm)==1) {
recvfrom(icmp_sock,&paket,sizeof(paket),0,(struct sockaddr *)&sin,&sin_len);
gettimeofday(&tm2,NULL);
sec=tm2.tv_sec-tm1.tv_sec;
usec=tm2.tv_usec-tm1.tv_usec;
ms=(sec*1000)+((float)usec/1000);
printf("ping: %9.2fms\n",ms);
}
else {
printf("ping timeout\n");
try ++;
if ( try > 2 )return(-1);
close (icmp_sock);
goto kkk;
}

*src=(ip->daddr);
return 0;
}



Login or Register to add favorites

File Archive:

May 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    44 Files
  • 2
    May 2nd
    5 Files
  • 3
    May 3rd
    11 Files
  • 4
    May 4th
    0 Files
  • 5
    May 5th
    0 Files
  • 6
    May 6th
    0 Files
  • 7
    May 7th
    0 Files
  • 8
    May 8th
    0 Files
  • 9
    May 9th
    0 Files
  • 10
    May 10th
    0 Files
  • 11
    May 11th
    0 Files
  • 12
    May 12th
    0 Files
  • 13
    May 13th
    0 Files
  • 14
    May 14th
    0 Files
  • 15
    May 15th
    0 Files
  • 16
    May 16th
    0 Files
  • 17
    May 17th
    0 Files
  • 18
    May 18th
    0 Files
  • 19
    May 19th
    0 Files
  • 20
    May 20th
    0 Files
  • 21
    May 21st
    0 Files
  • 22
    May 22nd
    0 Files
  • 23
    May 23rd
    0 Files
  • 24
    May 24th
    0 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close