Hello everybody
im just creating an client that is going to communicated with Iterative server.
and i get this error:
warning: the `gets' function is dangerous and should not be used.
and i think this is related to this code:
printf("Enter message to be sent:\n");
gets(send_buf);
and this is my code for the client could anyone could check it to see if am on the right track: -
/**************************************************************************/
-
/* Generic client example is used with connection-oriented server designs */
-
/**************************************************************************/
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <sys/socket.h>
-
#include <netinet/in.h>
-
#include <string.h>
-
-
#define EOB "$$"
-
#define KB_size 1024
-
int ClientNo = 0;
-
-
main (int argc, char *argv[])
-
{
-
int len, rc;
-
int sockfd;
-
char send_buf[80];
-
char recv_buf[80];
-
char KB_buff[KB_size];
-
int intPort;
-
struct sockaddr_in addr;
-
-
/*************************************************/
-
/* Create an AF_INET stream socket */
-
/*************************************************/
-
sockfd = socket(AF_INET, SOCK_STREAM, 0);
-
if (sockfd < 0)
-
{
-
perror("socket");
-
exit(-1);
-
}
-
-
/*************************************************/
-
/* Initialize the socket address structure */
-
/*************************************************/
-
memset(&addr, 0, sizeof(addr));
-
addr.sin_family = AF_INET;
-
addr.sin_addr.s_addr = htonl(INADDR_ANY);
-
addr.sin_port = htons(intPort);
-
-
/*************************************************/
-
/* Connect to the server */
-
/*************************************************/
-
rc = connect(sockfd,(struct sockaddr *)&addr, sizeof(struct sockaddr_in));
-
if (rc < 0)
-
{
-
perror("connect");
-
close(sockfd);
-
exit(-1);
-
}
-
printf("Connect completed.\n");
-
-
/*************************************************/
-
/* Enter data buffer that is to be sent */
-
/*************************************************/
-
printf("Enter message to be sent:\n");
-
gets(send_buf);
-
-
/*************************************************/
-
/* Send data buffer to the worker job */
-
/*************************************************/
-
len = send(sockfd, send_buf, strlen(send_buf) + 1, 0);
-
if (len != strlen(send_buf) + 1)
-
{
-
perror("send");
-
close(sockfd);
-
exit(-1);
-
}
-
printf("%d bytes sent\n", len);
-
-
/*************************************************/
-
/* Receive data buffer from the worker job */
-
/*************************************************/
-
len = recv(sockfd, recv_buf, sizeof(recv_buf), 0);
-
if (len != strlen(send_buf) + 1)
-
{
-
perror("recv");
-
close(sockfd);
-
exit(-1);
-
}
-
printf("%d bytes received\n", len);
-
-
/*************************************************/
-
/* Close down the socket */
-
/*************************************************/
-
close(sockfd);
-
}
2 29991
gets() is deprecated and unsafe.
Use fgets() instead.
Look at man :
This is a _dangerous_ function, as it has no way of checking the
amount of space available in BUF. One of the attacks used by the Inter-
net Worm of 1988 used this to overrun a buffer allocated on the stack
of the finger daemon and overwrite the return address, causing the dae-
mon to execute code downloaded into it over the connection.
Warning: The gets function is very dangerous because it provides no protection against overflowing the string s. The GNU library includes it for compatibility only. You should always use fgets or getline instead. To remind you of this, the linker (if using GNU ld) will issue a warning whenever you use gets.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Stuart Anderson |
last post by:
I am looking to use Ken Stephenson's CirclePack program
(http://www.math.utk.edu/~kens/) with some tiling programs written by
Cannon, Floyd, Parry. The programs I want to use are subdivide.c...
|
by: jose_luis_fdez_diaz_news |
last post by:
Hi,
If I don't include <libgen.h> I get then warnig below in regcmp call:
warning: improper pointer/integer combination: op "="
but if I include it the warning is not shown, but them program...
|
by: Lee |
last post by:
Hi
Whenever I use the gets() function, the gnu c compiler gives a
warning that it is dangerous to use gets(). Is this due to the
possibility of array overflow? Is it correct that the program...
|
by: Brendan |
last post by:
Hi,
I'm trying to mimic the IPC/messaging system of an specific OS in a
portable way by using GCC's library. The IPC system uses buffered
asynchronous messages, where any thread can send a...
|
by: paytam |
last post by:
hi all
can you tell me what's the wrong with this code?
I use gcc compiler,but when I wanted to use
gets() function in my code but it takes a dangerous warning(the gets
function is dangerous...
|
by: metalinc |
last post by:
hi...im new to C programming...need help...tried to run this code but got this error
fork.c: In function ‘parse’:
fork.c:44: warning: comparison between pointer and integer
fork.c:51: warning:...
|
by: Dave Stafford |
last post by:
I have a macro that I use across the board for freeing ram. I'd like to
clean up my code so I don't get these warnings.
#define sfree(x) _internal_sfree((void **)&x)
#define _internal_sfree(x)...
|
by: Rajesh V |
last post by:
When I use gets() function, the gcc compiler gives the warning - gets function is dangerous and should not be used. What is the problem in using it and how to avoid it ?
|
by: pereges |
last post by:
I'm getting a warning on my linux gcc compiler:
/tmp/ccXgHa9s.o(.text+0x48): In function `main':
: warning: the `gets' function is dangerous and should not be used.
And here's where I used...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |