mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-20 05:21:59 -04:00
Add faster version code.
This commit is contained in:
parent
f7a168e184
commit
31606543da
|
@ -205,7 +205,7 @@ PT_THREAD( psock_send ( register struct psock *s, const char *buf, unsigned int
|
||||||
|
|
||||||
/* Save the length of and a pointer to the data that is to be
|
/* Save the length of and a pointer to the data that is to be
|
||||||
sent. */
|
sent. */
|
||||||
s->sendptr = ( u8_t*)buf;
|
s->sendptr = ( u8_t * ) buf;
|
||||||
s->sendlen = len;
|
s->sendlen = len;
|
||||||
|
|
||||||
s->state = STATE_NONE;
|
s->state = STATE_NONE;
|
||||||
|
@ -305,7 +305,7 @@ PT_THREAD( psock_readto ( register struct psock *psock, unsigned char c ) )
|
||||||
{
|
{
|
||||||
PT_BEGIN( &psock->psockpt );
|
PT_BEGIN( &psock->psockpt );
|
||||||
|
|
||||||
buf_setup( &psock->buf, (u8_t*) psock->bufptr, psock->bufsize );
|
buf_setup( &psock->buf, ( u8_t * ) psock->bufptr, psock->bufsize );
|
||||||
|
|
||||||
/* XXX: Should add buf_checkmarker() before do{} loop, if
|
/* XXX: Should add buf_checkmarker() before do{} loop, if
|
||||||
incoming data has been handled while waiting for a write. */
|
incoming data has been handled while waiting for a write. */
|
||||||
|
@ -334,7 +334,7 @@ PT_THREAD( psock_readbuf ( register struct psock *psock ) )
|
||||||
{
|
{
|
||||||
PT_BEGIN( &psock->psockpt );
|
PT_BEGIN( &psock->psockpt );
|
||||||
|
|
||||||
buf_setup( &psock->buf, (u8_t*) psock->bufptr, psock->bufsize );
|
buf_setup( &psock->buf, ( u8_t * ) psock->bufptr, psock->bufsize );
|
||||||
|
|
||||||
/* XXX: Should add buf_checkmarker() before do{} loop, if
|
/* XXX: Should add buf_checkmarker() before do{} loop, if
|
||||||
incoming data has been handled while waiting for a write. */
|
incoming data has been handled while waiting for a write. */
|
||||||
|
@ -366,7 +366,7 @@ void psock_init( register struct psock *psock, char *buffer, unsigned int buffer
|
||||||
psock->readlen = 0;
|
psock->readlen = 0;
|
||||||
psock->bufptr = buffer;
|
psock->bufptr = buffer;
|
||||||
psock->bufsize = buffersize;
|
psock->bufsize = buffersize;
|
||||||
buf_setup( &psock->buf, (u8_t*) buffer, buffersize );
|
buf_setup( &psock->buf, ( u8_t * ) buffer, buffersize );
|
||||||
PT_INIT( &psock->pt );
|
PT_INIT( &psock->pt );
|
||||||
PT_INIT( &psock->psockpt );
|
PT_INIT( &psock->psockpt );
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,11 +44,11 @@
|
||||||
*
|
*
|
||||||
* $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $
|
* $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "uip_timer.h"
|
#include "uip_timer.h"
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a timer.
|
* Set a timer.
|
||||||
*
|
*
|
||||||
|
@ -60,13 +60,14 @@
|
||||||
* \param interval The interval before the timer expires.
|
* \param interval The interval before the timer expires.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void
|
void timer_set( struct timer *t, clock_time_t interval )
|
||||||
timer_set(struct timer *t, clock_time_t interval)
|
|
||||||
{
|
{
|
||||||
t->interval = interval;
|
t->interval = interval;
|
||||||
t->start = clock_time();
|
t->start = clock_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the timer with the same interval.
|
* Reset the timer with the same interval.
|
||||||
*
|
*
|
||||||
|
@ -80,12 +81,13 @@ timer_set(struct timer *t, clock_time_t interval)
|
||||||
*
|
*
|
||||||
* \sa timer_restart()
|
* \sa timer_restart()
|
||||||
*/
|
*/
|
||||||
void
|
void timer_reset( struct timer *t )
|
||||||
timer_reset(struct timer *t)
|
|
||||||
{
|
{
|
||||||
t->start += t->interval;
|
t->start += t->interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restart the timer from the current point in time
|
* Restart the timer from the current point in time
|
||||||
*
|
*
|
||||||
|
@ -100,12 +102,13 @@ timer_reset(struct timer *t)
|
||||||
*
|
*
|
||||||
* \sa timer_reset()
|
* \sa timer_reset()
|
||||||
*/
|
*/
|
||||||
void
|
void timer_restart( struct timer *t )
|
||||||
timer_restart(struct timer *t)
|
|
||||||
{
|
{
|
||||||
t->start = clock_time();
|
t->start = clock_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a timer has expired.
|
* Check if a timer has expired.
|
||||||
*
|
*
|
||||||
|
@ -117,11 +120,11 @@ timer_restart(struct timer *t)
|
||||||
* \return Non-zero if the timer has expired, zero otherwise.
|
* \return Non-zero if the timer has expired, zero otherwise.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int
|
int timer_expired( struct timer *t )
|
||||||
timer_expired(struct timer *t)
|
|
||||||
{
|
{
|
||||||
return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;
|
return( clock_time_t ) ( clock_time() - t->start ) >= ( clock_time_t ) t->interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
*
|
*
|
||||||
* $Id: uip-split.c,v 1.2 2006/06/12 08:00:30 adam Exp $
|
* $Id: uip-split.c,v 1.2 2006/06/12 08:00:30 adam Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "uip-split.h"
|
#include "uip-split.h"
|
||||||
|
@ -40,97 +39,106 @@
|
||||||
#include "uip-fw.h"
|
#include "uip-fw.h"
|
||||||
#include "uip_arch.h"
|
#include "uip_arch.h"
|
||||||
|
|
||||||
|
#define BUF ( ( struct uip_tcpip_hdr * ) &uip_buf[UIP_LLH_LEN] )
|
||||||
|
|
||||||
#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void
|
void uip_split_output( void )
|
||||||
uip_split_output(void)
|
|
||||||
{
|
{
|
||||||
u16_t tcplen, len1, len2;
|
u16_t tcplen, len1, len2;
|
||||||
|
|
||||||
/* We only try to split maximum sized TCP segments. */
|
/* We only try to split maximum sized TCP segments. */
|
||||||
if(BUF->proto == UIP_PROTO_TCP &&
|
if( BUF->proto == UIP_PROTO_TCP && uip_len == UIP_BUFSIZE - UIP_LLH_LEN )
|
||||||
uip_len == UIP_BUFSIZE - UIP_LLH_LEN) {
|
{
|
||||||
|
tcplen = uip_len - UIP_TCPIP_HLEN;
|
||||||
|
|
||||||
tcplen = uip_len - UIP_TCPIP_HLEN;
|
/* Split the segment in two. If the original packet length was
|
||||||
/* Split the segment in two. If the original packet length was
|
|
||||||
odd, we make the second packet one byte larger. */
|
odd, we make the second packet one byte larger. */
|
||||||
len1 = len2 = tcplen / 2;
|
len1 = len2 = tcplen / 2;
|
||||||
if(len1 + len2 < tcplen) {
|
if( len1 + len2 < tcplen )
|
||||||
++len2;
|
{
|
||||||
}
|
++len2;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the first packet. This is done by altering the length
|
/* Create the first packet. This is done by altering the length
|
||||||
field of the IP header and updating the checksums. */
|
field of the IP header and updating the checksums. */
|
||||||
uip_len = len1 + UIP_TCPIP_HLEN;
|
uip_len = len1 + UIP_TCPIP_HLEN;
|
||||||
#if UIP_CONF_IPV6
|
#if UIP_CONF_IPV6
|
||||||
/* For IPv6, the IP length field does not include the IPv6 IP header
|
|
||||||
|
/* For IPv6, the IP length field does not include the IPv6 IP header
|
||||||
length. */
|
length. */
|
||||||
BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
|
BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );
|
||||||
BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
|
BUF->len[1] = ( (uip_len - UIP_IPH_LEN) & 0xff );
|
||||||
#else /* UIP_CONF_IPV6 */
|
#else /* UIP_CONF_IPV6 */
|
||||||
BUF->len[0] = uip_len >> 8;
|
BUF->len[0] = uip_len >> 8;
|
||||||
BUF->len[1] = uip_len & 0xff;
|
BUF->len[1] = uip_len & 0xff;
|
||||||
#endif /* UIP_CONF_IPV6 */
|
#endif /* UIP_CONF_IPV6 */
|
||||||
|
|
||||||
/* Recalculate the TCP checksum. */
|
/* Recalculate the TCP checksum. */
|
||||||
BUF->tcpchksum = 0;
|
BUF->tcpchksum = 0;
|
||||||
BUF->tcpchksum = ~(uip_tcpchksum());
|
BUF->tcpchksum = ~( uip_tcpchksum() );
|
||||||
|
|
||||||
#if !UIP_CONF_IPV6
|
#if !UIP_CONF_IPV6
|
||||||
/* Recalculate the IP checksum. */
|
|
||||||
BUF->ipchksum = 0;
|
|
||||||
BUF->ipchksum = ~(uip_ipchksum());
|
|
||||||
#endif /* UIP_CONF_IPV6 */
|
|
||||||
|
|
||||||
/* Transmit the first packet. */
|
/* Recalculate the IP checksum. */
|
||||||
/* uip_fw_output();*/
|
BUF->ipchksum = 0;
|
||||||
// tcpip_output();
|
BUF->ipchksum = ~( uip_ipchksum() );
|
||||||
|
#endif /* UIP_CONF_IPV6 */
|
||||||
|
|
||||||
/* Now, create the second packet. To do this, it is not enough to
|
/* Transmit the first packet. */
|
||||||
|
|
||||||
|
/* uip_fw_output();*/
|
||||||
|
|
||||||
|
// tcpip_output();
|
||||||
|
|
||||||
|
/* Now, create the second packet. To do this, it is not enough to
|
||||||
just alter the length field, but we must also update the TCP
|
just alter the length field, but we must also update the TCP
|
||||||
sequence number and point the uip_appdata to a new place in
|
sequence number and point the uip_appdata to a new place in
|
||||||
memory. This place is detemined by the length of the first
|
memory. This place is detemined by the length of the first
|
||||||
packet (len1). */
|
packet (len1). */
|
||||||
uip_len = len2 + UIP_TCPIP_HLEN;
|
uip_len = len2 + UIP_TCPIP_HLEN;
|
||||||
#if UIP_CONF_IPV6
|
#if UIP_CONF_IPV6
|
||||||
/* For IPv6, the IP length field does not include the IPv6 IP header
|
|
||||||
|
/* For IPv6, the IP length field does not include the IPv6 IP header
|
||||||
length. */
|
length. */
|
||||||
BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
|
BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );
|
||||||
BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
|
BUF->len[1] = ( (uip_len - UIP_IPH_LEN) & 0xff );
|
||||||
#else /* UIP_CONF_IPV6 */
|
#else /* UIP_CONF_IPV6 */
|
||||||
BUF->len[0] = uip_len >> 8;
|
BUF->len[0] = uip_len >> 8;
|
||||||
BUF->len[1] = uip_len & 0xff;
|
BUF->len[1] = uip_len & 0xff;
|
||||||
#endif /* UIP_CONF_IPV6 */
|
#endif /* UIP_CONF_IPV6 */
|
||||||
|
|
||||||
/* uip_appdata += len1;*/
|
/* uip_appdata += len1;*/
|
||||||
memcpy(uip_appdata, (u8_t *)uip_appdata + len1, len2);
|
memcpy( uip_appdata, ( u8_t * ) uip_appdata + len1, len2 );
|
||||||
|
|
||||||
uip_add32(BUF->seqno, len1);
|
uip_add32( BUF->seqno, len1 );
|
||||||
BUF->seqno[0] = uip_acc32[0];
|
BUF->seqno[0] = uip_acc32[0];
|
||||||
BUF->seqno[1] = uip_acc32[1];
|
BUF->seqno[1] = uip_acc32[1];
|
||||||
BUF->seqno[2] = uip_acc32[2];
|
BUF->seqno[2] = uip_acc32[2];
|
||||||
BUF->seqno[3] = uip_acc32[3];
|
BUF->seqno[3] = uip_acc32[3];
|
||||||
|
|
||||||
/* Recalculate the TCP checksum. */
|
/* Recalculate the TCP checksum. */
|
||||||
BUF->tcpchksum = 0;
|
BUF->tcpchksum = 0;
|
||||||
BUF->tcpchksum = ~(uip_tcpchksum());
|
BUF->tcpchksum = ~( uip_tcpchksum() );
|
||||||
|
|
||||||
#if !UIP_CONF_IPV6
|
#if !UIP_CONF_IPV6
|
||||||
/* Recalculate the IP checksum. */
|
|
||||||
BUF->ipchksum = 0;
|
|
||||||
BUF->ipchksum = ~(uip_ipchksum());
|
|
||||||
#endif /* UIP_CONF_IPV6 */
|
|
||||||
|
|
||||||
/* Transmit the second packet. */
|
/* Recalculate the IP checksum. */
|
||||||
/* uip_fw_output();*/
|
BUF->ipchksum = 0;
|
||||||
// tcpip_output();
|
BUF->ipchksum = ~( uip_ipchksum() );
|
||||||
} else {
|
#endif /* UIP_CONF_IPV6 */
|
||||||
/* uip_fw_output();*/
|
|
||||||
// tcpip_output();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Transmit the second packet. */
|
||||||
|
|
||||||
|
/* uip_fw_output();*/
|
||||||
|
|
||||||
|
// tcpip_output();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* uip_fw_output();*/
|
||||||
|
|
||||||
|
// tcpip_output();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1631,6 +1631,10 @@ u16_t uip_tcpchksum(void);
|
||||||
*/
|
*/
|
||||||
u16_t uip_udpchksum(void);
|
u16_t uip_udpchksum(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Work out the fasted way of sending the data to the low level driver.
|
||||||
|
*/
|
||||||
|
int uip_fast_send( int xARP );
|
||||||
|
|
||||||
#endif /* __UIP_H__ */
|
#endif /* __UIP_H__ */
|
||||||
|
|
||||||
|
|
|
@ -57,94 +57,89 @@
|
||||||
* $Id: uip_arp.c,v 1.8 2006/06/02 23:36:21 adam Exp $
|
* $Id: uip_arp.c,v 1.8 2006/06/02 23:36:21 adam Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "uip_arp.h"
|
#include "uip_arp.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef __ICCARM__
|
#ifdef __ICCARM__
|
||||||
#pragma pack(1)
|
#pragma pack( 1 )
|
||||||
#endif
|
#endif
|
||||||
|
struct arp_hdr
|
||||||
struct arp_hdr {
|
{
|
||||||
struct uip_eth_hdr ethhdr;
|
struct uip_eth_hdr ethhdr;
|
||||||
u16_t hwtype;
|
u16_t hwtype;
|
||||||
u16_t protocol;
|
u16_t protocol;
|
||||||
u8_t hwlen;
|
u8_t hwlen;
|
||||||
u8_t protolen;
|
u8_t protolen;
|
||||||
u16_t opcode;
|
u16_t opcode;
|
||||||
struct uip_eth_addr shwaddr;
|
struct uip_eth_addr shwaddr;
|
||||||
u16_t sipaddr[2];
|
u16_t sipaddr[2];
|
||||||
struct uip_eth_addr dhwaddr;
|
struct uip_eth_addr dhwaddr;
|
||||||
u16_t dipaddr[2];
|
u16_t dipaddr[2];
|
||||||
} PACK_STRUCT_END;
|
} PACK_STRUCT_END;
|
||||||
|
|
||||||
#ifdef __ICCARM__
|
#ifdef __ICCARM__
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __ICCARM__
|
#ifdef __ICCARM__
|
||||||
#pragma pack(1)
|
#pragma pack( 1 )
|
||||||
#endif
|
#endif
|
||||||
|
struct ethip_hdr
|
||||||
|
{
|
||||||
|
struct uip_eth_hdr ethhdr;
|
||||||
|
|
||||||
struct ethip_hdr {
|
/* IP header. */
|
||||||
struct uip_eth_hdr ethhdr;
|
u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
|
||||||
/* IP header. */
|
u16_t ipchksum;
|
||||||
u8_t vhl,
|
u16_t srcipaddr[2], destipaddr[2];
|
||||||
tos,
|
|
||||||
len[2],
|
|
||||||
ipid[2],
|
|
||||||
ipoffset[2],
|
|
||||||
ttl,
|
|
||||||
proto;
|
|
||||||
u16_t ipchksum;
|
|
||||||
u16_t srcipaddr[2],
|
|
||||||
destipaddr[2];
|
|
||||||
} PACK_STRUCT_END;
|
} PACK_STRUCT_END;
|
||||||
|
|
||||||
#ifdef __ICCARM__
|
#ifdef __ICCARM__
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
#endif
|
#endif
|
||||||
|
#define ARP_REQUEST 1
|
||||||
|
#define ARP_REPLY 2
|
||||||
|
|
||||||
#define ARP_REQUEST 1
|
#define ARP_HWTYPE_ETH 1
|
||||||
#define ARP_REPLY 2
|
|
||||||
|
|
||||||
#define ARP_HWTYPE_ETH 1
|
struct arp_entry
|
||||||
|
{
|
||||||
struct arp_entry {
|
u16_t ipaddr[2];
|
||||||
u16_t ipaddr[2];
|
struct uip_eth_addr ethaddr;
|
||||||
struct uip_eth_addr ethaddr;
|
u8_t time;
|
||||||
u8_t time;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct uip_eth_addr broadcast_ethaddr =
|
static const struct uip_eth_addr broadcast_ethaddr = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
|
||||||
{{0xff,0xff,0xff,0xff,0xff,0xff}};
|
static const u16_t broadcast_ipaddr[2] = { 0xffff, 0xffff };
|
||||||
static const u16_t broadcast_ipaddr[2] = {0xffff,0xffff};
|
|
||||||
|
|
||||||
static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
|
static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
|
||||||
static u16_t ipaddr[2];
|
static u16_t ipaddr[2];
|
||||||
static u8_t i, c;
|
static u8_t i, c;
|
||||||
|
|
||||||
static u8_t arptime;
|
static u8_t arptime;
|
||||||
static u8_t tmpage;
|
static u8_t tmpage;
|
||||||
|
|
||||||
|
#define BUF ( ( struct arp_hdr * ) &uip_buf[0] )
|
||||||
|
#define IPBUF ( ( struct ethip_hdr * ) &uip_buf[0] )
|
||||||
|
|
||||||
#define BUF ((struct arp_hdr *)&uip_buf[0])
|
|
||||||
#define IPBUF ((struct ethip_hdr *)&uip_buf[0])
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the ARP module.
|
* Initialize the ARP module.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
void
|
void uip_arp_init( void )
|
||||||
uip_arp_init(void)
|
|
||||||
{
|
{
|
||||||
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
|
||||||
memset(arp_table[i].ipaddr, 0, 4);
|
{
|
||||||
}
|
memset( arp_table[i].ipaddr, 0, 4 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Periodic ARP processing function.
|
* Periodic ARP processing function.
|
||||||
*
|
*
|
||||||
|
@ -153,86 +148,93 @@ uip_arp_init(void)
|
||||||
* is 10 seconds between the calls.
|
* is 10 seconds between the calls.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
void
|
void uip_arp_timer( void )
|
||||||
uip_arp_timer(void)
|
|
||||||
{
|
{
|
||||||
struct arp_entry *tabptr;
|
struct arp_entry *tabptr;
|
||||||
|
|
||||||
++arptime;
|
|
||||||
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
|
||||||
tabptr = &arp_table[i];
|
|
||||||
if((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 &&
|
|
||||||
arptime - tabptr->time >= UIP_ARP_MAXAGE) {
|
|
||||||
memset(tabptr->ipaddr, 0, 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
++arptime;
|
||||||
|
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
|
||||||
|
{
|
||||||
|
tabptr = &arp_table[i];
|
||||||
|
if( (tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 && arptime - tabptr->time >= UIP_ARP_MAXAGE )
|
||||||
|
{
|
||||||
|
memset( tabptr->ipaddr, 0, 4 );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
static void
|
static void uip_arp_update( u16_t *ipaddr, struct uip_eth_addr *ethaddr )
|
||||||
uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
|
|
||||||
{
|
{
|
||||||
register struct arp_entry *tabptr;
|
register struct arp_entry *tabptr;
|
||||||
/* Walk through the ARP mapping table and try to find an entry to
|
|
||||||
|
/* Walk through the ARP mapping table and try to find an entry to
|
||||||
update. If none is found, the IP -> MAC address mapping is
|
update. If none is found, the IP -> MAC address mapping is
|
||||||
inserted in the ARP table. */
|
inserted in the ARP table. */
|
||||||
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
|
||||||
|
{
|
||||||
|
tabptr = &arp_table[i];
|
||||||
|
|
||||||
tabptr = &arp_table[i];
|
/* Only check those entries that are actually in use. */
|
||||||
/* Only check those entries that are actually in use. */
|
if( tabptr->ipaddr[0] != 0 && tabptr->ipaddr[1] != 0 )
|
||||||
if(tabptr->ipaddr[0] != 0 &&
|
{
|
||||||
tabptr->ipaddr[1] != 0) {
|
/* Check if the source IP address of the incoming packet matches
|
||||||
|
|
||||||
/* Check if the source IP address of the incoming packet matches
|
|
||||||
the IP address in this ARP table entry. */
|
the IP address in this ARP table entry. */
|
||||||
if(ipaddr[0] == tabptr->ipaddr[0] &&
|
if( ipaddr[0] == tabptr->ipaddr[0] && ipaddr[1] == tabptr->ipaddr[1] )
|
||||||
ipaddr[1] == tabptr->ipaddr[1]) {
|
{
|
||||||
|
/* An old entry found, update this and return. */
|
||||||
|
memcpy( tabptr->ethaddr.addr, ethaddr->addr, 6 );
|
||||||
|
tabptr->time = arptime;
|
||||||
|
|
||||||
/* An old entry found, update this and return. */
|
return;
|
||||||
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
|
}
|
||||||
tabptr->time = arptime;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
/* If we get here, no existing ARP table entry was found, so we
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we get here, no existing ARP table entry was found, so we
|
|
||||||
create one. */
|
create one. */
|
||||||
|
|
||||||
/* First, we try to find an unused entry in the ARP table. */
|
/* First, we try to find an unused entry in the ARP table. */
|
||||||
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
|
||||||
tabptr = &arp_table[i];
|
{
|
||||||
if(tabptr->ipaddr[0] == 0 &&
|
tabptr = &arp_table[i];
|
||||||
tabptr->ipaddr[1] == 0) {
|
if( tabptr->ipaddr[0] == 0 && tabptr->ipaddr[1] == 0 )
|
||||||
break;
|
{
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* If no unused entry is found, we try to find the oldest entry and
|
/* If no unused entry is found, we try to find the oldest entry and
|
||||||
throw it away. */
|
throw it away. */
|
||||||
if(i == UIP_ARPTAB_SIZE) {
|
if( i == UIP_ARPTAB_SIZE )
|
||||||
tmpage = 0;
|
{
|
||||||
c = 0;
|
tmpage = 0;
|
||||||
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
c = 0;
|
||||||
tabptr = &arp_table[i];
|
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
|
||||||
if(arptime - tabptr->time > tmpage) {
|
{
|
||||||
tmpage = arptime - tabptr->time;
|
tabptr = &arp_table[i];
|
||||||
c = i;
|
if( arptime - tabptr->time > tmpage )
|
||||||
}
|
{
|
||||||
}
|
tmpage = arptime - tabptr->time;
|
||||||
i = c;
|
c = i;
|
||||||
tabptr = &arp_table[i];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now, i is the ARP table entry which we will fill with the new
|
i = c;
|
||||||
|
tabptr = &arp_table[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now, i is the ARP table entry which we will fill with the new
|
||||||
information. */
|
information. */
|
||||||
memcpy(tabptr->ipaddr, ipaddr, 4);
|
memcpy( tabptr->ipaddr, ipaddr, 4 );
|
||||||
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
|
memcpy( tabptr->ethaddr.addr, ethaddr->addr, 6 );
|
||||||
tabptr->time = arptime;
|
tabptr->time = arptime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ARP processing for incoming IP packets
|
* ARP processing for incoming IP packets
|
||||||
*
|
*
|
||||||
|
@ -245,29 +247,34 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
|
||||||
* in the uip_buf[] buffer, and the length of the packet in the global
|
* in the uip_buf[] buffer, and the length of the packet in the global
|
||||||
* variable uip_len.
|
* variable uip_len.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
#if 1
|
#if 1
|
||||||
void
|
void uip_arp_ipin( void )
|
||||||
uip_arp_ipin(void)
|
|
||||||
{
|
{
|
||||||
uip_len -= sizeof(struct uip_eth_hdr);
|
uip_len -= sizeof( struct uip_eth_hdr );
|
||||||
|
|
||||||
/* Only insert/update an entry if the source IP address of the
|
/* Only insert/update an entry if the source IP address of the
|
||||||
incoming IP packet comes from a host on the local network. */
|
incoming IP packet comes from a host on the local network. */
|
||||||
if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
|
if( (IPBUF->srcipaddr[0] & uip_netmask[0]) != (uip_hostaddr[0] & uip_netmask[0]) )
|
||||||
(uip_hostaddr[0] & uip_netmask[0])) {
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if((IPBUF->srcipaddr[1] & uip_netmask[1]) !=
|
|
||||||
(uip_hostaddr[1] & uip_netmask[1])) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
|
|
||||||
|
|
||||||
return;
|
if( (IPBUF->srcipaddr[1] & uip_netmask[1]) != (uip_hostaddr[1] & uip_netmask[1]) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uip_arp_update( IPBUF->srcipaddr, &(IPBUF->ethhdr.src) );
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* 0 */
|
#endif /* 0 */
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ARP processing for incoming ARP packets.
|
* ARP processing for incoming ARP packets.
|
||||||
*
|
*
|
||||||
|
@ -289,56 +296,65 @@ uip_arp_ipin(void)
|
||||||
* header in the uip_buf[] buffer, and the length of the packet in the
|
* header in the uip_buf[] buffer, and the length of the packet in the
|
||||||
* global variable uip_len.
|
* global variable uip_len.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
void
|
void uip_arp_arpin( void )
|
||||||
uip_arp_arpin(void)
|
|
||||||
{
|
{
|
||||||
|
if( uip_len < sizeof(struct arp_hdr) )
|
||||||
|
{
|
||||||
|
uip_len = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(uip_len < sizeof(struct arp_hdr)) {
|
uip_len = 0;
|
||||||
uip_len = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uip_len = 0;
|
|
||||||
|
|
||||||
switch(BUF->opcode) {
|
switch( BUF->opcode )
|
||||||
case HTONS(ARP_REQUEST):
|
{
|
||||||
/* ARP request. If it asked for our address, we send out a
|
case HTONS( ARP_REQUEST ):
|
||||||
|
/* ARP request. If it asked for our address, we send out a
|
||||||
reply. */
|
reply. */
|
||||||
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
|
if( uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr) )
|
||||||
/* First, we register the one who made the request in our ARP
|
{
|
||||||
|
/* First, we register the one who made the request in our ARP
|
||||||
table, since it is likely that we will do more communication
|
table, since it is likely that we will do more communication
|
||||||
with this host in the future. */
|
with this host in the future. */
|
||||||
uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
|
uip_arp_update( BUF->sipaddr, &BUF->shwaddr );
|
||||||
|
|
||||||
/* The reply opcode is 2. */
|
/* The reply opcode is 2. */
|
||||||
BUF->opcode = HTONS(2);
|
BUF->opcode = HTONS( 2 );
|
||||||
|
|
||||||
memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
|
memcpy( BUF->dhwaddr.addr, BUF->shwaddr.addr, 6 );
|
||||||
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
|
memcpy( BUF->shwaddr.addr, uip_ethaddr.addr, 6 );
|
||||||
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
|
memcpy( BUF->ethhdr.src.addr, uip_ethaddr.addr, 6 );
|
||||||
memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
|
memcpy( BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6 );
|
||||||
|
|
||||||
BUF->dipaddr[0] = BUF->sipaddr[0];
|
BUF->dipaddr[0] = BUF->sipaddr[0];
|
||||||
BUF->dipaddr[1] = BUF->sipaddr[1];
|
BUF->dipaddr[1] = BUF->sipaddr[1];
|
||||||
BUF->sipaddr[0] = uip_hostaddr[0];
|
BUF->sipaddr[0] = uip_hostaddr[0];
|
||||||
BUF->sipaddr[1] = uip_hostaddr[1];
|
BUF->sipaddr[1] = uip_hostaddr[1];
|
||||||
|
|
||||||
BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
|
BUF->ethhdr.type = HTONS( UIP_ETHTYPE_ARP );
|
||||||
uip_len = sizeof(struct arp_hdr);
|
uip_len = sizeof( struct arp_hdr );
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case HTONS(ARP_REPLY):
|
break;
|
||||||
/* ARP reply. We insert or update the ARP table if it was meant
|
|
||||||
|
case HTONS( ARP_REPLY ):
|
||||||
|
/* ARP reply. We insert or update the ARP table if it was meant
|
||||||
for us. */
|
for us. */
|
||||||
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
|
if( uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr) )
|
||||||
uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
|
{
|
||||||
}
|
uip_arp_update( BUF->sipaddr, &BUF->shwaddr );
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepend Ethernet header to an outbound IP packet and see if we need
|
* Prepend Ethernet header to an outbound IP packet and see if we need
|
||||||
* to send out an ARP request.
|
* to send out an ARP request.
|
||||||
|
@ -365,75 +381,86 @@ uip_arp_arpin(void)
|
||||||
* buffer, and the length of the packet is in the global variable
|
* buffer, and the length of the packet is in the global variable
|
||||||
* uip_len.
|
* uip_len.
|
||||||
*/
|
*/
|
||||||
/*-----------------------------------------------------------------------------------*/
|
|
||||||
void
|
|
||||||
uip_arp_out(void)
|
|
||||||
{
|
|
||||||
struct arp_entry *tabptr;
|
|
||||||
|
|
||||||
/* Find the destination IP address in the ARP table and construct
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
void uip_arp_out( void )
|
||||||
|
{
|
||||||
|
struct arp_entry *tabptr;
|
||||||
|
|
||||||
|
/* Find the destination IP address in the ARP table and construct
|
||||||
the Ethernet header. If the destination IP addres isn't on the
|
the Ethernet header. If the destination IP addres isn't on the
|
||||||
local network, we use the default router's IP address instead.
|
local network, we use the default router's IP address instead.
|
||||||
|
|
||||||
If not ARP table entry is found, we overwrite the original IP
|
If not ARP table entry is found, we overwrite the original IP
|
||||||
packet with an ARP request for the IP address. */
|
packet with an ARP request for the IP address. */
|
||||||
|
|
||||||
/* First check if destination is a local broadcast. */
|
/* First check if destination is a local broadcast. */
|
||||||
if(uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) {
|
if( uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr) )
|
||||||
memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
|
{
|
||||||
} else {
|
memcpy( IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6 );
|
||||||
/* Check if the destination address is on the local network. */
|
}
|
||||||
if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) {
|
else
|
||||||
/* Destination address was not on the local network, so we need to
|
{
|
||||||
|
/* Check if the destination address is on the local network. */
|
||||||
|
if( !uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask) )
|
||||||
|
{
|
||||||
|
/* Destination address was not on the local network, so we need to
|
||||||
use the default router's IP address instead of the destination
|
use the default router's IP address instead of the destination
|
||||||
address when determining the MAC address. */
|
address when determining the MAC address. */
|
||||||
uip_ipaddr_copy(ipaddr, uip_draddr);
|
uip_ipaddr_copy( ipaddr, uip_draddr );
|
||||||
} else {
|
}
|
||||||
/* Else, we use the destination IP address. */
|
else
|
||||||
uip_ipaddr_copy(ipaddr, IPBUF->destipaddr);
|
{
|
||||||
}
|
/* Else, we use the destination IP address. */
|
||||||
|
uip_ipaddr_copy( ipaddr, IPBUF->destipaddr );
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
|
||||||
tabptr = &arp_table[i];
|
{
|
||||||
if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
|
tabptr = &arp_table[i];
|
||||||
break;
|
if( uip_ipaddr_cmp(ipaddr, tabptr->ipaddr) )
|
||||||
}
|
{
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(i == UIP_ARPTAB_SIZE) {
|
if( i == UIP_ARPTAB_SIZE )
|
||||||
/* The destination address was not in our ARP table, so we
|
{
|
||||||
|
/* The destination address was not in our ARP table, so we
|
||||||
overwrite the IP packet with an ARP request. */
|
overwrite the IP packet with an ARP request. */
|
||||||
|
memset( BUF->ethhdr.dest.addr, 0xff, 6 );
|
||||||
|
memset( BUF->dhwaddr.addr, 0x00, 6 );
|
||||||
|
memcpy( BUF->ethhdr.src.addr, uip_ethaddr.addr, 6 );
|
||||||
|
memcpy( BUF->shwaddr.addr, uip_ethaddr.addr, 6 );
|
||||||
|
|
||||||
memset(BUF->ethhdr.dest.addr, 0xff, 6);
|
uip_ipaddr_copy( BUF->dipaddr, ipaddr );
|
||||||
memset(BUF->dhwaddr.addr, 0x00, 6);
|
uip_ipaddr_copy( BUF->sipaddr, uip_hostaddr );
|
||||||
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
|
BUF->opcode = HTONS( ARP_REQUEST ); /* ARP request. */
|
||||||
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
|
BUF->hwtype = HTONS( ARP_HWTYPE_ETH );
|
||||||
|
BUF->protocol = HTONS( UIP_ETHTYPE_IP );
|
||||||
|
BUF->hwlen = 6;
|
||||||
|
BUF->protolen = 4;
|
||||||
|
BUF->ethhdr.type = HTONS( UIP_ETHTYPE_ARP );
|
||||||
|
|
||||||
uip_ipaddr_copy(BUF->dipaddr, ipaddr);
|
uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
|
||||||
uip_ipaddr_copy(BUF->sipaddr, uip_hostaddr);
|
|
||||||
BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */
|
|
||||||
BUF->hwtype = HTONS(ARP_HWTYPE_ETH);
|
|
||||||
BUF->protocol = HTONS(UIP_ETHTYPE_IP);
|
|
||||||
BUF->hwlen = 6;
|
|
||||||
BUF->protolen = 4;
|
|
||||||
BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
|
|
||||||
|
|
||||||
uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
|
uip_len = sizeof( struct arp_hdr );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uip_len = sizeof(struct arp_hdr);
|
/* Build an ethernet header. */
|
||||||
return;
|
memcpy( IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build an ethernet header. */
|
memcpy( IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6 );
|
||||||
memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
|
|
||||||
}
|
|
||||||
memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
|
|
||||||
|
|
||||||
IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);
|
IPBUF->ethhdr.type = HTONS( UIP_ETHTYPE_IP );
|
||||||
|
|
||||||
uip_len += sizeof(struct uip_eth_hdr);
|
uip_len += sizeof( struct uip_eth_hdr );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -32,43 +32,50 @@
|
||||||
* $Id: uiplib.c,v 1.2 2006/06/12 08:00:31 adam Exp $
|
* $Id: uiplib.c,v 1.2 2006/06/12 08:00:31 adam Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "uip.h"
|
#include "uip.h"
|
||||||
#include "uiplib.h"
|
#include "uiplib.h"
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
unsigned char
|
unsigned char uiplib_ipaddrconv( char *addrstr, unsigned char *ipaddr )
|
||||||
uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
|
|
||||||
{
|
{
|
||||||
unsigned char tmp;
|
unsigned char tmp;
|
||||||
char c;
|
char c;
|
||||||
unsigned char i, j;
|
unsigned char i, j;
|
||||||
|
|
||||||
tmp = 0;
|
|
||||||
|
|
||||||
for(i = 0; i < 4; ++i) {
|
|
||||||
j = 0;
|
|
||||||
do {
|
|
||||||
c = *addrstr;
|
|
||||||
++j;
|
|
||||||
if(j > 4) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(c == '.' || c == 0) {
|
|
||||||
*ipaddr = tmp;
|
|
||||||
++ipaddr;
|
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
} else if(c >= '0' && c <= '9') {
|
|
||||||
tmp = (tmp * 10) + (c - '0');
|
for( i = 0; i < 4; ++i )
|
||||||
} else {
|
{
|
||||||
return 0;
|
j = 0;
|
||||||
}
|
do
|
||||||
++addrstr;
|
{
|
||||||
} while(c != '.' && c != 0);
|
c = *addrstr;
|
||||||
}
|
++j;
|
||||||
return 1;
|
if( j > 4 )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( c == '.' || c == 0 )
|
||||||
|
{
|
||||||
|
*ipaddr = tmp;
|
||||||
|
++ipaddr;
|
||||||
|
tmp = 0;
|
||||||
|
}
|
||||||
|
else if( c >= '0' && c <= '9' )
|
||||||
|
{
|
||||||
|
tmp = ( tmp * 10 ) + ( c - '0' );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
++addrstr;
|
||||||
|
} while( c != '.' && c != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue