This is the mail archive of the cygwin-apps@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

sendto function


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);
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]