liqinhuixm commented on code in PR #2218: URL: https://github.com/apache/nuttx-apps/pull/2218#discussion_r1418211134
########## netutils/netlib/netlib_obtainipv6addr.c: ########## @@ -0,0 +1,178 @@ +/**************************************************************************** + * apps/netutils/netlib/netlib_obtainipv6addr.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <debug.h> + +#include <netinet/in.h> +#include <net/if.h> +#include <nuttx/net/dns.h> + +#include "netutils/netlib.h" +#include "netutils/dhcp6c.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_NET_ETHERNET +static void icmpv6_linkipaddr_6(FAR const uint8_t *mac, FAR uint16_t *ipaddr) +{ + ipaddr[0] = HTONS(0xfe80); + ipaddr[1] = 0; + ipaddr[2] = 0; + ipaddr[3] = 0; + ipaddr[4] = HTONS(mac[0] << 8 | mac[1]); + ipaddr[5] = HTONS(mac[2] << 8 | 0x00ff); + ipaddr[6] = HTONS(0x00fe << 8 | mac[3]); + ipaddr[7] = HTONS(mac[4] << 8 | mac[5]); + ipaddr[4] ^= HTONS(0x0200); +} + +static void dhcpv6_set_lladdr(FAR const char *ifname) +{ + struct in6_addr addr6; + uint8_t mac[IFHWADDRLEN]; + + /* Get the MAC address of the NIC */ + + netlib_getmacaddr(ifname, mac); + + /* Set the Link Local Address of the NIC */ + + icmpv6_linkipaddr_6(mac, (uint16_t *)&addr6); + netlib_set_ipv6addr(ifname, &addr6); + netlib_prefix2ipv6netmask(64, &addr6); +} +#endif + +static int dhcpv6_setup_result(FAR const char *ifname, + FAR struct dhcp6c_state *presult) Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org