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

@ -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
sent. */
s->sendptr = ( u8_t*)buf;
s->sendptr = ( u8_t * ) buf;
s->sendlen = len;
s->state = STATE_NONE;
@ -305,7 +305,7 @@ PT_THREAD( psock_readto ( register struct psock *psock, unsigned char c ) )
{
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
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 );
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
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->bufptr = buffer;
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->psockpt );
}

View file

@ -44,11 +44,11 @@
*
* $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $
*/
#include "clock.h"
#include "uip_timer.h"
/*---------------------------------------------------------------------------*/
/**
* Set a timer.
*
@ -60,13 +60,14 @@
* \param interval The interval before the timer expires.
*
*/
void
timer_set(struct timer *t, clock_time_t interval)
void timer_set( struct timer *t, clock_time_t interval )
{
t->interval = interval;
t->start = clock_time();
}
/*---------------------------------------------------------------------------*/
/**
* Reset the timer with the same interval.
*
@ -80,12 +81,13 @@ timer_set(struct timer *t, clock_time_t interval)
*
* \sa timer_restart()
*/
void
timer_reset(struct timer *t)
void timer_reset( struct timer *t )
{
t->start += t->interval;
}
/*---------------------------------------------------------------------------*/
/**
* Restart the timer from the current point in time
*
@ -100,12 +102,13 @@ timer_reset(struct timer *t)
*
* \sa timer_reset()
*/
void
timer_restart(struct timer *t)
void timer_restart( struct timer *t )
{
t->start = clock_time();
}
/*---------------------------------------------------------------------------*/
/**
* 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.
*
*/
int
timer_expired(struct timer *t)
int 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 $
*/
#include <string.h>
#include "uip-split.h"
@ -40,54 +39,56 @@
#include "uip-fw.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
uip_split_output(void)
void uip_split_output( void )
{
u16_t tcplen, len1, len2;
/* We only try to split maximum sized TCP segments. */
if(BUF->proto == UIP_PROTO_TCP &&
uip_len == UIP_BUFSIZE - UIP_LLH_LEN) {
if( BUF->proto == UIP_PROTO_TCP && uip_len == UIP_BUFSIZE - UIP_LLH_LEN )
{
tcplen = uip_len - UIP_TCPIP_HLEN;
/* Split the segment in two. If the original packet length was
odd, we make the second packet one byte larger. */
len1 = len2 = tcplen / 2;
if(len1 + len2 < tcplen) {
if( len1 + len2 < tcplen )
{
++len2;
}
/* Create the first packet. This is done by altering the length
field of the IP header and updating the checksums. */
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
length. */
BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
#else /* UIP_CONF_IPV6 */
BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );
BUF->len[1] = ( (uip_len - UIP_IPH_LEN) & 0xff );
#else /* UIP_CONF_IPV6 */
BUF->len[0] = uip_len >> 8;
BUF->len[1] = uip_len & 0xff;
#endif /* UIP_CONF_IPV6 */
#endif /* UIP_CONF_IPV6 */
/* Recalculate the TCP checksum. */
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 */
BUF->ipchksum = ~( uip_ipchksum() );
#endif /* UIP_CONF_IPV6 */
/* Transmit the first packet. */
/* uip_fw_output();*/
// tcpip_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
@ -95,20 +96,21 @@ uip_split_output(void)
memory. This place is detemined by the length of the first
packet (len1). */
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
length. */
BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
#else /* UIP_CONF_IPV6 */
BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );
BUF->len[1] = ( (uip_len - UIP_IPH_LEN) & 0xff );
#else /* UIP_CONF_IPV6 */
BUF->len[0] = uip_len >> 8;
BUF->len[1] = uip_len & 0xff;
#endif /* UIP_CONF_IPV6 */
#endif /* UIP_CONF_IPV6 */
/* 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[1] = uip_acc32[1];
BUF->seqno[2] = uip_acc32[2];
@ -116,21 +118,27 @@ uip_split_output(void)
/* Recalculate the TCP checksum. */
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 */
BUF->ipchksum = ~( uip_ipchksum() );
#endif /* UIP_CONF_IPV6 */
/* Transmit the second packet. */
/* uip_fw_output();*/
// tcpip_output();
} else {
/* uip_fw_output();*/
// tcpip_output();
}
/* uip_fw_output();*/
// tcpip_output();
}
else
{
/* uip_fw_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);
/**
* Work out the fasted way of sending the data to the low level driver.
*/
int uip_fast_send( int xARP );
#endif /* __UIP_H__ */

View file

@ -57,17 +57,15 @@
* $Id: uip_arp.c,v 1.8 2006/06/02 23:36:21 adam Exp $
*
*/
#include "uip_arp.h"
#include <string.h>
#ifdef __ICCARM__
#pragma pack(1)
#pragma pack( 1 )
#endif
struct arp_hdr {
struct arp_hdr
{
struct uip_eth_hdr ethhdr;
u16_t hwtype;
u16_t protocol;
@ -83,44 +81,36 @@ struct arp_hdr {
#ifdef __ICCARM__
#pragma pack()
#endif
#ifdef __ICCARM__
#pragma pack(1)
#pragma pack( 1 )
#endif
struct ethip_hdr {
struct ethip_hdr
{
struct uip_eth_hdr ethhdr;
/* IP header. */
u8_t vhl,
tos,
len[2],
ipid[2],
ipoffset[2],
ttl,
proto;
u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
u16_t ipchksum;
u16_t srcipaddr[2],
destipaddr[2];
u16_t srcipaddr[2], destipaddr[2];
} PACK_STRUCT_END;
#ifdef __ICCARM__
#pragma pack()
#endif
#define ARP_REQUEST 1
#define ARP_REPLY 2
#define ARP_HWTYPE_ETH 1
struct arp_entry {
struct arp_entry
{
u16_t ipaddr[2];
struct uip_eth_addr ethaddr;
u8_t time;
};
static const struct uip_eth_addr broadcast_ethaddr =
{{0xff,0xff,0xff,0xff,0xff,0xff}};
static const u16_t broadcast_ipaddr[2] = {0xffff,0xffff};
static const struct uip_eth_addr broadcast_ethaddr = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
static const u16_t broadcast_ipaddr[2] = { 0xffff, 0xffff };
static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
static u16_t ipaddr[2];
@ -129,22 +119,27 @@ static u8_t i, c;
static u8_t arptime;
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.
*
*/
/*-----------------------------------------------------------------------------------*/
void
uip_arp_init(void)
void uip_arp_init( void )
{
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
memset(arp_table[i].ipaddr, 0, 4);
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
memset( arp_table[i].ipaddr, 0, 4 );
}
}
/*-----------------------------------------------------------------------------------*/
/**
* Periodic ARP processing function.
*
@ -153,44 +148,44 @@ uip_arp_init(void)
* is 10 seconds between the calls.
*
*/
/*-----------------------------------------------------------------------------------*/
void
uip_arp_timer(void)
void uip_arp_timer( void )
{
struct arp_entry *tabptr;
++arptime;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
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);
if( (tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 && arptime - tabptr->time >= UIP_ARP_MAXAGE )
{
memset( tabptr->ipaddr, 0, 4 );
}
}
}
/*-----------------------------------------------------------------------------------*/
static void
uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
static void uip_arp_update( u16_t *ipaddr, struct uip_eth_addr *ethaddr )
{
register struct arp_entry *tabptr;
/* Walk through the ARP mapping table and try to find an entry to
update. If none is found, the IP -> MAC address mapping is
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];
/* 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
the IP address in this ARP table entry. */
if(ipaddr[0] == tabptr->ipaddr[0] &&
ipaddr[1] == tabptr->ipaddr[1]) {
if( ipaddr[0] == tabptr->ipaddr[0] && ipaddr[1] == tabptr->ipaddr[1] )
{
/* 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;
return;
@ -202,37 +197,44 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
create one. */
/* 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->ipaddr[1] == 0) {
if( tabptr->ipaddr[0] == 0 && tabptr->ipaddr[1] == 0 )
{
break;
}
}
/* If no unused entry is found, we try to find the oldest entry and
throw it away. */
if(i == UIP_ARPTAB_SIZE) {
if( i == UIP_ARPTAB_SIZE )
{
tmpage = 0;
c = 0;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
tabptr = &arp_table[i];
if(arptime - tabptr->time > tmpage) {
if( arptime - tabptr->time > tmpage )
{
tmpage = arptime - tabptr->time;
c = i;
}
}
i = c;
tabptr = &arp_table[i];
}
/* Now, i is the ARP table entry which we will fill with the new
information. */
memcpy(tabptr->ipaddr, ipaddr, 4);
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
memcpy( tabptr->ipaddr, ipaddr, 4 );
memcpy( tabptr->ethaddr.addr, ethaddr->addr, 6 );
tabptr->time = arptime;
}
/*-----------------------------------------------------------------------------------*/
/**
* 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
* variable uip_len.
*/
/*-----------------------------------------------------------------------------------*/
#if 1
void
uip_arp_ipin(void)
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
incoming IP packet comes from a host on the local network. */
if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
(uip_hostaddr[0] & uip_netmask[0])) {
if( (IPBUF->srcipaddr[0] & uip_netmask[0]) != (uip_hostaddr[0] & uip_netmask[0]) )
{
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;
}
uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
uip_arp_update( IPBUF->srcipaddr, &(IPBUF->ethhdr.src) );
return;
}
#endif /* 0 */
/*-----------------------------------------------------------------------------------*/
/**
* 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
* 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;
return;
}
uip_len = 0;
switch(BUF->opcode) {
case HTONS(ARP_REQUEST):
switch( BUF->opcode )
{
case HTONS( ARP_REQUEST ):
/* ARP request. If it asked for our address, we send out a
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
table, since it is likely that we will do more communication
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. */
BUF->opcode = HTONS(2);
BUF->opcode = HTONS( 2 );
memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
memcpy(BUF->shwaddr.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->dhwaddr.addr, BUF->shwaddr.addr, 6 );
memcpy( BUF->shwaddr.addr, uip_ethaddr.addr, 6 );
memcpy( BUF->ethhdr.src.addr, uip_ethaddr.addr, 6 );
memcpy( BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6 );
BUF->dipaddr[0] = BUF->sipaddr[0];
BUF->dipaddr[1] = BUF->sipaddr[1];
BUF->sipaddr[0] = uip_hostaddr[0];
BUF->sipaddr[1] = uip_hostaddr[1];
BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
uip_len = sizeof(struct arp_hdr);
BUF->ethhdr.type = HTONS( UIP_ETHTYPE_ARP );
uip_len = sizeof( struct arp_hdr );
}
break;
case HTONS(ARP_REPLY):
case HTONS( ARP_REPLY ):
/* ARP reply. We insert or update the ARP table if it was meant
for us. */
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
if( uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr) )
{
uip_arp_update( BUF->sipaddr, &BUF->shwaddr );
}
break;
}
return;
}
/*-----------------------------------------------------------------------------------*/
/**
* Prepend Ethernet header to an outbound IP packet and see if we need
* 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
* uip_len.
*/
/*-----------------------------------------------------------------------------------*/
void
uip_arp_out(void)
void uip_arp_out( void )
{
struct arp_entry *tabptr;
@ -379,61 +395,72 @@ uip_arp_out(void)
packet with an ARP request for the IP address. */
/* First check if destination is a local broadcast. */
if(uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) {
memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
} else {
if( uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr) )
{
memcpy( IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6 );
}
else
{
/* 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
use the default router's IP address instead of the destination
address when determining the MAC address. */
uip_ipaddr_copy(ipaddr, uip_draddr);
} else {
uip_ipaddr_copy( ipaddr, uip_draddr );
}
else
{
/* 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];
if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
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
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);
memset(BUF->dhwaddr.addr, 0x00, 6);
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
uip_ipaddr_copy(BUF->dipaddr, ipaddr);
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);
uip_ipaddr_copy( BUF->dipaddr, ipaddr );
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);
BUF->ethhdr.type = HTONS( UIP_ETHTYPE_ARP );
uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
uip_len = sizeof(struct arp_hdr);
uip_len = sizeof( struct arp_hdr );
return;
}
/* 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);
IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);
memcpy( IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6 );
uip_len += sizeof(struct uip_eth_hdr);
IPBUF->ethhdr.type = HTONS( UIP_ETHTYPE_IP );
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 $
*
*/
#include "uip.h"
#include "uiplib.h"
/*-----------------------------------------------------------------------------------*/
unsigned char
uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
unsigned char uiplib_ipaddrconv( char *addrstr, unsigned char *ipaddr )
{
unsigned char tmp;
char c;
@ -48,26 +44,37 @@ uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
tmp = 0;
for(i = 0; i < 4; ++i) {
for( i = 0; i < 4; ++i )
{
j = 0;
do {
do
{
c = *addrstr;
++j;
if(j > 4) {
if( j > 4 )
{
return 0;
}
if(c == '.' || c == 0) {
if( c == '.' || c == 0 )
{
*ipaddr = tmp;
++ipaddr;
tmp = 0;
} else if(c >= '0' && c <= '9') {
tmp = (tmp * 10) + (c - '0');
} else {
}
else if( c >= '0' && c <= '9' )
{
tmp = ( tmp * 10 ) + ( c - '0' );
}
else
{
return 0;
}
++addrstr;
} while(c != '.' && c != 0);
} while( c != '.' && c != 0 );
}
return 1;
}