CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Build errors

  1. #1
    Join Date
    Nov 2006
    Posts
    318

    Build errors

    Hello. I'm trying to build a packet sniffer from here. I got about 5 errors when trying to build this source code.

    Code:
    'local->h_addr_list[in]' could be '0':  this does not adhere to the specification for the function 'memcpy'. 
    'temp_data' could be '0':  this does not adhere to the specification for the function 'fwrite'. 
    Return value ignored: '_getch'.
    Dereferencing NULL pointer 'buf'. 
    Using uninitialized memory 'addr'.
    'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
    'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
    'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings

  2. #2
    Join Date
    Nov 2018
    Posts
    165

    Re: Build errors

    Well that's what you get when you compile decade++ old code with new tools able to inspect the code for more issues.

    > 'local->h_addr_list[in]' could be '0':
    Code:
        for (i = 0; local->h_addr_list[i] != 0; i++) {
            memcpy(&addr, local->h_addr_list[i], sizeof(struct in_addr));
            printf("Interface Number: %d Address: %s\n", i, inet_ntoa(addr));
        }
        printf("\nEnter the interface number you would like to sniff: ");
        scanf_s("%d", &in);
        memset(&dest, 0, sizeof(dest));
        memcpy(&dest.sin_addr.s_addr, local->h_addr_list[in], sizeof(dest.sin_addr.s_addr));
    The compiler learnt from the for loop that some subscript of h_addr_list yields a NULL pointer.
    Further, neither the result of scanf_s is checked, nor the resulting value stored in in.

    Code:
        int numValidInterfaces = 0;
        for (i = 0; local->h_addr_list[i] != 0; i++) {
            memcpy(&addr, local->h_addr_list[i], sizeof(struct in_addr));
            printf("Interface Number: %d Address: %s\n", i, inet_ntoa(addr));
            numValidInterfaces++;
        }
        printf("\nEnter the interface number you would like to sniff: ");
        // 
        if ( scanf_s("%d", &in) == 1 && in >= 0 && in < numValidInterfaces ) {
            memset(&dest, 0, sizeof(dest));
            memcpy(&dest.sin_addr.s_addr, local->h_addr_list[in], sizeof(dest.sin_addr.s_addr));
        } else {
            // Some error message about the user not being able to
            // follow instructions.
            // Then return with an error.
        }
    > 'temp_data' could be '0':
    You don't check for the malloc call returning NULL.
    Code:
        char *temp_data = (char *)malloc(DATA_SIZE);

  3. #3
    Join Date
    Nov 2006
    Posts
    318

    Re: Build errors

    Quote Originally Posted by salem_c View Post
    Well that's what you get when you compile decade++ old code with new tools able to inspect the code for more issues.
    I was looking for a packet sniffer to learn from and found the first I could find. I suppose I'll look a little deeper this time.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,916

    Re: Build errors

    There are loads of older c/c++ code available on the Internet. You may find similar issues with other found code.

    You don't say which compiler/os you're using. Note that some code is for a Posix system (eg Linux/gcc) and isn't easily converted to say Windows/Visual Studio as there are header differences.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Nov 2006
    Posts
    318

    Re: Build errors

    Quote Originally Posted by 2kaud View Post
    There are loads of older c/c++ code available on the Internet. You may find similar issues with other found code.
    I find that looking for code that old is ridiculously difficult building when you can't reach the authors. Been searching all through github for working src.

    Quote Originally Posted by 2kaud View Post
    You don't say which compiler/os you're using. Note that some code is for a Posix system (eg Linux/gcc) and isn't easily converted to say Windows/Visual Studio as there are header differences.
    Visual C++ 2022.

    Starting from scratch again....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured