X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=net%2Fnet.c;h=8f55281f406dc0bf97e71b66b990795db353d7cc;hb=7f732099a6f70689f589c40b50f8387df0f3831a;hp=fa35f0d2cde0deeec47c9a4a53cf0b2d6563aa2f;hpb=4f63acd0625553dd87d3a8a5b434578026765793;p=u-boot diff --git a/net/net.c b/net/net.c index fa35f0d2cd..8f55281f40 100644 --- a/net/net.c +++ b/net/net.c @@ -169,14 +169,12 @@ uchar NetCDPAddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc }; #endif /* Network loop state */ int NetState; -#ifdef CONFIG_NET_MULTI /* Tried all network devices */ int NetRestartWrap; /* Network loop restarted */ static int NetRestarted; /* At least one device configured */ static int NetDevExists; -#endif /* XXX in both little & big endian machines 0xFFFF == ntohs(-1) */ /* default is without VLAN */ @@ -217,6 +215,9 @@ volatile uchar *NetRxPackets[PKTBUFSRX]; /* Current RX packet handler */ static rxhand_f *packetHandler; +#ifdef CONFIG_CMD_TFTPPUT +static rxhand_icmp_f *packet_icmp_handler; /* Current ICMP rx handler */ +#endif /* Current timeout handler */ static thand_f *timeHandler; /* Time base value */ @@ -226,7 +227,7 @@ static ulong timeDelta; /* THE transmit packet */ volatile uchar *NetTxPacket; -static int net_check_prereq(proto_t protocol); +static int net_check_prereq(enum proto_t protocol); static int NetTryCount; @@ -245,7 +246,6 @@ int NetArpWaitTry; void ArpRequest(void) { - int i; volatile uchar *pkt; ARP_t *arp; @@ -267,11 +267,8 @@ void ArpRequest(void) memcpy(&arp->ar_data[0], NetOurEther, 6); /* source IP addr */ NetWriteIP((uchar *) &arp->ar_data[6], NetOurIP); - for (i = 10; i < 16; ++i) { - /* dest ET addr = 0 */ - arp->ar_data[i] = 0; - } - + /* dest ET addr = 0 */ + memset(&arp->ar_data[10], '\0', 6); if ((NetArpWaitPacketIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) { if (NetOurGatewayIP == 0) { @@ -312,8 +309,37 @@ void ArpTimeoutCheck(void) } } -static void -NetInitLoop(proto_t protocol) +/* + * Check if autoload is enabled. If so, use either NFS or TFTP to download + * the boot file. + */ +void net_auto_load(void) +{ + const char *s = getenv("autoload"); + + if (s != NULL) { + if (*s == 'n') { + /* + * Just use BOOTP/RARP to configure system; + * Do not use TFTP to load the bootfile. + */ + NetState = NETLOOP_SUCCESS; + return; + } +#if defined(CONFIG_CMD_NFS) + if (strcmp(s, "NFS") == 0) { + /* + * Use NFS to load the bootfile. + */ + NfsStart(); + return; + } +#endif + } + TftpStart(TFTPGET); +} + +static void NetInitLoop(enum proto_t protocol) { static int env_changed_id; bd_t *bd = gd->bd; @@ -321,7 +347,8 @@ NetInitLoop(proto_t protocol) /* update only when the environment has changed */ if (env_changed_id != env_id) { - NetCopyIP(&NetOurIP, &bd->bi_ip_addr); + NetOurIP = getenv_IPaddr("ipaddr"); + NetCopyIP(&bd->bi_ip_addr, &NetOurIP); NetOurGatewayIP = getenv_IPaddr("gatewayip"); NetOurSubnetMask = getenv_IPaddr("netmask"); NetServerIP = getenv_IPaddr("serverip"); @@ -341,15 +368,13 @@ NetInitLoop(proto_t protocol) * Main network processing loop. */ -int -NetLoop(proto_t protocol) +int NetLoop(enum proto_t protocol) { bd_t *bd = gd->bd; + int ret = -1; -#ifdef CONFIG_NET_MULTI NetRestarted = 0; NetDevExists = 0; -#endif /* XXX problem with bss workaround */ NetArpWaitPacketMAC = NULL; @@ -367,9 +392,8 @@ NetLoop(proto_t protocol) */ NetTxPacket = &PktBuf[0] + (PKTALIGN - 1); NetTxPacket -= (ulong)NetTxPacket % PKTALIGN; - for (i = 0; i < PKTBUFSRX; i++) { + for (i = 0; i < PKTBUFSRX; i++) NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN; - } } if (!NetArpWaitTxPacket) { @@ -379,20 +403,14 @@ NetLoop(proto_t protocol) } eth_halt(); -#ifdef CONFIG_NET_MULTI eth_set_current(); -#endif if (eth_init(bd) < 0) { eth_halt(); - return(-1); + return -1; } restart: -#ifdef CONFIG_NET_MULTI memcpy(NetOurEther, eth_get_dev()->enetaddr, 6); -#else - eth_getenv_enetaddr("ethaddr", NetOurEther); -#endif NetState = NETLOOP_CONTINUE; @@ -407,24 +425,28 @@ restart: case 1: /* network not configured */ eth_halt(); - return (-1); + return -1; -#ifdef CONFIG_NET_MULTI case 2: /* network device not configured */ break; -#endif /* CONFIG_NET_MULTI */ case 0: -#ifdef CONFIG_NET_MULTI NetDevExists = 1; -#endif + NetBootFileXferSize = 0; switch (protocol) { - case TFTP: + case TFTPGET: +#ifdef CONFIG_CMD_TFTPPUT + case TFTPPUT: +#endif /* always use ARP to get server ethernet address */ - TftpStart(); + TftpStart(protocol); break; - +#ifdef CONFIG_CMD_TFTPSRV + case TFTPSRV: + TftpStartServer(); + break; +#endif #if defined(CONFIG_CMD_DHCP) case DHCP: BootpTry = 0; @@ -480,7 +502,6 @@ restart: break; } - NetBootFileXferSize = 0; break; } @@ -491,11 +512,10 @@ restart: /* * Echo the inverted link state to the fault LED. */ - if (miiphy_link(eth_get_dev()->name, CONFIG_SYS_FAULT_MII_ADDR)) { + if (miiphy_link(eth_get_dev()->name, CONFIG_SYS_FAULT_MII_ADDR)) status_led_set(STATUS_LED_RED, STATUS_LED_OFF); - } else { + else status_led_set(STATUS_LED_RED, STATUS_LED_ON); - } #endif /* CONFIG_SYS_FAULT_ECHO_LINK_DOWN, ... */ #endif /* CONFIG_MII, ... */ @@ -523,7 +543,7 @@ restart: if (ctrlc()) { eth_halt(); puts("\nAbort\n"); - return (-1); + goto done; } ArpTimeoutCheck(); @@ -559,9 +579,7 @@ restart: switch (NetState) { case NETLOOP_RESTART: -#ifdef CONFIG_NET_MULTI NetRestarted = 1; -#endif goto restart; case NETLOOP_SUCCESS: @@ -577,12 +595,21 @@ restart: setenv("fileaddr", buf); } eth_halt(); - return NetBootFileXferSize; + ret = NetBootFileXferSize; + goto done; case NETLOOP_FAIL: - return (-1); + goto done; } } + +done: +#ifdef CONFIG_CMD_TFTPPUT + /* Clear out the handlers */ + NetSetHandler(NULL); + net_set_icmp_handler(NULL); +#endif + return ret; } /**********************************************************************/ @@ -627,10 +654,6 @@ void NetStartAgain(void) NetTryCount++; -#ifndef CONFIG_NET_MULTI - NetSetTimeout(10000UL, startAgainTimeout); - NetSetHandler(startAgainHandler); -#else /* !CONFIG_NET_MULTI*/ eth_halt(); #if !defined(CONFIG_NET_DO_NOT_TRY_ANOTHER) eth_try_another(!NetRestarted); @@ -647,7 +670,6 @@ void NetStartAgain(void) } else { NetState = NETLOOP_RESTART; } -#endif /* CONFIG_NET_MULTI */ } /**********************************************************************/ @@ -656,14 +678,20 @@ void NetStartAgain(void) */ void -NetSetHandler(rxhand_f * f) +NetSetHandler(rxhand_f *f) { packetHandler = f; } +#ifdef CONFIG_CMD_TFTPPUT +void net_set_icmp_handler(rxhand_icmp_f *f) +{ + packet_icmp_handler = f; +} +#endif void -NetSetTimeout(ulong iv, thand_f * f) +NetSetTimeout(ulong iv, thand_f *f) { if (iv == 0) { timeHandler = (thand_f *)0; @@ -676,7 +704,7 @@ NetSetTimeout(ulong iv, thand_f * f) void -NetSendPacket(volatile uchar * pkt, int len) +NetSendPacket(volatile uchar *pkt, int len) { (void) eth_send(pkt, len); } @@ -771,9 +799,9 @@ int PingSend(void) ip->ip_p = 0x01; /* ICMP */ ip->ip_sum = 0; /* already in network byte order */ - NetCopyIP((void*)&ip->ip_src, &NetOurIP); + NetCopyIP((void *)&ip->ip_src, &NetOurIP); /* - "" - */ - NetCopyIP((void*)&ip->ip_dst, &NetPingIP); + NetCopyIP((void *)&ip->ip_dst, &NetPingIP); ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2); s = &ip->udp_src; /* XXX ICMP starts here */ @@ -813,9 +841,7 @@ PingHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, static void PingStart(void) { -#if defined(CONFIG_NET_MULTI) printf("Using %s device\n", eth_get_name()); -#endif /* CONFIG_NET_MULTI */ NetSetTimeout(10000UL, PingTimeout); NetSetHandler(PingHandler); @@ -1049,7 +1075,7 @@ CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, } static void -CDPHandler(const uchar * pkt, unsigned len) +CDPHandler(const uchar *pkt, unsigned len) { const uchar *t; const ushort *ss; @@ -1095,9 +1121,8 @@ CDPHandler(const uchar * pkt, unsigned len) ss = (const ushort *)pkt; type = ntohs(ss[0]); tlen = ntohs(ss[1]); - if (tlen > len) { + if (tlen > len) goto pkt_short; - } pkt += tlen; len -= tlen; @@ -1106,51 +1131,50 @@ CDPHandler(const uchar * pkt, unsigned len) tlen -= 4; switch (type) { - case CDP_DEVICE_ID_TLV: - break; - case CDP_ADDRESS_TLV: - break; - case CDP_PORT_ID_TLV: - break; - case CDP_CAPABILITIES_TLV: - break; - case CDP_VERSION_TLV: - break; - case CDP_PLATFORM_TLV: - break; - case CDP_NATIVE_VLAN_TLV: - nvlan = *ss; - break; - case CDP_APPLIANCE_VLAN_TLV: - t = (const uchar *)ss; - while (tlen > 0) { - if (tlen < 3) - goto pkt_short; + case CDP_DEVICE_ID_TLV: + break; + case CDP_ADDRESS_TLV: + break; + case CDP_PORT_ID_TLV: + break; + case CDP_CAPABILITIES_TLV: + break; + case CDP_VERSION_TLV: + break; + case CDP_PLATFORM_TLV: + break; + case CDP_NATIVE_VLAN_TLV: + nvlan = *ss; + break; + case CDP_APPLIANCE_VLAN_TLV: + t = (const uchar *)ss; + while (tlen > 0) { + if (tlen < 3) + goto pkt_short; - applid = t[0]; - ss = (const ushort *)(t + 1); + applid = t[0]; + ss = (const ushort *)(t + 1); #ifdef CONFIG_CDP_APPLIANCE_VLAN_TYPE - if (applid == - CONFIG_CDP_APPLIANCE_VLAN_TYPE) - vlan = *ss; + if (applid == CONFIG_CDP_APPLIANCE_VLAN_TYPE) + vlan = *ss; #else - /* XXX will this work; dunno */ - vlan = ntohs(*ss); + /* XXX will this work; dunno */ + vlan = ntohs(*ss); #endif - t += 3; tlen -= 3; - } - break; - case CDP_TRIGGER_TLV: - break; - case CDP_POWER_CONSUMPTION_TLV: - break; - case CDP_SYSNAME_TLV: - break; - case CDP_SYSOBJECT_TLV: - break; - case CDP_MANAGEMENT_ADDRESS_TLV: - break; + t += 3; tlen -= 3; + } + break; + case CDP_TRIGGER_TLV: + break; + case CDP_POWER_CONSUMPTION_TLV: + break; + case CDP_SYSNAME_TLV: + break; + case CDP_SYSOBJECT_TLV: + break; + case CDP_MANAGEMENT_ADDRESS_TLV: + break; } } @@ -1167,9 +1191,7 @@ CDPHandler(const uchar * pkt, unsigned len) static void CDPStart(void) { -#if defined(CONFIG_NET_MULTI) printf("Using %s device\n", eth_get_name()); -#endif CDPSeq = 0; CDPOK = 0; @@ -1355,8 +1377,70 @@ static inline IP_t *NetDefragment(IP_t *ip, int *lenp) } #endif +/** + * Receive an ICMP packet. We deal with REDIRECT and PING here, and silently + * drop others. + * + * @parma ip IP packet containing the ICMP + */ +static void receive_icmp(IP_t *ip, int len, IPaddr_t src_ip, Ethernet_t *et) +{ + ICMP_t *icmph = (ICMP_t *)&ip->udp_src; + + switch (icmph->type) { + case ICMP_REDIRECT: + if (icmph->code != ICMP_REDIR_HOST) + return; + printf(" ICMP Host Redirect to %pI4 ", + &icmph->un.gateway); + break; +#if defined(CONFIG_CMD_PING) + case ICMP_ECHO_REPLY: + /* + * IP header OK. Pass the packet to the + * current handler. + */ + /* + * XXX point to ip packet - should this use + * packet_icmp_handler? + */ + (*packetHandler)((uchar *)ip, 0, src_ip, 0, 0); + break; + case ICMP_ECHO_REQUEST: + debug("Got ICMP ECHO REQUEST, return %d bytes\n", + ETHER_HDR_SIZE + len); + + memcpy(&et->et_dest[0], &et->et_src[0], 6); + memcpy(&et->et_src[0], NetOurEther, 6); + + ip->ip_sum = 0; + ip->ip_off = 0; + NetCopyIP((void *)&ip->ip_dst, &ip->ip_src); + NetCopyIP((void *)&ip->ip_src, &NetOurIP); + ip->ip_sum = ~NetCksum((uchar *)ip, + IP_HDR_SIZE_NO_UDP >> 1); + + icmph->type = ICMP_ECHO_REPLY; + icmph->checksum = 0; + icmph->checksum = ~NetCksum((uchar *)icmph, + (len - IP_HDR_SIZE_NO_UDP) >> 1); + (void) eth_send((uchar *)et, + ETHER_HDR_SIZE + len); + break; +#endif + default: +#ifdef CONFIG_CMD_TFTPPUT + if (packet_icmp_handler) + packet_icmp_handler(icmph->type, icmph->code, + ntohs(ip->udp_dst), src_ip, ntohs(ip->udp_src), + icmph->un.data, ntohs(ip->udp_len)); +#endif + break; + } +} + void -NetReceive(volatile uchar * inpkt, int len) +NetReceive(volatile uchar *inpkt, int len) { Ethernet_t *et; IP_t *ip; @@ -1477,26 +1561,20 @@ NetReceive(volatile uchar * inpkt, int len) printf("bad length %d < %d\n", len, ARP_HDR_SIZE); return; } - if (ntohs(arp->ar_hrd) != ARP_ETHER) { + if (ntohs(arp->ar_hrd) != ARP_ETHER) return; - } - if (ntohs(arp->ar_pro) != PROT_IP) { + if (ntohs(arp->ar_pro) != PROT_IP) return; - } - if (arp->ar_hln != 6) { + if (arp->ar_hln != 6) return; - } - if (arp->ar_pln != 4) { + if (arp->ar_pln != 4) return; - } - if (NetOurIP == 0) { + if (NetOurIP == 0) return; - } - if (NetReadIP(&arp->ar_data[16]) != NetOurIP) { + if (NetReadIP(&arp->ar_data[16]) != NetOurIP) return; - } switch (ntohs(arp->ar_op)) { case ARPOP_REQUEST: @@ -1601,13 +1679,11 @@ NetReceive(volatile uchar * inpkt, int len) debug("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff); /* Can't deal with anything except IPv4 */ - if ((ip->ip_hl_v & 0xf0) != 0x40) { + if ((ip->ip_hl_v & 0xf0) != 0x40) return; - } /* Can't deal with IP options (headers != 20 bytes) */ - if ((ip->ip_hl_v & 0x0f) > 0x05) { + if ((ip->ip_hl_v & 0x0f) > 0x05) return; - } /* Check the Checksum of the header */ if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2)) { puts("checksum bad\n"); @@ -1619,7 +1695,7 @@ NetReceive(volatile uchar * inpkt, int len) #ifdef CONFIG_MCAST_TFTP if (Mcast_addr != tmp) #endif - return; + return; } /* Read source IP address for later use */ src_ip = NetReadIP(&ip->ip_src); @@ -1628,7 +1704,8 @@ NetReceive(volatile uchar * inpkt, int len) * a fragment, and either the complete packet or NULL if * it is a fragment (if !CONFIG_IP_DEFRAG, it returns NULL) */ - if (!(ip = NetDefragment(ip, &len))) + ip = NetDefragment(ip, &len); + if (!ip) return; /* * watch for ICMP host redirects @@ -1646,51 +1723,14 @@ NetReceive(volatile uchar * inpkt, int len) * subnet. So this is probably a warning that your * configuration might be wrong. But I'm not really * sure if there aren't any other situations. + * + * Simon Glass : We get an ICMP when + * we send a tftp packet to a dead connection, or when + * there is no server at the other end. */ if (ip->ip_p == IPPROTO_ICMP) { - ICMP_t *icmph = (ICMP_t *)&(ip->udp_src); - - switch (icmph->type) { - case ICMP_REDIRECT: - if (icmph->code != ICMP_REDIR_HOST) - return; - printf(" ICMP Host Redirect to %pI4 ", - &icmph->un.gateway); - return; -#if defined(CONFIG_CMD_PING) - case ICMP_ECHO_REPLY: - /* - * IP header OK. Pass the packet to the - * current handler. - */ - /* XXX point to ip packet */ - (*packetHandler)((uchar *)ip, 0, src_ip, 0, 0); - return; - case ICMP_ECHO_REQUEST: - debug("Got ICMP ECHO REQUEST, return %d bytes\n", - ETHER_HDR_SIZE + len); - - memcpy(&et->et_dest[0], &et->et_src[0], 6); - memcpy(&et->et_src[0], NetOurEther, 6); - - ip->ip_sum = 0; - ip->ip_off = 0; - NetCopyIP((void*)&ip->ip_dst, &ip->ip_src); - NetCopyIP((void*)&ip->ip_src, &NetOurIP); - ip->ip_sum = ~NetCksum((uchar *)ip, - IP_HDR_SIZE_NO_UDP >> 1); - - icmph->type = ICMP_ECHO_REPLY; - icmph->checksum = 0; - icmph->checksum = ~NetCksum((uchar *)icmph, - (len - IP_HDR_SIZE_NO_UDP) >> 1); - (void) eth_send((uchar *)et, - ETHER_HDR_SIZE + len); - return; -#endif - default: - return; - } + receive_icmp(ip, len, src_ip, et); + return; } else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */ return; } @@ -1759,7 +1799,7 @@ NetReceive(volatile uchar * inpkt, int len) /**********************************************************************/ -static int net_check_prereq(proto_t protocol) +static int net_check_prereq(enum proto_t protocol) { switch (protocol) { /* Fall through */ @@ -1767,7 +1807,7 @@ static int net_check_prereq(proto_t protocol) case PING: if (NetPingIP == 0) { puts("*** ERROR: ping address not given\n"); - return (1); + return 1; } goto common; #endif @@ -1775,7 +1815,7 @@ static int net_check_prereq(proto_t protocol) case SNTP: if (NetNtpServerIP == 0) { puts("*** ERROR: NTP server address not given\n"); - return (1); + return 1; } goto common; #endif @@ -1790,10 +1830,11 @@ static int net_check_prereq(proto_t protocol) #if defined(CONFIG_CMD_NFS) case NFS: #endif - case TFTP: + case TFTPGET: + case TFTPPUT: if (NetServerIP == 0) { puts("*** ERROR: `serverip' not set\n"); - return (1); + return 1; } #if defined(CONFIG_CMD_PING) || defined(CONFIG_CMD_SNTP) || \ defined(CONFIG_CMD_DNS) @@ -1802,9 +1843,10 @@ common: /* Fall through */ case NETCONS: + case TFTPSRV: if (NetOurIP == 0) { puts("*** ERROR: `ipaddr' not set\n"); - return (1); + return 1; } /* Fall through */ @@ -1815,14 +1857,13 @@ common: case CDP: case DHCP: if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) { -#ifdef CONFIG_NET_MULTI extern int eth_get_dev_index(void); int num = eth_get_dev_index(); switch (num) { case -1: puts("*** ERROR: No ethernet found.\n"); - return (1); + return 1; case 0: puts("*** ERROR: `ethaddr' not set\n"); break; @@ -1833,29 +1874,25 @@ common: } NetStartAgain(); - return (2); -#else - puts("*** ERROR: `ethaddr' not set\n"); - return (1); -#endif + return 2; } /* Fall through */ default: - return (0); + return 0; } - return (0); /* OK */ + return 0; /* OK */ } /**********************************************************************/ int -NetCksumOk(uchar * ptr, int len) +NetCksumOk(uchar *ptr, int len) { return !((NetCksum(ptr, len) + 1) & 0xfffe); } unsigned -NetCksum(uchar * ptr, int len) +NetCksum(uchar *ptr, int len) { ulong xsum; ushort *p = (ushort *)ptr; @@ -1865,7 +1902,7 @@ NetCksum(uchar * ptr, int len) xsum += *p++; xsum = (xsum & 0xffff) + (xsum >> 16); xsum = (xsum & 0xffff) + (xsum >> 16); - return (xsum & 0xffff); + return xsum & 0xffff; } int @@ -1882,7 +1919,7 @@ NetEthHdrSize(void) } int -NetSetEther(volatile uchar * xet, uchar * addr, uint prot) +NetSetEther(volatile uchar *xet, uchar * addr, uint prot) { Ethernet_t *et = (Ethernet_t *)xet; ushort myvlanid; @@ -1894,7 +1931,7 @@ NetSetEther(volatile uchar * xet, uchar * addr, uint prot) memcpy(et->et_dest, addr, 6); memcpy(et->et_src, NetOurEther, 6); if ((myvlanid & VLAN_IDMASK) == VLAN_NONE) { - et->et_protlen = htons(prot); + et->et_protlen = htons(prot); return ETHER_HDR_SIZE; } else { VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)xet; @@ -1907,7 +1944,7 @@ NetSetEther(volatile uchar * xet, uchar * addr, uint prot) } void -NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len) +NetSetIP(volatile uchar *xip, IPaddr_t dest, int dport, int sport, int len) { IP_t *ip = (IP_t *)xip; @@ -1933,9 +1970,9 @@ NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len) ip->ip_p = 17; /* UDP */ ip->ip_sum = 0; /* already in network byte order */ - NetCopyIP((void*)&ip->ip_src, &NetOurIP); + NetCopyIP((void *)&ip->ip_src, &NetOurIP); /* - "" - */ - NetCopyIP((void*)&ip->ip_dst, &dest); + NetCopyIP((void *)&ip->ip_dst, &dest); ip->udp_src = htons(sport); ip->udp_dst = htons(dport); ip->udp_len = htons(8 + len); @@ -1950,9 +1987,8 @@ void copy_filename(char *dst, const char *src, int size) --size; } - while ((--size > 0) && *src && (*src != '"')) { + while ((--size > 0) && *src && (*src != '"')) *dst++ = *src++; - } *dst = '\0'; } @@ -2010,5 +2046,5 @@ ushort string_to_VLAN(const char *s) ushort getenv_VLAN(char *var) { - return (string_to_VLAN(getenv(var))); + return string_to_VLAN(getenv(var)); }