From 3e92f843ba2452b49cd716e7da08c3c01eda9be2 Mon Sep 17 00:00:00 2001 From: oliverschmidt Date: Mon, 18 Sep 2006 23:27:42 +0000 Subject: [PATCH] More uip_ipaddr_t fixes. --- apps/dhcp/dhcp.c | 27 +++++++++++++------------- apps/netconf/netconf.c | 44 +++++++++++++++++++++--------------------- core/net/resolv.c | 14 +++++++------- core/net/resolv.h | 6 +++--- 4 files changed, 45 insertions(+), 46 deletions(-) diff --git a/apps/dhcp/dhcp.c b/apps/dhcp/dhcp.c index f3a7d1e86..419d7008c 100644 --- a/apps/dhcp/dhcp.c +++ b/apps/dhcp/dhcp.c @@ -60,37 +60,36 @@ makebyte(u8_t byte, char *str) } /*---------------------------------------------------------------------------*/ static void -makeaddr(u16_t *addr, char *str) +makeaddr(uip_ipaddr_t *addr, char *str) { - str = makebyte(HTONS(addr[0]) >> 8, str); + str = makebyte(addr->u8[0], str); *str++ = '.'; - str = makebyte(HTONS(addr[0]) & 0xff, str); + str = makebyte(addr->u8[1], str); *str++ = '.'; - str = makebyte(HTONS(addr[1]) >> 8, str); + str = makebyte(addr->u8[2], str); *str++ = '.'; - str = makebyte(HTONS(addr[1]) & 0xff, str); + str = makebyte(addr->u8[3], str); *str++ = 0; } /*---------------------------------------------------------------------------*/ static void makestrings(void) { - u16_t addr[2], *addrptr; + uip_ipaddr_t addr, *addrptr; - uip_gethostaddr((uip_ipaddr_t *)addr); - makeaddr(addr, ipaddr); + uip_gethostaddr(&addr); + makeaddr(&addr, ipaddr); - uip_getnetmask((uip_ipaddr_t *)addr); - makeaddr(addr, netmask); + uip_getnetmask(&addr); + makeaddr(&addr, netmask); - uip_getdraddr((uip_ipaddr_t *)addr); - makeaddr(addr, gateway); + uip_getdraddr(&addr); + makeaddr(&addr, gateway); addrptr = resolv_getserver(); if(addrptr != NULL) { makeaddr(addrptr, dnsserver); } - } /*---------------------------------------------------------------------------*/ PROCESS_THREAD(dhcp_process, ev, data) @@ -146,7 +145,7 @@ dhcpc_configured(const struct dhcpc_state *s) uip_sethostaddr(&s->ipaddr); uip_setnetmask(&s->netmask); uip_setdraddr(&s->default_router); - resolv_conf((u16_t *)&s->dnsaddr); + resolv_conf(&s->dnsaddr); set_statustext("Configured."); process_post(PROCESS_CURRENT(), SHOWCONFIG, NULL); } diff --git a/apps/netconf/netconf.c b/apps/netconf/netconf.c index 4e8c901ee..baf9bf841 100644 --- a/apps/netconf/netconf.c +++ b/apps/netconf/netconf.c @@ -29,7 +29,7 @@ * * This file is part of the Contiki desktop environment * - * $Id: netconf.c,v 1.4 2006/09/18 22:48:05 oliverschmidt Exp $ + * $Id: netconf.c,v 1.5 2006/09/18 23:27:42 oliverschmidt Exp $ * */ @@ -83,31 +83,31 @@ makebyte(u8_t byte, char *str) } /*-----------------------------------------------------------------------------------*/ static void -makeaddr(u16_t *addr, char *str) +makeaddr(uip_ipaddr_t *addr, char *str) { - str = makebyte(HTONS(addr[0]) >> 8, str); + str = makebyte(addr->u8[0], str); *str++ = '.'; - str = makebyte(HTONS(addr[0]) & 0xff, str); + str = makebyte(addr->u8[1], str); *str++ = '.'; - str = makebyte(HTONS(addr[1]) >> 8, str); + str = makebyte(addr->u8[2], str); *str++ = '.'; - str = makebyte(HTONS(addr[1]) & 0xff, str); + str = makebyte(addr->u8[3], str); *str++ = 0; } /*-----------------------------------------------------------------------------------*/ static void makestrings(void) { - u16_t addr[2], *addrptr; + uip_ipaddr_t addr, *addrptr; - uip_gethostaddr((uip_ipaddr_t *)addr); - makeaddr(addr, ipaddr); + uip_gethostaddr(&addr); + makeaddr(&addr, ipaddr); - uip_getnetmask((uip_ipaddr_t *)addr); - makeaddr(addr, netmask); + uip_getnetmask(&addr); + makeaddr(&addr, netmask); - uip_getdraddr((uip_ipaddr_t *)addr); - makeaddr(addr, gateway); + uip_getdraddr(&addr); + makeaddr(&addr, gateway); addrptr = resolv_getserver(); if(addrptr != NULL) { @@ -127,26 +127,26 @@ nullterminate(char *cptr) static void apply_tcpipconfig(void) { - u16_t addr[2]; + uip_ipaddr_t addr; nullterminate(ipaddr); - if(uiplib_ipaddrconv(ipaddr, (unsigned char *)addr)) { - uip_sethostaddr((uip_ipaddr_t *)addr); + if(uiplib_ipaddrconv(ipaddr, (unsigned char *)&addr)) { + uip_sethostaddr(&addr); } nullterminate(netmask); - if(uiplib_ipaddrconv(netmask, (unsigned char *)addr)) { - uip_setnetmask((uip_ipaddr_t *)addr); + if(uiplib_ipaddrconv(netmask, (unsigned char *)&addr)) { + uip_setnetmask(&addr); } nullterminate(gateway); - if(uiplib_ipaddrconv(gateway, (unsigned char *)addr)) { - uip_setdraddr((uip_ipaddr_t *)addr); + if(uiplib_ipaddrconv(gateway, (unsigned char *)&addr)) { + uip_setdraddr(&addr); } nullterminate(dnsserver); - if(uiplib_ipaddrconv(dnsserver, (unsigned char *)addr)) { - resolv_conf(addr); + if(uiplib_ipaddrconv(dnsserver, (unsigned char *)&addr)) { + resolv_conf(&addr); } } /*-----------------------------------------------------------------------------------*/ diff --git a/core/net/resolv.c b/core/net/resolv.c index 831a43da5..7a6167457 100644 --- a/core/net/resolv.c +++ b/core/net/resolv.c @@ -57,7 +57,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: resolv.c,v 1.3 2006/08/14 23:37:21 oliverschmidt Exp $ + * $Id: resolv.c,v 1.4 2006/09/18 23:30:40 oliverschmidt Exp $ * */ @@ -453,13 +453,13 @@ resolv_lookup(char *name) * been configured. */ /*-----------------------------------------------------------------------------------*/ -u16_t * +uip_ipaddr_t * resolv_getserver(void) { if(resolv_conn == NULL) { return NULL; } - return resolv_conn->ripaddr.u16; + return &resolv_conn->ripaddr; } /*-----------------------------------------------------------------------------------*/ /** @@ -470,11 +470,11 @@ resolv_getserver(void) */ /*-----------------------------------------------------------------------------------*/ void -resolv_conf(u16_t *dnsserver) +resolv_conf(const uip_ipaddr_t *dnsserver) { - static u16_t server[2]; - uip_ipaddr_copy(server, dnsserver); - process_post(&resolv_process, EVENT_NEW_SERVER, server); + static uip_ipaddr_t server; + uip_ipaddr_copy(&server, dnsserver); + process_post(&resolv_process, EVENT_NEW_SERVER, &server); /* if(resolv_conn != NULL) { uip_udp_remove(resolv_conn); diff --git a/core/net/resolv.h b/core/net/resolv.h index 48831f7c5..c1bcbfa1d 100644 --- a/core/net/resolv.h +++ b/core/net/resolv.h @@ -34,7 +34,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: resolv.h,v 1.2 2006/08/26 23:58:45 oliverschmidt Exp $ + * $Id: resolv.h,v 1.3 2006/09/18 23:30:40 oliverschmidt Exp $ * */ #ifndef __RESOLV_H__ @@ -51,8 +51,8 @@ CCIF extern process_event_t resolv_event_found; void resolv_found(char *name, u16_t *ipaddr); /* Functions. */ -CCIF void resolv_conf(u16_t *dnsserver); -CCIF u16_t *resolv_getserver(void); +CCIF void resolv_conf(const uip_ipaddr_t *dnsserver); +CCIF uip_ipaddr_t *resolv_getserver(void); void resolv_init(char *arg); CCIF u16_t *resolv_lookup(char *name); CCIF void resolv_query(char *name);