2 * Copied from Linux Monitor (LiMon) - Networking.
4 * Copyright 1994 - 2000 Neil Russell.
6 * Copyright 2000 Roland Borde
7 * Copyright 2000 Paolo Scaffardi
8 * Copyright 2000-2002 Wolfgang Denk, wd@denx.de
14 * The user interface supports commands for BOOTP, RARP, and TFTP.
15 * Also, we support ARP internally. Depending on available data,
16 * these interact as follows:
20 * Prerequisites: - own ethernet address
21 * We want: - own IP address
22 * - TFTP server IP address
28 * Prerequisites: - own ethernet address
29 * We want: - own IP address
30 * - TFTP server IP address
35 * Prerequisites: - own ethernet address
37 * - TFTP server IP address
38 * We want: - TFTP server ethernet address
43 * Prerequisites: - own ethernet address
44 * We want: - IP, Netmask, ServerIP, Gateway IP
45 * - bootfilename, lease time
50 * Prerequisites: - own ethernet address
52 * - TFTP server IP address
53 * - TFTP server ethernet address
54 * - name of bootfile (if unknown, we use a default name
55 * derived from our own IP address)
56 * We want: - load the boot file
69 #if (CONFIG_COMMANDS & CFG_CMD_NET)
71 #define ARP_TIMEOUT 5 /* Seconds before trying ARP again */
72 #ifndef CONFIG_NET_RETRY_COUNT
73 # define ARP_TIMEOUT_COUNT 5 /* # of timeouts before giving up */
75 # define ARP_TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
82 /** BOOTP EXTENTIONS **/
84 IPaddr_t NetOurSubnetMask=0; /* Our subnet mask (0=unknown) */
85 IPaddr_t NetOurGatewayIP=0; /* Our gateways IP address */
86 IPaddr_t NetOurDNSIP=0; /* Our DNS IP address */
87 char NetOurNISDomain[32]={0,}; /* Our NIS domain */
88 char NetOurHostName[32]={0,}; /* Our hostname */
89 char NetOurRootPath[64]={0,}; /* Our bootpath */
90 ushort NetBootFileSize=0; /* Our bootfile size in blocks */
92 /** END OF BOOTP EXTENTIONS **/
94 ulong NetBootFileXferSize; /* The actual transferred size of the bootfile (in bytes) */
95 uchar NetOurEther[6]; /* Our ethernet address */
96 uchar NetServerEther[6] = /* Boot server enet address */
98 IPaddr_t NetOurIP; /* Our IP addr (0 = unknown) */
99 IPaddr_t NetServerIP; /* Our IP addr (0 = unknown) */
100 volatile uchar *NetRxPkt; /* Current receive packet */
101 int NetRxPktLen; /* Current rx packet length */
102 unsigned NetIPID; /* IP packet ID */
103 uchar NetBcastAddr[6] = /* Ethernet bcast address */
104 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
105 uchar NetEtherNullAddr[6] =
106 { 0, 0, 0, 0, 0, 0 };
107 int NetState; /* Network loop state */
108 #ifdef CONFIG_NET_MULTI
109 int NetRestartWrap = 0; /* Tried all network devices */
110 static int NetRestarted = 0; /* Network loop restarted */
111 static int NetDevExists = 0; /* At least one device configured */
114 char BootFile[128]; /* Boot File name */
116 #if (CONFIG_COMMANDS & CFG_CMD_PING)
117 IPaddr_t NetPingIP; /* the ip address to ping */
119 static void PingStart(void);
122 volatile uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
124 volatile uchar *NetRxPackets[PKTBUFSRX]; /* Receive packets */
126 static rxhand_f *packetHandler; /* Current RX packet handler */
127 static thand_f *timeHandler; /* Current timeout handler */
128 static ulong timeValue; /* Current timeout value */
129 volatile uchar *NetTxPacket = 0; /* THE transmit packet */
131 static int net_check_prereq (proto_t protocol);
133 /**********************************************************************/
135 IPaddr_t NetArpWaitPacketIP;
136 IPaddr_t NetArpWaitReplyIP;
137 uchar *NetArpWaitPacketMAC; /* MAC address of waiting packet's destination */
138 uchar *NetArpWaitTxPacket; /* THE transmit packet */
139 int NetArpWaitTxPacketSize;
140 uchar NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
141 ulong NetArpWaitTimerStart;
144 void ArpRequest(void)
151 printf("ARP broadcast %d\n", NetArpWaitTry);
155 NetSetEther(pkt, NetBcastAddr, PROT_ARP);
156 pkt += ETHER_HDR_SIZE;
160 arp->ar_hrd = htons(ARP_ETHER);
161 arp->ar_pro = htons(PROT_IP);
164 arp->ar_op = htons(ARPOP_REQUEST);
166 memcpy (&arp->ar_data[0], NetOurEther, 6); /* source ET addr */
167 NetWriteIP((uchar*)&arp->ar_data[6], NetOurIP); /* source IP addr */
168 for (i=10; i<16; ++i) {
169 arp->ar_data[i] = 0; /* dest ET addr = 0 */
172 if((NetArpWaitPacketIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) {
173 if (NetOurGatewayIP == 0) {
174 puts ("## Warning: gatewayip needed but not set\n");
176 NetArpWaitReplyIP = NetOurGatewayIP;
178 NetArpWaitReplyIP = NetArpWaitPacketIP;
180 NetWriteIP((uchar*)&arp->ar_data[16], NetArpWaitReplyIP);
181 (void) eth_send(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
184 void ArpTimeoutCheck(void)
188 if (!NetArpWaitPacketIP)
193 /* check for arp timeout */
194 if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT * CFG_HZ) {
197 if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) {
198 puts ("\nARP Retry count exceeded; starting again\n");
202 NetArpWaitTimerStart = t;
208 /**********************************************************************/
210 * Main network processing loop.
214 NetLoop(proto_t protocol)
216 DECLARE_GLOBAL_DATA_PTR;
220 #ifdef CONFIG_NET_MULTI
225 /* XXX problem with bss workaround */
226 NetArpWaitPacketMAC = NULL;
227 NetArpWaitTxPacket = NULL;
228 NetArpWaitPacketIP = 0;
229 NetArpWaitReplyIP = 0;
230 NetArpWaitTxPacket = NULL;
237 * Setup packet buffers, aligned correctly.
239 NetTxPacket = &PktBuf[0] + (PKTALIGN - 1);
240 NetTxPacket -= (ulong)NetTxPacket % PKTALIGN;
241 for (i = 0; i < PKTBUFSRX; i++) {
242 NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN;
247 if (!NetArpWaitTxPacket) {
248 NetArpWaitTxPacket = &NetArpWaitPacketBuf[0] + (PKTALIGN - 1);
249 NetArpWaitTxPacket -= (ulong)NetArpWaitTxPacket % PKTALIGN;
250 NetArpWaitTxPacketSize = 0;
258 #ifdef CONFIG_NET_MULTI
259 memcpy (NetOurEther, eth_get_dev()->enetaddr, 6);
261 memcpy (NetOurEther, bd->bi_enetaddr, 6);
264 NetState = NETLOOP_CONTINUE;
267 * Start the ball rolling with the given start function. From
268 * here on, this code is a state machine driven by received
269 * packets and timer events.
273 #if (CONFIG_COMMANDS & CFG_CMD_PING)
277 NetCopyIP(&NetOurIP, &bd->bi_ip_addr);
278 NetOurGatewayIP = getenv_IPaddr ("gatewayip");
279 NetOurSubnetMask= getenv_IPaddr ("netmask");
283 NetServerIP = getenv_IPaddr ("serverip");
285 #if (CONFIG_COMMANDS & CFG_CMD_PING)
298 * initialize our IP addr to 0 in order to accept ANY
299 * IP addr assigned to us by the BOOTP / RARP server
308 switch (net_check_prereq (protocol)) {
310 /* network not configured */
313 #ifdef CONFIG_NET_MULTI
315 /* network device not configured */
317 #endif /* CONFIG_NET_MULTI */
320 #ifdef CONFIG_NET_MULTI
325 /* always use ARP to get server ethernet address */
329 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
331 /* Start with a clean slate... */
334 DhcpRequest(); /* Basically same as BOOTP */
336 #endif /* CFG_CMD_DHCP */
347 #if (CONFIG_COMMANDS & CFG_CMD_PING)
356 NetBootFileXferSize = 0;
362 * Main packet reception loop. Loop receiving packets until
363 * someone sets `NetQuit'.
367 #ifdef CONFIG_SHOW_ACTIVITY
369 extern void show_activity(int arg);
374 * Check the ethernet for a new packet. The ethernet
375 * receive routine will process it.
380 * Abort if ctrl-c was pressed.
391 * Check for a timeout, and run the timeout handler
394 if (timeHandler && (get_timer(0) > timeValue)) {
398 timeHandler = (thand_f *)0;
405 case NETLOOP_RESTART:
406 #ifdef CONFIG_NET_MULTI
411 case NETLOOP_SUCCESS:
412 if (NetBootFileXferSize > 0) {
414 printf("Bytes transferred = %ld (%lx hex)\n",
416 NetBootFileXferSize);
417 sprintf(buf, "%lx", NetBootFileXferSize);
418 setenv("filesize", buf);
421 return NetBootFileXferSize;
429 /**********************************************************************/
432 startAgainTimeout(void)
434 NetState = NETLOOP_RESTART;
438 startAgainHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
440 /* Totally ignore the packet */
446 #ifndef CONFIG_NET_MULTI
447 NetSetTimeout(10 * CFG_HZ, startAgainTimeout);
448 NetSetHandler(startAgainHandler);
450 DECLARE_GLOBAL_DATA_PTR;
453 eth_try_another(!NetRestarted);
460 NetSetTimeout(10 * CFG_HZ, startAgainTimeout);
461 NetSetHandler(startAgainHandler);
465 NetState = NETLOOP_FAIL;
470 NetState = NETLOOP_RESTART;
475 /**********************************************************************/
481 NetSetHandler(rxhand_f * f)
488 NetSetTimeout(int iv, thand_f * f)
491 timeHandler = (thand_f *)0;
494 timeValue = get_timer(0) + iv;
500 NetSendPacket(volatile uchar * pkt, int len)
502 (void) eth_send(pkt, len);
506 NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
508 /* convert to new style broadcast */
512 /* if broadcast, make the ether address a broadcast and don't do ARP */
513 if (dest == 0xFFFFFFFF)
514 ether = NetBcastAddr;
516 /* if MAC address was not discovered yet, save the packet and do an ARP request */
517 if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
520 printf("sending ARP for %08lx\n", dest);
523 NetArpWaitPacketIP = dest;
524 NetArpWaitPacketMAC = ether;
525 NetSetEther (NetArpWaitTxPacket, NetArpWaitPacketMAC, PROT_IP);
526 NetSetIP (NetArpWaitTxPacket + ETHER_HDR_SIZE, dest, dport, sport, len);
527 memcpy(NetArpWaitTxPacket + ETHER_HDR_SIZE + IP_HDR_SIZE,
528 (uchar *)NetTxPacket + ETHER_HDR_SIZE + IP_HDR_SIZE, len);
530 /* size of the waiting packet */
531 NetArpWaitTxPacketSize = ETHER_HDR_SIZE + IP_HDR_SIZE + len;
533 /* and do the ARP request */
535 NetArpWaitTimerStart = get_timer(0);
537 return 1; /* waiting */
541 printf("sending UDP to %08lx/%02x:%02x:%02x:%02x:%02x:%02x\n",
542 dest, ether[0], ether[1], ether[2], ether[3], ether[4], ether[5]);
545 NetSetEther (NetTxPacket, ether, PROT_IP);
546 NetSetIP (NetTxPacket + ETHER_HDR_SIZE, dest, dport, sport, len);
547 (void) eth_send(NetTxPacket, ETHER_HDR_SIZE + IP_HDR_SIZE + len);
549 return 0; /* transmited */
552 #if (CONFIG_COMMANDS & CFG_CMD_PING)
553 static ushort PingSeqNo;
561 /* XXX always send arp request */
563 memcpy(mac, NetEtherNullAddr, 6);
566 printf("sending ARP for %08lx\n", NetPingIP);
569 NetArpWaitPacketIP = NetPingIP;
570 NetArpWaitPacketMAC = mac;
572 NetSetEther(NetArpWaitTxPacket, mac, PROT_IP);
574 ip = (volatile IP_t *)(NetArpWaitTxPacket + ETHER_HDR_SIZE);
577 * Construct an IP and ICMP header. (need to set no fragment bit - XXX)
579 ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */
581 ip->ip_len = htons(IP_HDR_SIZE_NO_UDP + 8);
582 ip->ip_id = htons(NetIPID++);
583 ip->ip_off = htons(0x4000); /* No fragmentation */
585 ip->ip_p = 0x01; /* ICMP */
587 NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */
588 NetCopyIP((void*)&ip->ip_dst, &NetPingIP); /* - "" - */
589 ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
591 s = &ip->udp_src; /* XXX ICMP starts here */
592 s[0] = htons(0x0800); /* echo-request, code */
593 s[1] = 0; /* checksum */
594 s[2] = 0; /* identifier */
595 s[3] = htons(PingSeqNo++); /* sequence number */
596 s[1] = ~NetCksum((uchar *)s, 8/2);
598 /* size of the waiting packet */
599 NetArpWaitTxPacketSize = ETHER_HDR_SIZE + IP_HDR_SIZE_NO_UDP + 8;
601 /* and do the ARP request */
603 NetArpWaitTimerStart = get_timer(0);
605 return 1; /* waiting */
612 NetState = NETLOOP_FAIL; /* we did not get the reply */
616 PingHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
619 volatile IP_t *ip = (volatile IP_t *)pkt;
621 tmp = NetReadIP((void *)&ip->ip_src);
622 if (tmp != NetPingIP)
625 NetState = NETLOOP_SUCCESS;
628 static void PingStart(void)
630 NetSetTimeout (10 * CFG_HZ, PingTimeout);
631 NetSetHandler (PingHandler);
639 NetReceive(volatile uchar * pkt, int len)
649 et = (Ethernet_t *)pkt;
651 x = ntohs(et->et_protlen);
655 * Got a 802 packet. Check the other protocol field.
657 x = ntohs(et->et_prot);
658 ip = (IP_t *)(pkt + E802_HDR_SIZE);
659 len -= E802_HDR_SIZE;
661 ip = (IP_t *)(pkt + ETHER_HDR_SIZE);
662 len -= ETHER_HDR_SIZE;
666 printf("Receive from protocol 0x%x\n", x);
673 * We have to deal with two types of ARP packets:
674 * - REQUEST packets will be answered by sending our
675 * IP address - if we know it.
676 * - REPLY packates are expected only after we asked
677 * for the TFTP server's or the gateway's ethernet
678 * address; so if we receive such a packet, we set
679 * the server ethernet address
685 if (len < ARP_HDR_SIZE) {
686 printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
689 if (ntohs(arp->ar_hrd) != ARP_ETHER) {
692 if (ntohs(arp->ar_pro) != PROT_IP) {
695 if (arp->ar_hln != 6) {
698 if (arp->ar_pln != 4) {
706 if (NetReadIP(&arp->ar_data[16]) != NetOurIP) {
710 switch (ntohs(arp->ar_op)) {
711 case ARPOP_REQUEST: /* reply with our IP address */
713 printf("Got ARP REQUEST, return our IP\n");
715 NetSetEther((uchar *)et, et->et_src, PROT_ARP);
716 arp->ar_op = htons(ARPOP_REPLY);
717 memcpy (&arp->ar_data[10], &arp->ar_data[0], 6);
718 NetCopyIP(&arp->ar_data[16], &arp->ar_data[6]);
719 memcpy (&arp->ar_data[ 0], NetOurEther, 6);
720 NetCopyIP(&arp->ar_data[ 6], &NetOurIP);
721 (void) eth_send((uchar *)et, ((uchar *)arp-pkt) + ARP_HDR_SIZE);
724 case ARPOP_REPLY: /* arp reply */
725 /* are we waiting for a reply */
726 if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
729 printf("Got ARP REPLY, set server/gtwy eth addr (%02x:%02x:%02x:%02x:%02x:%02x)\n",
730 arp->ar_data[0], arp->ar_data[1],
731 arp->ar_data[2], arp->ar_data[3],
732 arp->ar_data[4], arp->ar_data[5]);
735 tmp = NetReadIP(&arp->ar_data[6]);
737 /* matched waiting packet's address */
738 if (tmp == NetArpWaitReplyIP) {
742 /* save address for later use */
743 memcpy(NetArpWaitPacketMAC, &arp->ar_data[0], 6);
745 /* modify header, and transmit it */
746 memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, NetArpWaitPacketMAC, 6);
747 (void) eth_send(NetArpWaitTxPacket, NetArpWaitTxPacketSize);
749 /* no arp request pending now */
750 NetArpWaitPacketIP = 0;
751 NetArpWaitTxPacketSize = 0;
752 NetArpWaitPacketMAC = NULL;
758 printf("Unexpected ARP opcode 0x%x\n", ntohs(arp->ar_op));
765 printf("Got RARP\n");
768 if (len < ARP_HDR_SIZE) {
769 printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
773 if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
774 (ntohs(arp->ar_hrd) != ARP_ETHER) ||
775 (ntohs(arp->ar_pro) != PROT_IP) ||
776 (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
778 printf("invalid RARP header\n");
780 NetCopyIP(&NetOurIP, &arp->ar_data[16]);
781 NetCopyIP(&NetServerIP, &arp->ar_data[ 6]);
782 memcpy (NetServerEther, &arp->ar_data[ 0], 6);
784 (*packetHandler)(0,0,0,0);
792 if (len < IP_HDR_SIZE) {
793 debug ("len bad %d < %d\n", len, IP_HDR_SIZE);
796 if (len < ntohs(ip->ip_len)) {
797 printf("len bad %d < %d\n", len, ntohs(ip->ip_len));
800 len = ntohs(ip->ip_len);
802 printf("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff);
804 if ((ip->ip_hl_v & 0xf0) != 0x40) {
807 if (ip->ip_off & htons(0x1fff)) { /* Can't deal w/ fragments */
810 if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2)) {
811 printf("checksum bad\n");
814 tmp = NetReadIP(&ip->ip_dst);
815 if (NetOurIP && tmp != NetOurIP && tmp != 0xFFFFFFFF) {
819 * watch for ICMP host redirects
821 * There is no real handler code (yet). We just watch
822 * for ICMP host redirect messages. In case anybody
823 * sees these messages: please contact me
824 * (wd@denx.de), or - even better - send me the
825 * necessary fixes :-)
827 * Note: in all cases where I have seen this so far
828 * it was a problem with the router configuration,
829 * for instance when a router was configured in the
830 * BOOTP reply, but the TFTP server was on the same
831 * subnet. So this is probably a warning that your
832 * configuration might be wrong. But I'm not really
833 * sure if there aren't any other situations.
835 if (ip->ip_p == IPPROTO_ICMP) {
836 ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);
838 switch (icmph->type) {
840 if (icmph->code != ICMP_REDIR_HOST)
842 puts (" ICMP Host Redirect to ");
843 print_IPaddr(icmph->un.gateway);
846 #if (CONFIG_COMMANDS & CFG_CMD_PING)
847 case ICMP_ECHO_REPLY:
849 * IP header OK. Pass the packet to the current handler.
851 /* XXX point to ip packet */
852 (*packetHandler)((uchar *)ip, 0, 0, 0);
858 } else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */
863 * IP header OK. Pass the packet to the current handler.
865 (*packetHandler)((uchar *)ip +IP_HDR_SIZE,
868 ntohs(ip->udp_len) - 8);
875 /**********************************************************************/
877 static int net_check_prereq (proto_t protocol)
881 #if (CONFIG_COMMANDS & CFG_CMD_PING)
883 if (NetPingIP == 0) {
884 puts ("*** ERROR: ping address not given\n");
890 if (NetServerIP == 0) {
891 puts ("*** ERROR: `serverip' not set\n");
895 #if (CONFIG_COMMANDS & CFG_CMD_PING)
900 puts ("*** ERROR: `ipaddr' not set\n");
908 if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
909 #ifdef CONFIG_NET_MULTI
910 extern int eth_get_dev_index (void);
911 int num = eth_get_dev_index();
915 puts ("*** ERROR: No ethernet found.\n");
918 puts ("*** ERROR: `ethaddr' not set\n");
921 printf ("*** ERROR: `eth%daddr' not set\n",
929 puts ("*** ERROR: `ethaddr' not set\n");
939 /**********************************************************************/
942 NetCksumOk(uchar * ptr, int len)
944 return !((NetCksum(ptr, len) + 1) & 0xfffe);
949 NetCksum(uchar * ptr, int len)
955 xsum += *((ushort *)ptr)++;
956 xsum = (xsum & 0xffff) + (xsum >> 16);
957 xsum = (xsum & 0xffff) + (xsum >> 16);
958 return (xsum & 0xffff);
963 NetSetEther(volatile uchar * xet, uchar * addr, uint prot)
965 Ethernet_t *et = (Ethernet_t *)xet;
967 memcpy (et->et_dest, addr, 6);
968 memcpy (et->et_src, NetOurEther, 6);
969 et->et_protlen = htons(prot);
974 NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len)
976 volatile IP_t *ip = (IP_t *)xip;
979 * If the data is an odd number of bytes, zero the
980 * byte after the last byte so that the checksum
984 xip[IP_HDR_SIZE + len] = 0;
987 * Construct an IP and UDP header.
988 (need to set no fragment bit - XXX)
990 ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */
992 ip->ip_len = htons(IP_HDR_SIZE + len);
993 ip->ip_id = htons(NetIPID++);
994 ip->ip_off = htons(0x4000); /* No fragmentation */
996 ip->ip_p = 17; /* UDP */
998 NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */
999 NetCopyIP((void*)&ip->ip_dst, &dest); /* - "" - */
1000 ip->udp_src = htons(sport);
1001 ip->udp_dst = htons(dport);
1002 ip->udp_len = htons(8 + len);
1004 ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
1007 void copy_filename (uchar *dst, uchar *src, int size)
1009 if (*src && (*src == '"')) {
1014 while ((--size > 0) && *src && (*src != '"')) {
1020 #endif /* CFG_CMD_NET */
1022 void ip_to_string (IPaddr_t x, char *s)
1025 sprintf (s,"%d.%d.%d.%d",
1026 (int)((x >> 24) & 0xff),
1027 (int)((x >> 16) & 0xff),
1028 (int)((x >> 8) & 0xff),
1029 (int)((x >> 0) & 0xff)
1033 IPaddr_t string_to_ip(char *s)
1042 for (addr=0, i=0; i<4; ++i) {
1043 ulong val = s ? simple_strtoul(s, &e, 10) : 0;
1045 addr |= (val & 0xFF);
1051 return (htonl(addr));
1054 void print_IPaddr (IPaddr_t x)
1058 ip_to_string(x, tmp);
1063 IPaddr_t getenv_IPaddr (char *var)
1065 return (string_to_ip(getenv(var)));