Re: ping.c
- From: Martin Baulig <martin home-of-linux org>
- To: Greg lee <lee moore5651 lll hawaii edu>
- cc: gnome-list gnome org
- Subject: Re: ping.c
- Date: Thu, 9 Jul 1998 14:17:18 +0200 (CEST)
-----BEGIN PGP SIGNED MESSAGE-----
Hi,
your fix is wrong since it will break it on libc6. I have a better
approach:
#if (_LINUX_C_LIB_VERSION_MAJOR == 5)
typedef struct icmphdr struct_icmp;
#define icmp_type type
#define icmp_code code
#define icmp_cksum checksum
#define icmp_id un.echo.id
#define icmp_seq un.echo.sequence
#define icmp_gwaddr un.gateway
#else
typedef struct icmp struct_icmp;
#endif
and then use `struct_icmp' instead of `struct icmp'. I'll fix this in CVS
this afternoon.
Martin
On Wed, 8 Jul 1998, Greg lee wrote:
> To: gnome-list@gnome.org
> Subject: ping.c
> From: Greg lee <lee@moore5651.lll.hawaii.edu>
>
>
> As was mentioned, gnome-admin/gxsnmp/app/ping.c uses
> "struct icmp", which Linux appears not to have available.
> I read some Linux header files and, proceeding by names
> and analogy (no understanding), I fixed it. Either my
> fix doesn't work, or there are some other things wrong,
> because I can't get anything sensible from the SNMP
> utility. Anyhow, for what it's worth, here is the revised
> code for Linux. It compiles, anyway.
>
> ...
>
> int
> sendping (u_long address)
> {
> struct in_addr if_addr;
> register struct icmphdr *icp;
> int cc;
> char outpack[sizeof(struct icmphdr)];
>
> memset ((char *)&whereto, '\0', sizeof(struct sockaddr) );
> to->sin_family = AF_INET;
> to->sin_addr.s_addr = address;
> if_addr.s_addr = address;
>
> if (!ident)
> ident = getpid () & 0xFFFF;
>
> icp = (struct icmphdr *)outpack;
> icp->type = ICMP_ECHO;
> icp->code = 0;
> icp->checksum = 0;
> (icp->un).echo.sequence = htons((unsigned short)(ntransmitted++));
> (icp->un).echo.id = ident;
> CLR (ntohs((icp->un).echo.sequence) % mx_dup_ck);
> cc = datalen + 8; /* skips ICMP portion */
> icp->checksum = in_cksum ((u_short *)icp, cc);
> sendto (Pingsocket, (char *)outpack, cc, 0, &whereto,
> sizeof (struct sockaddr));
> return 1;
> }
>
> struct sockaddr_in *
> readping ()
> {
> struct ip *ip;
> register struct icmphdr *icp;
> int hlen;
> int i, cc;
> struct sockaddr_in from;
> struct sockaddr_in *ret;
>
> if (!packet &&(packet = (u_char *)g_malloc(packlen)) == NULL )
> {
> g_print ("ping: g_malloc failed for %d bytes\n", packlen);
> perror ("");
> exit (1);
> }
> errno = 0;
> i = sizeof(from);
> if ((cc = recvfrom (Pingsocket, (char *)packet, packlen, 0, &from, &i))
> < 0)
> return NULL;
> /*
> Lets check the ip header
> */
> ip = (struct ip *)packet;
> hlen = ip->ip_hl << 2;
> icp = (struct icmphdr *)(packet + hlen);
> if (icp->type == ICMP_ECHOREPLY && (icp->un).echo.id == ident)
> {
> ret = (struct sockaddr_in *)g_malloc (sizeof (struct sockaddr_in));
> memcpy ((char *)ret, &from, sizeof (struct sockaddr_in));
> return ret;
> }
> else
> return NULL;
> }
>
>
>
> Greg Lee, lee@hawaii.edu, root@moore5651.lll.hawaii.edu
>
>
> --
> To unsubscribe: mail gnome-list-request@gnome.org with
> "unsubscribe" as the Subject.
>
- -----------------------------------------------------------------
Martin Baulig - Angewandte Mathematik - Universitaet Trier
baulig@castor.uni-trier.de, http://www.home-of-linux.org/
Key: 1024-bit key with ID C8178435 created 1997/01/24
ID: 67 C1 84 A0 47 F5 11 C5 5F 68 4C 84 99 05 C3 92
Finger me for public key or fetch finger.txt from the url above
- ------------------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3i
Charset: noconv
iQCVAwUBNaS00YA8K7jIF4Q1AQF/hQP/ThF81nTqKuW+ZZ3Ug+EYH85CmbctbKMO
FnQJfxhh+SymS1Qdsxw5piDytTaBPVa4dROHMaJq5W49jbiQjkc98vLRfRMLzMkV
YqAQSYQgByZX/ruMpLokTHGq1PoRV98oJlBQ3TzPcSfzx2Rm1m8ucAAwdbnahg1j
ZR6chLsQmvY=
=BHQN
-----END PGP SIGNATURE-----
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]