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 timeStart; /* Time base value */
129 static ulong timeDelta; /* Current timeout value */
130 volatile uchar *NetTxPacket = 0; /* THE transmit packet */
132 static int net_check_prereq (proto_t protocol);
134 /**********************************************************************/
136 IPaddr_t NetArpWaitPacketIP;
137 IPaddr_t NetArpWaitReplyIP;
138 uchar *NetArpWaitPacketMAC; /* MAC address of waiting packet's destination */
139 uchar *NetArpWaitTxPacket; /* THE transmit packet */
140 int NetArpWaitTxPacketSize;
141 uchar NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
142 ulong NetArpWaitTimerStart;
145 void ArpRequest(void)
152 printf("ARP broadcast %d\n", NetArpWaitTry);
156 NetSetEther(pkt, NetBcastAddr, PROT_ARP);
157 pkt += ETHER_HDR_SIZE;
161 arp->ar_hrd = htons(ARP_ETHER);
162 arp->ar_pro = htons(PROT_IP);
165 arp->ar_op = htons(ARPOP_REQUEST);
167 memcpy (&arp->ar_data[0], NetOurEther, 6); /* source ET addr */
168 NetWriteIP((uchar*)&arp->ar_data[6], NetOurIP); /* source IP addr */
169 for (i=10; i<16; ++i) {
170 arp->ar_data[i] = 0; /* dest ET addr = 0 */
173 if((NetArpWaitPacketIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) {
174 if (NetOurGatewayIP == 0) {
175 puts ("## Warning: gatewayip needed but not set\n");
177 NetArpWaitReplyIP = NetOurGatewayIP;
179 NetArpWaitReplyIP = NetArpWaitPacketIP;
181 NetWriteIP((uchar*)&arp->ar_data[16], NetArpWaitReplyIP);
182 (void) eth_send(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
185 void ArpTimeoutCheck(void)
189 if (!NetArpWaitPacketIP)
194 /* check for arp timeout */
195 if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT * CFG_HZ) {
198 if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) {
199 puts ("\nARP Retry count exceeded; starting again\n");
203 NetArpWaitTimerStart = t;
209 /**********************************************************************/
211 * Main network processing loop.
215 NetLoop(proto_t protocol)
217 DECLARE_GLOBAL_DATA_PTR;
221 #ifdef CONFIG_NET_MULTI
226 /* XXX problem with bss workaround */
227 NetArpWaitPacketMAC = NULL;
228 NetArpWaitTxPacket = NULL;
229 NetArpWaitPacketIP = 0;
230 NetArpWaitReplyIP = 0;
231 NetArpWaitTxPacket = NULL;
238 * Setup packet buffers, aligned correctly.
240 NetTxPacket = &PktBuf[0] + (PKTALIGN - 1);
241 NetTxPacket -= (ulong)NetTxPacket % PKTALIGN;
242 for (i = 0; i < PKTBUFSRX; i++) {
243 NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN;
248 if (!NetArpWaitTxPacket) {
249 NetArpWaitTxPacket = &NetArpWaitPacketBuf[0] + (PKTALIGN - 1);
250 NetArpWaitTxPacket -= (ulong)NetArpWaitTxPacket % PKTALIGN;
251 NetArpWaitTxPacketSize = 0;
259 #ifdef CONFIG_NET_MULTI
260 memcpy (NetOurEther, eth_get_dev()->enetaddr, 6);
262 memcpy (NetOurEther, bd->bi_enetaddr, 6);
265 NetState = NETLOOP_CONTINUE;
268 * Start the ball rolling with the given start function. From
269 * here on, this code is a state machine driven by received
270 * packets and timer events.
274 #if (CONFIG_COMMANDS & CFG_CMD_PING)
278 NetCopyIP(&NetOurIP, &bd->bi_ip_addr);
279 NetOurGatewayIP = getenv_IPaddr ("gatewayip");
280 NetOurSubnetMask= getenv_IPaddr ("netmask");
284 NetServerIP = getenv_IPaddr ("serverip");
286 #if (CONFIG_COMMANDS & CFG_CMD_PING)
299 * initialize our IP addr to 0 in order to accept ANY
300 * IP addr assigned to us by the BOOTP / RARP server
309 switch (net_check_prereq (protocol)) {
311 /* network not configured */
314 #ifdef CONFIG_NET_MULTI
316 /* network device not configured */
318 #endif /* CONFIG_NET_MULTI */
321 #ifdef CONFIG_NET_MULTI
326 /* always use ARP to get server ethernet address */
330 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
332 /* Start with a clean slate... */
335 DhcpRequest(); /* Basically same as BOOTP */
337 #endif /* CFG_CMD_DHCP */
348 #if (CONFIG_COMMANDS & CFG_CMD_PING)
357 NetBootFileXferSize = 0;
363 * Main packet reception loop. Loop receiving packets until
364 * someone sets `NetQuit'.
368 #ifdef CONFIG_SHOW_ACTIVITY
370 extern void show_activity(int arg);
375 * Check the ethernet for a new packet. The ethernet
376 * receive routine will process it.
381 * Abort if ctrl-c was pressed.
392 * Check for a timeout, and run the timeout handler
395 if (timeHandler && ((get_timer(0) - timeStart) > timeDelta)) {
399 timeHandler = (thand_f *)0;
406 case NETLOOP_RESTART:
407 #ifdef CONFIG_NET_MULTI
412 case NETLOOP_SUCCESS:
413 if (NetBootFileXferSize > 0) {
415 printf("Bytes transferred = %ld (%lx hex)\n",
417 NetBootFileXferSize);
418 sprintf(buf, "%lx", NetBootFileXferSize);
419 setenv("filesize", buf);
422 return NetBootFileXferSize;
430 /**********************************************************************/
433 startAgainTimeout(void)
435 NetState = NETLOOP_RESTART;
439 startAgainHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
441 /* Totally ignore the packet */
447 #ifndef CONFIG_NET_MULTI
448 NetSetTimeout(10 * CFG_HZ, startAgainTimeout);
449 NetSetHandler(startAgainHandler);
451 DECLARE_GLOBAL_DATA_PTR;
454 eth_try_another(!NetRestarted);
461 NetSetTimeout(10 * CFG_HZ, startAgainTimeout);
462 NetSetHandler(startAgainHandler);
466 NetState = NETLOOP_FAIL;
471 NetState = NETLOOP_RESTART;
476 /**********************************************************************/
482 NetSetHandler(rxhand_f * f)
489 NetSetTimeout(int iv, thand_f * f)
492 timeHandler = (thand_f *)0;
495 timeStart = get_timer(0);
502 NetSendPacket(volatile uchar * pkt, int len)
504 (void) eth_send(pkt, len);
508 NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
510 /* convert to new style broadcast */
514 /* if broadcast, make the ether address a broadcast and don't do ARP */
515 if (dest == 0xFFFFFFFF)
516 ether = NetBcastAddr;
518 /* if MAC address was not discovered yet, save the packet and do an ARP request */
519 if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
522 printf("sending ARP for %08lx\n", dest);
525 NetArpWaitPacketIP = dest;
526 NetArpWaitPacketMAC = ether;
527 NetSetEther (NetArpWaitTxPacket, NetArpWaitPacketMAC, PROT_IP);
528 NetSetIP (NetArpWaitTxPacket + ETHER_HDR_SIZE, dest, dport, sport, len);
529 memcpy(NetArpWaitTxPacket + ETHER_HDR_SIZE + IP_HDR_SIZE,
530 (uchar *)NetTxPacket + ETHER_HDR_SIZE + IP_HDR_SIZE, len);
532 /* size of the waiting packet */
533 NetArpWaitTxPacketSize = ETHER_HDR_SIZE + IP_HDR_SIZE + len;
535 /* and do the ARP request */
537 NetArpWaitTimerStart = get_timer(0);
539 return 1; /* waiting */
543 printf("sending UDP to %08lx/%02x:%02x:%02x:%02x:%02x:%02x\n",
544 dest, ether[0], ether[1], ether[2], ether[3], ether[4], ether[5]);
547 NetSetEther (NetTxPacket, ether, PROT_IP);
548 NetSetIP (NetTxPacket + ETHER_HDR_SIZE, dest, dport, sport, len);
549 (void) eth_send(NetTxPacket, ETHER_HDR_SIZE + IP_HDR_SIZE + len);
551 return 0; /* transmited */
554 #if (CONFIG_COMMANDS & CFG_CMD_PING)
555 static ushort PingSeqNo;
563 /* XXX always send arp request */
565 memcpy(mac, NetEtherNullAddr, 6);
568 printf("sending ARP for %08lx\n", NetPingIP);
571 NetArpWaitPacketIP = NetPingIP;
572 NetArpWaitPacketMAC = mac;
574 NetSetEther(NetArpWaitTxPacket, mac, PROT_IP);
576 ip = (volatile IP_t *)(NetArpWaitTxPacket + ETHER_HDR_SIZE);
579 * Construct an IP and ICMP header. (need to set no fragment bit - XXX)
581 ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */
583 ip->ip_len = htons(IP_HDR_SIZE_NO_UDP + 8);
584 ip->ip_id = htons(NetIPID++);
585 ip->ip_off = htons(0x4000); /* No fragmentation */
587 ip->ip_p = 0x01; /* ICMP */
589 NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */
590 NetCopyIP((void*)&ip->ip_dst, &NetPingIP); /* - "" - */
591 ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
593 s = &ip->udp_src; /* XXX ICMP starts here */
594 s[0] = htons(0x0800); /* echo-request, code */
595 s[1] = 0; /* checksum */
596 s[2] = 0; /* identifier */
597 s[3] = htons(PingSeqNo++); /* sequence number */
598 s[1] = ~NetCksum((uchar *)s, 8/2);
600 /* size of the waiting packet */
601 NetArpWaitTxPacketSize = ETHER_HDR_SIZE + IP_HDR_SIZE_NO_UDP + 8;
603 /* and do the ARP request */
605 NetArpWaitTimerStart = get_timer(0);
607 return 1; /* waiting */
614 NetState = NETLOOP_FAIL; /* we did not get the reply */
618 PingHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
621 volatile IP_t *ip = (volatile IP_t *)pkt;
623 tmp = NetReadIP((void *)&ip->ip_src);
624 if (tmp != NetPingIP)
627 NetState = NETLOOP_SUCCESS;
630 static void PingStart(void)
632 NetSetTimeout (10 * CFG_HZ, PingTimeout);
633 NetSetHandler (PingHandler);
641 NetReceive(volatile uchar * pkt, int len)
651 et = (Ethernet_t *)pkt;
653 x = ntohs(et->et_protlen);
657 * Got a 802 packet. Check the other protocol field.
659 x = ntohs(et->et_prot);
660 ip = (IP_t *)(pkt + E802_HDR_SIZE);
661 len -= E802_HDR_SIZE;
663 ip = (IP_t *)(pkt + ETHER_HDR_SIZE);
664 len -= ETHER_HDR_SIZE;
668 printf("Receive from protocol 0x%x\n", x);
675 * We have to deal with two types of ARP packets:
676 * - REQUEST packets will be answered by sending our
677 * IP address - if we know it.
678 * - REPLY packates are expected only after we asked
679 * for the TFTP server's or the gateway's ethernet
680 * address; so if we receive such a packet, we set
681 * the server ethernet address
687 if (len < ARP_HDR_SIZE) {
688 printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
691 if (ntohs(arp->ar_hrd) != ARP_ETHER) {
694 if (ntohs(arp->ar_pro) != PROT_IP) {
697 if (arp->ar_hln != 6) {
700 if (arp->ar_pln != 4) {
708 if (NetReadIP(&arp->ar_data[16]) != NetOurIP) {
712 switch (ntohs(arp->ar_op)) {
713 case ARPOP_REQUEST: /* reply with our IP address */
715 printf("Got ARP REQUEST, return our IP\n");
717 NetSetEther((uchar *)et, et->et_src, PROT_ARP);
718 arp->ar_op = htons(ARPOP_REPLY);
719 memcpy (&arp->ar_data[10], &arp->ar_data[0], 6);
720 NetCopyIP(&arp->ar_data[16], &arp->ar_data[6]);
721 memcpy (&arp->ar_data[ 0], NetOurEther, 6);
722 NetCopyIP(&arp->ar_data[ 6], &NetOurIP);
723 (void) eth_send((uchar *)et, ((uchar *)arp-pkt) + ARP_HDR_SIZE);
726 case ARPOP_REPLY: /* arp reply */
727 /* are we waiting for a reply */
728 if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
731 printf("Got ARP REPLY, set server/gtwy eth addr (%02x:%02x:%02x:%02x:%02x:%02x)\n",
732 arp->ar_data[0], arp->ar_data[1],
733 arp->ar_data[2], arp->ar_data[3],
734 arp->ar_data[4], arp->ar_data[5]);
737 tmp = NetReadIP(&arp->ar_data[6]);
739 /* matched waiting packet's address */
740 if (tmp == NetArpWaitReplyIP) {
744 /* save address for later use */
745 memcpy(NetArpWaitPacketMAC, &arp->ar_data[0], 6);
747 /* modify header, and transmit it */
748 memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, NetArpWaitPacketMAC, 6);
749 (void) eth_send(NetArpWaitTxPacket, NetArpWaitTxPacketSize);
751 /* no arp request pending now */
752 NetArpWaitPacketIP = 0;
753 NetArpWaitTxPacketSize = 0;
754 NetArpWaitPacketMAC = NULL;
760 printf("Unexpected ARP opcode 0x%x\n", ntohs(arp->ar_op));
767 printf("Got RARP\n");
770 if (len < ARP_HDR_SIZE) {
771 printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
775 if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
776 (ntohs(arp->ar_hrd) != ARP_ETHER) ||
777 (ntohs(arp->ar_pro) != PROT_IP) ||
778 (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
780 printf("invalid RARP header\n");
782 NetCopyIP(&NetOurIP, &arp->ar_data[16]);
783 NetCopyIP(&NetServerIP, &arp->ar_data[ 6]);
784 memcpy (NetServerEther, &arp->ar_data[ 0], 6);
786 (*packetHandler)(0,0,0,0);
794 if (len < IP_HDR_SIZE) {
795 debug ("len bad %d < %d\n", len, IP_HDR_SIZE);
798 if (len < ntohs(ip->ip_len)) {
799 printf("len bad %d < %d\n", len, ntohs(ip->ip_len));
802 len = ntohs(ip->ip_len);
804 printf("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff);
806 if ((ip->ip_hl_v & 0xf0) != 0x40) {
809 if (ip->ip_off & htons(0x1fff)) { /* Can't deal w/ fragments */
812 if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2)) {
813 printf("checksum bad\n");
816 tmp = NetReadIP(&ip->ip_dst);
817 if (NetOurIP && tmp != NetOurIP && tmp != 0xFFFFFFFF) {
821 * watch for ICMP host redirects
823 * There is no real handler code (yet). We just watch
824 * for ICMP host redirect messages. In case anybody
825 * sees these messages: please contact me
826 * (wd@denx.de), or - even better - send me the
827 * necessary fixes :-)
829 * Note: in all cases where I have seen this so far
830 * it was a problem with the router configuration,
831 * for instance when a router was configured in the
832 * BOOTP reply, but the TFTP server was on the same
833 * subnet. So this is probably a warning that your
834 * configuration might be wrong. But I'm not really
835 * sure if there aren't any other situations.
837 if (ip->ip_p == IPPROTO_ICMP) {
838 ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);
840 switch (icmph->type) {
842 if (icmph->code != ICMP_REDIR_HOST)
844 puts (" ICMP Host Redirect to ");
845 print_IPaddr(icmph->un.gateway);
848 #if (CONFIG_COMMANDS & CFG_CMD_PING)
849 case ICMP_ECHO_REPLY:
851 * IP header OK. Pass the packet to the current handler.
853 /* XXX point to ip packet */
854 (*packetHandler)((uchar *)ip, 0, 0, 0);
860 } else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */
865 * IP header OK. Pass the packet to the current handler.
867 (*packetHandler)((uchar *)ip +IP_HDR_SIZE,
870 ntohs(ip->udp_len) - 8);
877 /**********************************************************************/
879 static int net_check_prereq (proto_t protocol)
883 #if (CONFIG_COMMANDS & CFG_CMD_PING)
885 if (NetPingIP == 0) {
886 puts ("*** ERROR: ping address not given\n");
892 if (NetServerIP == 0) {
893 puts ("*** ERROR: `serverip' not set\n");
897 #if (CONFIG_COMMANDS & CFG_CMD_PING)
902 puts ("*** ERROR: `ipaddr' not set\n");
910 if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
911 #ifdef CONFIG_NET_MULTI
912 extern int eth_get_dev_index (void);
913 int num = eth_get_dev_index();
917 puts ("*** ERROR: No ethernet found.\n");
920 puts ("*** ERROR: `ethaddr' not set\n");
923 printf ("*** ERROR: `eth%daddr' not set\n",
931 puts ("*** ERROR: `ethaddr' not set\n");
941 /**********************************************************************/
944 NetCksumOk(uchar * ptr, int len)
946 return !((NetCksum(ptr, len) + 1) & 0xfffe);
951 NetCksum(uchar * ptr, int len)
957 xsum += *((ushort *)ptr)++;
958 xsum = (xsum & 0xffff) + (xsum >> 16);
959 xsum = (xsum & 0xffff) + (xsum >> 16);
960 return (xsum & 0xffff);
965 NetSetEther(volatile uchar * xet, uchar * addr, uint prot)
967 Ethernet_t *et = (Ethernet_t *)xet;
969 memcpy (et->et_dest, addr, 6);
970 memcpy (et->et_src, NetOurEther, 6);
971 et->et_protlen = htons(prot);
976 NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len)
978 volatile IP_t *ip = (IP_t *)xip;
981 * If the data is an odd number of bytes, zero the
982 * byte after the last byte so that the checksum
986 xip[IP_HDR_SIZE + len] = 0;
989 * Construct an IP and UDP header.
990 (need to set no fragment bit - XXX)
992 ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */
994 ip->ip_len = htons(IP_HDR_SIZE + len);
995 ip->ip_id = htons(NetIPID++);
996 ip->ip_off = htons(0x4000); /* No fragmentation */
998 ip->ip_p = 17; /* UDP */
1000 NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */
1001 NetCopyIP((void*)&ip->ip_dst, &dest); /* - "" - */
1002 ip->udp_src = htons(sport);
1003 ip->udp_dst = htons(dport);
1004 ip->udp_len = htons(8 + len);
1006 ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
1009 void copy_filename (uchar *dst, uchar *src, int size)
1011 if (*src && (*src == '"')) {
1016 while ((--size > 0) && *src && (*src != '"')) {
1022 #endif /* CFG_CMD_NET */
1024 void ip_to_string (IPaddr_t x, char *s)
1027 sprintf (s,"%d.%d.%d.%d",
1028 (int)((x >> 24) & 0xff),
1029 (int)((x >> 16) & 0xff),
1030 (int)((x >> 8) & 0xff),
1031 (int)((x >> 0) & 0xff)
1035 IPaddr_t string_to_ip(char *s)
1044 for (addr=0, i=0; i<4; ++i) {
1045 ulong val = s ? simple_strtoul(s, &e, 10) : 0;
1047 addr |= (val & 0xFF);
1053 return (htonl(addr));
1056 void print_IPaddr (IPaddr_t x)
1060 ip_to_string(x, tmp);
1065 IPaddr_t getenv_IPaddr (char *var)
1067 return (string_to_ip(getenv(var)));