diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-10-31 23:27:55 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-10-31 23:27:55 +0000 |
commit | be3873f03972b44e95458345b5ab73b1b75e2eee (patch) | |
tree | 2fc5881e116bb36f5d6c6f2ae8ed86456b96c2cf /nuttx/netutils | |
parent | a76a953e2fb34a521faac9c66207c08f77da9ce5 (diff) | |
download | px4-nuttx-be3873f03972b44e95458345b5ab73b1b75e2eee.tar.gz px4-nuttx-be3873f03972b44e95458345b5ab73b1b75e2eee.tar.bz2 px4-nuttx-be3873f03972b44e95458345b5ab73b1b75e2eee.zip |
in progress update
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@360 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/netutils')
-rw-r--r-- | nuttx/netutils/dhcpc/dhcpc.c | 34 | ||||
-rw-r--r-- | nuttx/netutils/resolv/resolv.c | 40 | ||||
-rw-r--r-- | nuttx/netutils/uiplib/uip-gethostaddr.c | 2 |
3 files changed, 49 insertions, 27 deletions
diff --git a/nuttx/netutils/dhcpc/dhcpc.c b/nuttx/netutils/dhcpc/dhcpc.c index cff741794..a84728013 100644 --- a/nuttx/netutils/dhcpc/dhcpc.c +++ b/nuttx/netutils/dhcpc/dhcpc.c @@ -161,7 +161,7 @@ static uint8 *add_req_ipaddr(struct dhcpc_state *presult, uint8 *optptr) { *optptr++ = DHCP_OPTION_REQ_IPADDR; *optptr++ = 4; - memcpy(optptr, presult->ipaddr, 4); + memcpy(optptr, &presult->ipaddr.s_addr, 4); return optptr + 4; } @@ -262,13 +262,13 @@ static uint8 parse_options(struct dhcpc_state *presult, uint8 *optptr, int len) switch(*optptr) { case DHCP_OPTION_SUBNET_MASK: - memcpy(presult->netmask, optptr + 2, 4); + memcpy(&presult->netmask.s_addr, optptr + 2, 4); break; case DHCP_OPTION_ROUTER: - memcpy(presult->default_router, optptr + 2, 4); + memcpy(&presult->default_router.s_addr, optptr + 2, 4); break; case DHCP_OPTION_DNS_SERVER: - memcpy(presult->dnsaddr, optptr + 2, 4); + memcpy(&presult->dnsaddr.s_addr, optptr + 2, 4); break; case DHCP_OPTION_MSG_TYPE: type = *(optptr + 2); @@ -296,7 +296,7 @@ static uint8 parse_msg(struct dhcpc_state_internal *pdhcpc, int buflen, struct d memcmp(pbuffer->xid, xid, sizeof(xid)) == 0 && memcmp(pbuffer->chaddr, pdhcpc->mac_addr, pdhcpc->mac_len) == 0) { - memcpy(presult->ipaddr, pbuffer->yiaddr, 4); + memcpy(&presult->ipaddr.s_addr, pbuffer->yiaddr, 4); return parse_options(presult, &pbuffer->options[4], buflen); } return 0; @@ -440,17 +440,25 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult) while(state != STATE_CONFIG_RECEIVED); dbg("Got IP address %d.%d.%d.%d\n", - uip_ipaddr1(presult->ipaddr), uip_ipaddr2(presult->ipaddr), - uip_ipaddr3(presult->ipaddr), uip_ipaddr4(presult->ipaddr)); + (presult->ipaddr.s_addr >> 24 ) & 0xff, + (presult->ipaddr.s_addr >> 16 ) & 0xff, + (presult->ipaddr.s_addr >> 8 ) & 0xff, + (presult->ipaddr.s_addr ) & 0xff); dbg("Got netmask %d.%d.%d.%d\n", - uip_ipaddr1(presult->netmask), uip_ipaddr2(presult->netmask), - uip_ipaddr3(presult->netmask), uip_ipaddr4(presult->netmask)); + (presult->netmask.s_addr >> 24 ) & 0xff, + (presult->netmask.s_addr >> 16 ) & 0xff, + (presult->netmask.s_addr >> 8 ) & 0xff, + (presult->netmask.s_addr ) & 0xff); dbg("Got DNS server %d.%d.%d.%d\n", - uip_ipaddr1(presult->dnsaddr), uip_ipaddr2(presult->dnsaddr), - uip_ipaddr3(presult->dnsaddr), uip_ipaddr4(presult->dnsaddr)); + (presult->dnsaddr.s_addr >> 24 ) & 0xff, + (presult->dnsaddr.s_addr >> 16 ) & 0xff, + (presult->dnsaddr.s_addr >> 8 ) & 0xff, + (presult->dnsaddr.s_addr ) & 0xff); dbg("Got default router %d.%d.%d.%d\n", - uip_ipaddr1(presult->default_router), uip_ipaddr2(presult->default_router), - uip_ipaddr3(presult->default_router), uip_ipaddr4(presult->default_router)); + (presult->default_router.s_addr >> 24 ) & 0xff, + (presult->default_router.s_addr >> 16 ) & 0xff, + (presult->default_router.s_addr >> 8 ) & 0xff, + (presult->default_router.s_addr ) & 0xff); dbg("Lease expires in %ld seconds\n", ntohs(presult->lease_time[0])*65536ul + ntohs(presult->lease_time[1])); return OK; diff --git a/nuttx/netutils/resolv/resolv.c b/nuttx/netutils/resolv/resolv.c index b318e551e..741116bb7 100644 --- a/nuttx/netutils/resolv/resolv.c +++ b/nuttx/netutils/resolv/resolv.c @@ -130,8 +130,9 @@ struct dns_answer uint16 ttl[2]; uint16 len; #ifdef CONFIG_NET_IPv6 + struct in6_addr ipaddr; #else - uint16 ipaddr[2]; + struct in_addr ipaddr; #endif }; @@ -144,8 +145,9 @@ struct namemap uint8 err; char name[32]; #ifdef CONFIG_NET_IPv6 + struct in6_addr ipaddr; #else - uint16 ipaddr[2]; + struct in_addr ipaddr; #endif }; @@ -200,7 +202,7 @@ static int send_query(const char *name, struct sockaddr_in *addr) char *nptr; const char *nameptr; uint8 seqno = g_seqno++; - static unsigned char endquery[] = {0,0,1,0,1}; + static unsigned char endquery[] = {0, 0, 1, 0, 1}; char buffer[SEND_BUFFER_SIZE]; int n; @@ -234,7 +236,7 @@ static int send_query(const char *name, struct sockaddr_in *addr) /* Called when new UDP data arrives */ #ifdef CONFIG_NET_IPv6 -#error "Not implemented +#error "Not implemented" #else int recv_response(struct sockaddr_in *addr) #endif @@ -314,14 +316,16 @@ int recv_response(struct sockaddr_in *addr) if (ans->type == HTONS(1) && ans->class == HTONS(1) && ans->len == HTONS(4)) { dbg("IP address %d.%d.%d.%d\n", - htons(ans->ipaddr[0]) >> 8, htons(ans->ipaddr[0]) & 0xff, - htons(ans->ipaddr[1]) >> 8, htons(ans->ipaddr[1]) & 0xff); + (ans->ipaddr.s_addr >> 24 ) & 0xff, + (ans->ipaddr.s_addr >> 16 ) & 0xff, + (ans->ipaddr.s_addr >> 8 ) & 0xff, + (ans->ipaddr.s_addr ) & 0xff); /* XXX: we should really check that this IP address is the one * we want. */ - addr->sin_addr.s_addr = ((uint32)ans->ipaddr[0] << 16) | (uint32)ans->ipaddr[1]; + addr->sin_addr.s_addr = ans->ipaddr.s_addr; return OK; } else @@ -374,23 +378,33 @@ int resolv_query(const char *name, struct sockaddr_in *addr) /* Obtain the currently configured DNS server. */ #ifdef CONFIG_NET_IPv6 -void resolv_getserver(struct sockaddr_in6 *dnsserver) +void resolv_getserver(struct in6_addr *dnsserver) #else -void resolv_getserver(struct sockaddr_in *dnsserver) +void resolv_getserver(struct in_addr *dnsserver) #endif { - memcpy(dnsserver, &g_dnsserver, ADDRLEN); +#ifdef CONFIG_NET_IPv6 + memcpy(dnsserver, &g_dnsserver.sin6_addr, ADDRLEN); +#else + dnsserver->s_addr = g_dnsserver.sin_addr.s_addr; +#endif } /* Configure which DNS server to use for queries */ #ifdef CONFIG_NET_IPv6 -void resolv_conf(const struct sockaddr_in6 *dnsserver) +void resolv_conf(const struct in6_addr *dnsserver) #else -void resolv_conf(const struct sockaddr_in *dnsserver) +void resolv_conf(const struct in_addr *dnsserver) #endif { - memcpy(&g_dnsserver, dnsserver, ADDRLEN); + g_dnsserver.sin_family = AF_INET; + g_dnsserver.sin_port = HTONS(53); +#ifdef CONFIG_NET_IPv6 + memcpy(&g_dnsserver.sin6_addr, dnsserver, ADDRLEN); +#else + g_dnsserver.sin_addr.s_addr = dnsserver->s_addr; +#endif } /* Initalize the resolver. */ diff --git a/nuttx/netutils/uiplib/uip-gethostaddr.c b/nuttx/netutils/uiplib/uip-gethostaddr.c index 64c5bb2ff..a8d36efac 100644 --- a/nuttx/netutils/uiplib/uip-gethostaddr.c +++ b/nuttx/netutils/uiplib/uip-gethostaddr.c @@ -86,7 +86,7 @@ int uip_gethostaddr(const char *ifname, struct in_addr *addr) { struct ifreq req; strncpy(req.ifr_name, ifname, IFNAMSIZ); - ret = ioctl(sockfd, SIOCSIFADDR, (unsigned long)&req); + ret = ioctl(sockfd, SIOCGIFADDR, (unsigned long)&req); if (!ret) { #ifdef CONFIG_NET_IPv6 |