Add faster version code.

This commit is contained in:
Richard Barry 2008-11-16 15:13:40 +00:00
parent f7a168e184
commit 31606543da
7 changed files with 2060 additions and 1685 deletions

View file

@ -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;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @} */ /** @} */

View file

@ -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,25 +39,23 @@
#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;
} }
@ -66,6 +63,7 @@ uip_split_output(void)
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 );
@ -80,13 +78,16 @@ uip_split_output(void)
BUF->tcpchksum = ~( uip_tcpchksum() ); BUF->tcpchksum = ~( uip_tcpchksum() );
#if !UIP_CONF_IPV6 #if !UIP_CONF_IPV6
/* Recalculate the IP checksum. */ /* Recalculate the IP checksum. */
BUF->ipchksum = 0; BUF->ipchksum = 0;
BUF->ipchksum = ~( uip_ipchksum() ); BUF->ipchksum = ~( uip_ipchksum() );
#endif /* UIP_CONF_IPV6 */ #endif /* UIP_CONF_IPV6 */
/* Transmit the first packet. */ /* Transmit the first packet. */
/* uip_fw_output();*/ /* uip_fw_output();*/
// tcpip_output(); // tcpip_output();
/* Now, create the second packet. To do this, it is not enough to /* Now, create the second packet. To do this, it is not enough to
@ -96,6 +97,7 @@ uip_split_output(void)
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 );
@ -119,18 +121,24 @@ uip_split_output(void)
BUF->tcpchksum = ~( uip_tcpchksum() ); BUF->tcpchksum = ~( uip_tcpchksum() );
#if !UIP_CONF_IPV6 #if !UIP_CONF_IPV6
/* Recalculate the IP checksum. */ /* Recalculate the IP checksum. */
BUF->ipchksum = 0; BUF->ipchksum = 0;
BUF->ipchksum = ~( uip_ipchksum() ); BUF->ipchksum = ~( uip_ipchksum() );
#endif /* UIP_CONF_IPV6 */ #endif /* UIP_CONF_IPV6 */
/* Transmit the second packet. */ /* Transmit the second packet. */
/* uip_fw_output();*/ /* uip_fw_output();*/
// tcpip_output(); // tcpip_output();
} else { }
else
{
/* uip_fw_output();*/ /* uip_fw_output();*/
// tcpip_output(); // tcpip_output();
} }
}
}
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

File diff suppressed because it is too large Load diff

View file

@ -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__ */

View file

