I wrote this c program to send a struct from the client to a server which has the same struct initialized in it. I used gcc feature of cygwin to compile it and I got the following error. Can anyone tell me wha could possibly have gone wrong because I was not able to figure out anything. -
348 [main] c 7160 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack)
-
Segmentation fault (core dumped)
-
-
#include <stdio.h> /* standard C i/o facilities */
-
#include <stdlib.h> /* needed for atoi() */
-
#include <unistd.h> /* Unix System Calls */
-
#include <sys/types.h> /* system data type definitions */
-
#include <sys/socket.h> /* socket specific definitions */
-
#include <netinet/in.h> /* INET constants and stuff */
-
#include <arpa/inet.h> /* IP address conversion stuff */
-
#include <netdb.h> /* Name lookups (gethostbyname) */
-
#include <fcntl.h> /* Read and Write Fucntions */
-
#include <string.h> /* FoR Memset() */
-
-
-
void DieWithError(char *errorMessage)
-
{
-
perror(errorMessage);
-
exit(1);
-
}
-
-
-
struct message
-
{
-
int packet_num;
-
int syn;
-
int ack;
-
char * msg;
-
};
-
-
int main(int argc, char *argv[])
-
{
-
int sock;
-
int fd;
-
int x;
-
int packet_count;
-
struct sockaddr_in echoServAddr;
-
struct sockaddr_in fromAddr;
-
unsigned short echoServPort;
-
unsigned int fromSize;
-
char *servIP;
-
char *buff;
-
struct message recvMsg;
-
struct message sendMsg;
-
struct message sendMsgBuff;
-
int stringLen;
-
-
if((argc < 3 ) || ( argc > 4 ))
-
{
-
fprintf(stderr,"Usage: %s <Server IP> <File name> [<Port Number>]\n",argv[0]);
-
exit(1);
-
}
-
servIP = argv[1];
-
-
if(argc == 4)
-
echoServPort = atoi(argv[3]);
-
else
-
echoServPort = 7;
-
-
-
/* Create a datagram/UDP socket */
-
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
-
DieWithError("socket() failed");
-
-
memset(&echoServAddr, 0, sizeof(echoServAddr));
-
memset(&recvMsg,0,sizeof(recvMsg));
-
memset(&sendMsg,0,sizeof(sendMsg));
-
echoServAddr.sin_family = AF_INET;
-
echoServAddr.sin_addr.s_addr = inet_addr(servIP);
-
echoServAddr.sin_port = htons(echoServPort);
-
-
fd = open(argv[2],O_RDONLY);
-
if(fd==-1)
-
DieWithError("File opening failed");
-
-
buff = (char*)(malloc(10000));
-
x = read(fd,buff,sizeof(buff));
-
if(x==-1)
-
DieWithError("File read failed");
-
-
packet_count=0;
-
-
sendMsg.packet_num = htonl(packet_count);
-
sendMsg.syn = 0;
-
sendMsg.ack = 1;
-
buff = argv[2];
-
buff[strlen(buff) + 1] = '\0';
-
sendMsg.msg = buff;
-
-
/* Send the string to the server */
-
if((sendto(sock, (struct message *) &sendMsg, sizeof(sendMsg), 0, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr))) != sizeof(sendMsg))
-
DieWithError("sendto() sent a different number of bytes than expected");
-
-
/* Recv a response */
-
fromSize = sizeof(fromAddr);
-
if(stringLen = recvfrom(sock, (struct message *) &recvMsg, sizeof(recvMsg), 0, (struct sockaddr*) &fromAddr, &fromSize) != sizeof(sendMsg))
-
DieWithError("recvfrom() failed");
-
-
if(recvMsg.ack != sendMsg.ack)
-
DieWithError("Message Not Acknowledged properly");
-
-
if (echoServAddr.sin_addr.s_addr != fromAddr.sin_addr.s_addr)
-
{
-
fprintf(stderr,"Error: received a packet from unknown source.\n");
-
exit(1);
-
}
-
-
/* null-terminate the received data */
-
printf("Received Acknowledgement : %s\n", recvMsg.ack);
-
-
close(sock);
-
exit(0);
-
}
-
1 1458 donbock 2,426
Recognized Expert Top Contributor
Can you use a debugger to find out whereabouts in your program the error occurs? If not, sprinkle printf's throughout your program and look to see the last printf message before the error message.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Laszlo |
last post by:
Hi all,
As a novice I installed PostgreSQL 7.2.1 on Win32 and works,
Borland C++Builder Enterprise Suite 5.0 (build 12.34) what works too.
I decided to combine these two programs and develop a...
|
by: Grant Richard |
last post by:
Using the TcpListener and TcpClient I created a program that just sends and
receives a short string - over and over again. The program is fine until it
gets to around 1500 to 1800 messages. At...
|
by: Agnes |
last post by:
My client hold its MS SQL server in hkbranch, Both china and hong kong
office can run the vb.net application very well via VPN. Now, they want to
reduce cost and move the MS SQL server to china 's...
|
by: dasilva109 |
last post by:
Hi guys
I am new to C++ and need urgent help with this part of my code for a
uni coursework I have to submit by Thursday
//ClientData.h
#ifndef CLIENTDATA_H
#define CLIENTDATA_H
#include...
|
by: Toby |
last post by:
Hi, I've managed to get my hands on the ms 2003 toolkit, and have
successfully (i think) created a .pyd file in win xp (setup.py is
provided intersystems cache):
...
| |
by: kalaisuresh |
last post by:
hai,
in my program i used the DBI module
my program running well in terminal(redhat linux 9.0)
if i use the same program in interface (use CGI)
that time it shows the log error
BEGIN...
|
by: pranas |
last post by:
I'm not a proffessional programmer and I'm asking for your help. I'm using PHP and running Apache server and Mysql database server on my home network computer to serve my web site. My PHP error log...
|
by: fatboySudsy |
last post by:
Hi,
I have constructed a client program that has given me some error codes that i just cannot see. I was wondering if a different set of eyes with much more experience than me could help me out. ...
|
by: alho |
last post by:
The web service is called by a program running on pocket pc. When to
call the web service, the first call is still ok, but for the second
or later calls, it will throw "403 Forbidden" WebException....
|
by: Kapps |
last post by:
Hi,
I'm having a problem with my program not being able to run on certain computers. They have the basics, such as the .Net Frameworks. Upon trying to run the program, it gives the error:
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |