I have a c program that works under gcc, but silently segfaults tcc during
compile.

 

Are there some debugging options for tcc to see what is going on in order to
fix my program?

 

Thanks,

 

John Refling

--

 

// ping 10.11.12.1 -> 10.11.12.255

 

#ifdef __TINYC__

#include <sys/unistd.h>

#include <stdio.h>

#include <stdlib.h>

#include "c:/win/tcc/include/winapi/windef.h"

#include "c:/win/tcc/include/winapi/winbase.h"

 

#define INADDR_NONE 0xffffffff // should be in one of the below

HANDLE WINAPI IcmpCreateFile(VOID);

 

typedef ULONG IPAddr;

typedef ULONG IPMask;

typedef ULONG IP_STATUS;

typedef struct icmp_echo_reply {

    IPAddr Address;

    ULONG Status;

    ULONG RoundTripTime;

    USHORT DataSize;

    USHORT Reserved;

    PVOID Data;

    struct ip_option_information Options;

} ICMP_ECHO_REPLY,*PICMP_ECHO_REPLY;

 

typedef struct ip_option_information {

    UCHAR Ttl;

    UCHAR Tos;

    UCHAR Flags;

    UCHAR OptionsSize;

    PUCHAR OptionsData;

} IP_OPTION_INFORMATION,*PIP_OPTION_INFORMATION;

 

DWORD WINAPI IcmpSendEcho(HANDLE IcmpHandle,IPAddr DestinationAddress,LPVOID
RequestData,WORD RequestSize,PIP_OPTION_INFORMATION RequestOptions,LPVOID
ReplyBuffer,DWORD ReplySize,DWORD Timeout);

#endif

 

int __cdecl main(int argc, char **argv)  {

 

    // Declare and initialize variables

    

    HANDLE hIcmpFile;

    unsigned long ipaddr = INADDR_NONE;

    DWORD dwRetVal = 0;

    char SendData[32] = "Data Buffer";

    LPVOID ReplyBuffer = NULL;

    DWORD ReplySize = 0;

    

    char *base = malloc(100);

    if (argc == 2) {

        strcpy(base, argv[1]);

    } else {

        strcpy(base, "10.11.12");

    }

    strcat(base, ".");

    char *end = &base[strlen(base)];

 

    hIcmpFile = IcmpCreateFile();

    if (hIcmpFile == INVALID_HANDLE_VALUE) {

        printf("Unable to open handle.\n");

        printf("IcmpCreatefile returned error: %ld\n", GetLastError() );

        return 1;

    }    

 

    ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);

    ReplyBuffer = (VOID*) malloc(ReplySize);

    if (ReplyBuffer == NULL) {

        printf("Unable to allocate memory\n");

        return 1;

    }    

 

    int xxx;

    char *numb = malloc(10);

    for (xxx = 1; xxx < 255; xxx++) {

        sprintf(numb, "%d", xxx);

        strcpy(end, numb);

 

        ipaddr = inet_addr(base);

        if (ipaddr == INADDR_NONE) {

            printf("usage: %s IP address\n", argv[0]);

            return 1;

        }

    

        dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData,
sizeof(SendData), 

            NULL, ReplyBuffer, ReplySize, 30);

 

        if (dwRetVal != 0) {

            PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;

            struct in_addr ReplyAddr;

            ReplyAddr.S_un.S_addr = pEchoReply->Address;

//          printf("Sent icmp message to %s\n", base);

            if (dwRetVal > 1) {

//              printf("Received %ld icmp message responses\n", dwRetVal);

//              printf("Information from the first response:\n"); 

            }    

            else {    

//              printf("Received %ld icmp message response\n", dwRetVal);

//              printf("Information from this response:\n"); 

            }    

//          printf("Received from %s\n", inet_ntoa( ReplyAddr ) );

//          printf("Status = %ld\n", pEchoReply->Status);

 

            // only print out if status is zero.  ping command can succeed

            // but the dest can be unreachable.  don't want to know about
that.

            if (0 == pEchoReply->Status) {

                printf("%s\n", base);

            }

 

//          printf("Roundtrip time = %ld milliseconds\n",
pEchoReply->RoundTripTime);

//          printf("%s: %ld ms\n", base, pEchoReply->RoundTripTime);

        } else {

//          printf("Call to IcmpSendEcho failed.\n");

//          printf("!IcmpSendEcho(%s): %ld\n", base, GetLastError() );

//          return 1;

        }

    }

    return 0;

}

 

_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to