---
title: "Loopback test"
url: "https://maker.wiznet.io/forum/13664"
markdown_url: "https://maker.wiznet.io/forum/13664/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "soorajsuresh80"
created: "2020-01-21T07:43:03+09:00"
last_activity: "2020-01-30T09:12:54+09:00"
language: "en"
views: 841
replies: 5
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# Loopback test

## Question

Asked by soorajsuresh80 on 2020-01-21 in Ethernet Chips.

Hello,
I was running through the loopback tcp example program with the W5500 evaluation board .And i got some doubts .
Can anyone please explain whats happening on this particular portion,
switch(getSn_SR(sn))
{
case SOCK_ESTABLISHED :
if(getSn_IR(sn) & Sn_IR_CON)
{
#ifdef *LOOPBACK_DEBUG*
getSn_DIPR(sn, destip);
destport = getSn_DPORT(sn);

```
    	 printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
```

#endif
setSn_IR(sn,Sn_IR_CON);
}
if((size = getSn_RX_RSR(sn)) > 0)
{
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
ret = recv(sn, buf, size);
if(ret &lt;= 0) return ret;
sentsize = 0;
while(size != sentsize)
{
ret = send(sn,buf+sentsize,size-sentsize);
if(ret &lt; 0)
{
close(sn);
return ret;
}
sentsize += ret; // Don’t care SOCKERR_BUSY, because it is zero.
}
}
break;

## Replies

### Reply 1 by becky, 2020-01-22

![](https://avatars.discourse-cdn.com/v4/letter/s/53a042/48.png) soorajsuresh80:

> if(getSn_IR(sn) & Sn_IR_CON)
> {
> #ifdef *LOOPBACK_DEBUG*
> getSn_DIPR(sn, destip);
> destport = getSn_DPORT(sn);
>
> ```
    	 printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
```
>
> #endif
> setSn_IR(sn,Sn_IR_CON);
> }

When a connect interrupt occurs (connect interrupt occurs immediately after tcp connection via handshaking), check the connected target.

![](https://avatars.discourse-cdn.com/v4/letter/s/53a042/48.png) soorajsuresh80:

> if((size = getSn_RX_RSR(sn)) > 0)
> {
> if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
> ret = recv(sn, buf, size);
> if(ret &lt;= 0) return ret;
> sentsize = 0;
> while(size != sentsize)
> {
> ret = send(sn,buf+sentsize,size-sentsize);
> if(ret &lt; 0)
> {
> close(sn);
> return ret;
> }
> sentsize += ret; // Don’t care SOCKERR_BUSY, because it is zero.
> }
> }

When data is received it is sent again.

### Reply 2 by soorajsuresh80, 2020-01-23 (in reply to reply 1)

becky:

> if((size = getSn_RX_RSR(sn)) > 0)

I believe this line is reading the received data size from the particular register . But i dont see any data receiving command before this.

### Reply 3 by becky, 2020-01-27

![image](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/c/c4f9fcebf67765e35f9b301f29cadcaf7bcd795e.png)

Check the size of received data through getSn_RX_RSR and receive the data through recv () function.

### Reply 4 by soorajsuresh80, 2020-01-29

HELLO Becky!
Thanks for the help.
The loopback test is working fine for me now.
I wonder if you could help me with something ,
I want to change the loopback data for some reason, basically to ensure control over the data transfer,
If so where should i edit in the code?

### Reply 5 by becky, 2020-01-30

![](https://avatars.discourse-cdn.com/v4/letter/s/53a042/48.png) soorajsuresh80:

> ret = recv(sn, buf, size);

![](https://avatars.discourse-cdn.com/v4/letter/s/53a042/48.png) soorajsuresh80:

> ret = send(sn,buf+sentsize,size-sentsize);

The received data is stored to “buf” and send the data stored “buf”.
So you can modify data via “buf”.

---

Source: https://maker.wiznet.io/forum/13664
