www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-apps/2000/07/12/08:12:56

Mailing-List: contact cygwin-apps-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-apps-owner AT sourceware DOT cygnus DOT com
List-Subscribe: <mailto:cygwin-apps-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-apps/>
List-Post: <mailto:cygwin-apps AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-apps-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/lists.html#faqs>
Delivered-To: mailing list cygwin-apps AT sources DOT redhat DOT com
Message-ID: <007d01bfebfb$1aff7090$f7c723cb@lifelesswks>
From: "Robert Collins" <robert DOT collins AT itdomain DOT com DOT au>
To: "cygapp" <cygwin-apps AT sourceware DOT cygnus DOT com>
Subject: sendto function
Date: Wed, 12 Jul 2000 22:17:09 +1000
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700

Is the sendto function capable of sending icmp packets?

The following code fragment is not working properly...
It runs on Un*x at the moment, and I'm hoping for some hint/direction for me
to alter it, or alter cygwin to get it working.

pingerLog outputs errno and strerror().

the first time the function is called, no error is set, but AFAICT, no
packet is generated.
The second, third, fourth.. time the function is called, error (2) No such
file or directory is returned.
I've done a strace on this (I'll attach it anyone wants). and it shows
cygwin_send recieving an error
WSAENOSOCK - unless I've got my wires crossed and this error turns up
elsewhere !

I know this is probably not enough information, and to run gdb,  but as I am
not recieving a flat out crash, and do not know what the innards of cygwin
operating normally are, I thought I'd ask first.

Alternatively, if anyone knows of/has code that can send and icmp ping and
will compile and run under cygwin I'll happily take that and leave this
issue for a later date.

Thanks in advance,
Rob

(strace excerpt)====
 1930 52886463 [main] pinger 1504 _open: -1 = open
(/usr/local/etc/zoneinfo/posixrules, 0x10000)^M
 1109 52887572 [main] pinger 1504 _write: write (2, 0x248F294, 95)^M
  238 52887810 [main] pinger 1504 fhandler_base::write: after write, name
some disk file, rpos 95^M
  196 52888006 [main] pinger 1504 _write: 95 = write (2, 0x248F294, 95)^M
19330 52907336 [main] pinger 1504 set_winsock_errno: 10038 (WSAENOTSOCK) ->
108^M
  296 52907632 [main] pinger 1504 cygwin_send: -1 = send (1, 248FA94, 0,
0)^M
=======

static void
pingerSendEcho(struct in_addr to, int opcode, char *payload, int len)
{
    LOCAL_ARRAY(char, pkt, MAX_PKT_SZ);
    struct icmphdr *icmp = NULL;
    icmpEchoData *echo;
    int icmp_pktsize = sizeof(struct icmphdr);
    struct sockaddr_in S;
    memset(pkt, '\0', MAX_PKT_SZ);
    icmp = (struct icmphdr *) (void *) pkt;
    /*
     * cevans - beware signed/unsigned issues in untrusted data from
     * the network!!
     */
    if (len < 0) {
        len = 0;
    }
    icmp->icmp_type = ICMP_ECHO;
    icmp->icmp_code = 0;
    icmp->icmp_cksum = 0;
    icmp->icmp_id = icmp_ident;
    icmp->icmp_seq = (u_short) icmp_pkts_sent++;
    echo = (icmpEchoData *) (icmp + 1);
    echo->opcode = (unsigned char) opcode;
    echo->tv = current_time;
    icmp_pktsize += sizeof(icmpEchoData) - MAX_PAYLOAD;
    if (payload) {
        if (len > MAX_PAYLOAD)
            len = MAX_PAYLOAD;
        xmemcpy(echo->payload, payload, len);
        icmp_pktsize += len;
    }
    icmp->icmp_cksum = in_cksum((u_short *) icmp, icmp_pktsize);
    S.sin_family = AF_INET;
    /*
     * cevans: alert: trusting to-host, was supplied in network packet
     */
    S.sin_addr = to;
    S.sin_port = 0;
    assert(icmp_pktsize <= MAX_PKT_SZ);
    sendto(icmp_sock,
        pkt,
        icmp_pktsize,
        0,
        (struct sockaddr *) &S,
        sizeof(struct sockaddr_in));
    pingerLog(icmp, to, 0, 0);
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019