@ -57,8 +57,6 @@
* $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>
@ -66,8 +64,8 @@
#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;
@ -83,43 +81,35 @@ struct arp_hdr {
#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 ethip_hdr { {
struct uip_eth_hdr ethhdr; struct uip_eth_hdr ethhdr;
/* IP header. */ /* IP header. */
u8_t vhl, u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
tos,
len[2],
ipid[2],
ipoffset[2],
ttl,
proto;
u16_t ipchksum; u16_t ipchksum;
u16_t srcipaddr[2], u16_t srcipaddr[2], destipaddr[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_REQUEST 1
#define ARP_REPLY 2 #define ARP_REPLY 2
#define ARP_HWTYPE_ETH 1 #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];
@ -131,20 +121,25 @@ static u8_t tmpage;
#define BUF ( ( struct arp_hdr * ) &uip_buf[0] ) #define BUF ( ( struct arp_hdr * ) &uip_buf[0] )
#define IPBUF ( ( struct ethip_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,42 +148,42 @@ 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; ++arptime;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
tabptr = &arp_table[i]; tabptr = &arp_table[i];
if((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 && if( (tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 && arptime - tabptr->time >= UIP_ARP_MAXAGE )
arptime - tabptr->time >= UIP_ARP_MAXAGE) { {
memset( tabptr->ipaddr, 0, 4 ); 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. */
if(tabptr->ipaddr[0] != 0 &&
tabptr->ipaddr[1] != 0) {
/* Only check those entries that are actually in use. */
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. */ /* An old entry found, update this and return. */
memcpy( tabptr->ethaddr.addr, ethaddr->addr, 6 ); memcpy( tabptr->ethaddr.addr, ethaddr->addr, 6 );
tabptr->time = arptime; tabptr->time = arptime;
@ -202,26 +197,31 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
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]; tabptr = &arp_table[i];
if(tabptr->ipaddr[0] == 0 && if( tabptr->ipaddr[0] == 0 && tabptr->ipaddr[1] == 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; tmpage = 0;
c = 0; c = 0;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
tabptr = &arp_table[i]; tabptr = &arp_table[i];
if(arptime - tabptr->time > tmpage) { if( arptime - tabptr->time > tmpage )
{
tmpage = arptime - tabptr->time; tmpage = arptime - tabptr->time;
c = i; c = i;
} }
} }
i = c; i = c;
tabptr = &arp_table[i]; tabptr = &arp_table[i];
} }
@ -232,7 +232,9 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
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])) { if( (IPBUF->srcipaddr[1] & uip_netmask[1]) != (uip_hostaddr[1] & uip_netmask[1]) )
{
return; return;
} }
uip_arp_update( IPBUF->srcipaddr, &(IPBUF->ethhdr.src) ); uip_arp_update( IPBUF->srcipaddr, &(IPBUF->ethhdr.src) );
return; return;
} }
#endif /* 0 */ #endif /* 0 */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/** /**
* ARP processing for incoming ARP packets. * ARP processing for incoming ARP packets.
* *
@ -289,22 +296,25 @@ 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
uip_arp_arpin(void)
{
if(uip_len < sizeof(struct arp_hdr)) { /*-----------------------------------------------------------------------------------*/
void uip_arp_arpin( void )
{
if( uip_len < sizeof(struct arp_hdr) )
{
uip_len = 0; uip_len = 0;
return; return;
} }
uip_len = 0; uip_len = 0;
switch(BUF->opcode) { switch( BUF->opcode )
{
case HTONS( ARP_REQUEST ): case HTONS( ARP_REQUEST ):
/* ARP request. If it asked for our address, we send out a /* 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. */
@ -326,19 +336,25 @@ uip_arp_arpin(void)
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; break;
case HTONS( ARP_REPLY ): case HTONS( ARP_REPLY ):
/* ARP reply. We insert or update the ARP table if it was meant /* 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; break;
} }
return; 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,9 +381,9 @@ 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 void uip_arp_out( void )
uip_arp_out(void)
{ {
struct arp_entry *tabptr; struct arp_entry *tabptr;
@ -379,31 +395,39 @@ uip_arp_out(void)
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 ); memcpy( IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6 );
} else { }
else
{
/* Check if the destination address is on the local network. */ /* Check if the destination address is on the local network. */
if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) { if( !uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask) )
{
/* Destination address was not on the local network, so we need to /* 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
{
/* Else, we use the destination IP address. */ /* Else, we use the destination IP address. */
uip_ipaddr_copy( ipaddr, IPBUF->destipaddr ); 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]; tabptr = &arp_table[i];
if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) { if( uip_ipaddr_cmp(ipaddr, tabptr->ipaddr) )
{
break; 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->ethhdr.dest.addr, 0xff, 6 );
memset( BUF->dhwaddr.addr, 0x00, 6 ); memset( BUF->dhwaddr.addr, 0x00, 6 );
memcpy( BUF->ethhdr.src.addr, uip_ethaddr.addr, 6 ); memcpy( BUF->ethhdr.src.addr, uip_ethaddr.addr, 6 );
@ -427,13 +451,16 @@ uip_arp_out(void)
/* Build an ethernet header. */ /* Build an ethernet header. */
memcpy( IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6 ); memcpy( IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6 );
} }
memcpy( IPBUF->ethhdr.src.addr, uip_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 );
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/** @} */ /** @} */
/** @} */ /** @} */

View file

@ -32,15 +32,11 @@
* $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;
@ -48,26 +44,37 @@ uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
tmp = 0; tmp = 0;
for(i = 0; i < 4; ++i) { for( i = 0; i < 4; ++i )
{
j = 0; j = 0;
do { do
{
c = *addrstr; c = *addrstr;
++j; ++j;
if(j > 4) { if( j > 4 )
{
return 0; return 0;
} }
if(c == '.' || c == 0) {
if( c == '.' || c == 0 )
{
*ipaddr = tmp; *ipaddr = tmp;
++ipaddr; ++ipaddr;
tmp = 0; tmp = 0;
} else if(c >= '0' && c <= '9') { }
else if( c >= '0' && c <= '9' )
{
tmp = ( tmp * 10 ) + ( c - '0' ); tmp = ( tmp * 10 ) + ( c - '0' );
} else { }
else
{
return 0; return 0;
} }
++addrstr; ++addrstr;
} while( c != '.' && c != 0 ); } while( c != '.' && c != 0 );
} }
return 1; return 1;
} }