MC52233 client using minisockets

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC52233 client using minisockets

2,653 Views
wyliek
Contributor I
Hi there

I have been trying to implement a simple tcp session between my PC and the 52233Demo board. The trouble I am having has been with the m_connect and m_send socket functions. All I want to do is open a socket, send one character via TCP and then close the socket. My code is as follows:

M_SOCK sockfd;
struct sockaddr_in dest_addr; // will hold the destination addr
char stuff='f';
int nb_bl=0;

sockfd = m_socket(); // do some error checking
//m_ioctl(sockfd,SO_NBIO ,&nb_bl);

dest_addr.sin_family = AF_INET;
dest_addr.sin_port = 3490;
dest_addr.sin_addr.s_addr = inet_addr("192.1.3.149" );
memset(&(dest_addr.sin_zero), '\0', 8);

m_connect(sockfd, &dest_addr, something);

nmpcts=m_send(sockfd,&stuff,1);

m_close(sockfd);

When I run the code on the coldfire the following happens:
mc52233 sends out an ARP request
Pc replies witht its mac address
mc5233 sends out TCP syn request
PC replies with RST ACK
and then no more packets are sent and the mc52233 continues runnig other tasks.

It seems that the connect fucntion is working but not the send.
I think this may have something to do with my callback function: something
at the moment it does nothing cause I'm not to sure how to use this. However the socket should be by default set to blocking so the callback function should not be needed...

Can anyone point out what I am doing wrong. Please speak slowly as I am new to sockets and TCP/IP :smileyhappy:

Thanks
Kyle
Labels (1)
0 Kudos
Reply
2 Replies

343 Views
mccPaul
Contributor I
Hi Kyle,
 
It doesn't look as though you are doing much wrong, so it may be more that one of the calls has failed. I know that some of your code must be working for a SYN to have been sent, but I'd do the following:
 
Check that m_sock doesn't return NULL;
 
Explicitly set the socket to blocking mode - m_ioctl(sockfd, SO_BIO, NULL); // data not used by m_ioctl
 
Check the return from m_connect, if it is EINPROGRESS, the socket is non-blocking. Connected OK will return 0.
 
What is nmpcts after the call to m_send? -1 indicates an error and a BSD error code may be found in sockfd->error.
 
If that is all fine, try removing the m_close - maybe the stack dumps the data before it reaches the ethernet interface.
 
Paul.
0 Kudos
Reply

343 Views
wyliek
Contributor I
Hi Paul,

Thanks for the suggestions. It seems that you were correct. The code was working, the problem happened to be on the PC side. I was not listening for a connection from the coldfire. Therefore, when the TCP SYN request was received the PC replied with a reset ACK which prevented the connection.

I have since fixed the problem, only to encounter a new one:

I have been playing around with the ColFire Lite example project (HTTP server) to try and familiarise myself with the Interniche network stack and NicheTask. My goal is to edit the project to contain a task which simply sends a string via UDP. What I have done so far is:

In the create_apptasks() function I have added-

e = TK_NEWTASK(&kel_udp_task);
if (e != 0)
{
dprintf("udp task create error\n" );
panic("create_apptasks" );
return -1; // compiler warnings
}

which should create a new task if I am not mistaken.
I have declared the task object-

TK_OBJECT(to_keludpclient);
TK_ENTRY(tk_keludpclient);
struct inet_taskinfo kel_udp_task={&to_keludpclient,
"UDP Client",
tk_keludpclient,
NET_PRIORITY,
APP_STACK_SIZE
};

My code for the task is as follows-

TK_ENTRY(tk_keludpclient)
{
int e;
char data[]="some text";
e=0;
while (!iniche_net_ready)
TK_SLEEP(1);
e=kel_send_udp(data, 9, 0xC0010395, 3490, 3490);
TK_RETURN_OK();
}

int kel_send_udp(char *data, int datalen, ip_addr destip, u_short lport, u_short fport)
{
PACKET data_pkt;
int e;
void * event;

data_pkt=udp_alloc(datalen,0);
if (!data_pkt)
printf("trouble allocating packet" );
data_pkt->nb_prot =data;
data_pkt->nb_plen =datalen;
data_pkt->fhost =destip;
e=udp_send(fport, lport, data_pkt);
TK_APP_BLOCK(event);
return e;

}

This sends a UDP packet to My PC containing "some text". But my PC replies with and ICMP "destination unreachable". Could the problem be that I'm not listening for the packet again?

Another more important issue is that on observing the serial port output I get:

INET> Illegal instruction -- PC = 0x00010000
Illegal instruction -- PC = 0x00010000
Illegal instruction -- PC = 0x00010000
Illegal instruction -- PC = 0x00010000
Illegal instruction -- PC = 0x00010000
Illegal instruction -- PC = 0x00010000
Illegal instruction -- PC = 0x00010000
Illegal instruction -- PC = 0x00010000
Illegal instruction -- PC = 0x00010000
Illegal instruction -- PC = 0x00010000

which continues endlessly. Can anyone tell me what is causing this error?
0 Kudos
Reply