|
-
September 24th, 2025, 11:24 AM
#1
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
-
September 25th, 2025, 01:15 AM
#2
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);
-
September 25th, 2025, 06:54 AM
#3
Re: Build errors
 Originally Posted by salem_c
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.
-
September 26th, 2025, 02:57 AM
#4
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)
-
September 28th, 2025, 10:34 AM
#5
Re: Build errors
 Originally Posted by 2kaud
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.
 Originally Posted by 2kaud
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|