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;
257 #ifdef CONFIG_NET_MULTI
258 memcpy (NetOurEther, eth_get_dev()->enetaddr, 6);
260 memcpy (NetOurEther, bd->bi_enetaddr, 6);
263 NetState = NETLOOP_CONTINUE;
266 * Start the ball rolling with the given start function. From
267 * here on, this code is a state machine driven by received
268 * packets and timer events.
272 #if (CONFIG_COMMANDS & CFG_CMD_PING)
276 NetCopyIP(&NetOurIP, &bd->bi_ip_addr);
277 NetOurGatewayIP = getenv_IPaddr ("gatewayip");
278 NetOurSubnetMask= getenv_IPaddr ("netmask");
282 NetServerIP = getenv_IPaddr ("serverip");
284 #if (CONFIG_COMMANDS & CFG_CMD_PING)
297 * initialize our IP addr to 0 in order to accept ANY
298 * IP addr assigned to us by the BOOTP / RARP server
307 switch (net_check_prereq (protocol)) {
309 /* network not configured */
312 #ifdef CONFIG_NET_MULTI
314 /* network device not configured */
316 #endif /* CONFIG_NET_MULTI */
319 #ifdef CONFIG_NET_MULTI
324 /* always use ARP to get server ethernet address */
328 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
330 /* Start with a clean slate... */
333 DhcpRequest(); /* Basically same as BOOTP */
335 #endif /* CFG_CMD_DHCP */
346 #if (CONFIG_COMMANDS & CFG_CMD_PING)
355 NetBootFileXferSize = 0;
361 * Main packet reception loop. Loop receiving packets until
362 * someone sets `NetQuit'.
366 #ifdef CONFIG_SHOW_ACTIVITY
368 extern void show_activity(int arg);
373 * Check the ethernet for a new packet. The ethernet
374 * receive routine will process it.
379 * Abort if ctrl-c was pressed.
390 * Check for a timeout, and run the timeout handler
393 if (timeHandler && (get_timer(0) > timeValue)) {
397 timeHandler = (thand_f *)0;
404 case NETLOOP_RESTART:
405 #ifdef CONFIG_NET_MULTI
410 case NETLOOP_SUCCESS:
411 if (NetBootFileXferSize > 0) {
413 printf("Bytes transferred = %ld (%lx hex)\n",
415 NetBootFileXferSize);
416 sprintf(buf, "%lx", NetBootFileXferSize);
417 setenv("filesize", buf);
420 return NetBootFileXferSize;
428 /**********************************************************************/
431 startAgainTimeout(void)
433 NetState = NETLOOP_RESTART;
437 startAgainHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
439 /* Totally ignore the packet */
445 #ifndef CONFIG_NET_MULTI
446 NetSetTimeout(10 * CFG_HZ, startAgainTimeout);
447 NetSetHandler(startAgainHandler);
449 DECLARE_GLOBAL_DATA_PTR;
452 eth_try_another(!NetRestarted);
459 NetSetTimeout(10 * CFG_HZ, startAgainTimeout);
460 NetSetHandler(startAgainHandler);
464 NetState = NETLOOP_FAIL;
469 NetState = NETLOOP_RESTART;
474 /**********************************************************************/
480 NetSetHandler(rxhand_f * f)
487 NetSetTimeout(int iv, thand_f * f)
490 timeHandler = (thand_f *)0;
493 timeValue = get_timer(0) + iv;
499 NetSendPacket(volatile uchar * pkt, int len)
501 (void) eth_send(pkt, len);
505 NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
507 /* convert to new style broadcast */
511 /* if broadcast, make the ether address a broadcast and don't do ARP */
512 if (dest == 0xFFFFFFFF)
513 ether = NetBcastAddr;
515 /* if MAC address was not discovered yet, save the packet and do an ARP request */
516 if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
519 printf("sending ARP for %08lx\n", dest);
522 NetArpWaitPacketIP = dest;
523 NetArpWaitPacketMAC = ether;
524 NetSetEther (NetArpWaitTxPacket, NetArpWaitPacketMAC, PROT_IP);
525 NetSetIP (NetArpWaitTxPacket + ETHER_HDR_SIZE, dest, dport, sport, len);
526 memcpy(NetArpWaitTxPacket + ETHER_HDR_SIZE + IP_HDR_SIZE,
527 (uchar *)NetTxPacket + ETHER_HDR_SIZE + IP_HDR_SIZE, len);
529 /* size of the waiting packet */
530 NetArpWaitTxPacketSize = ETHER_HDR_SIZE + IP_HDR_SIZE + len;
532 /* and do the ARP request */
534 NetArpWaitTimerStart = get_timer(0);
536 return 1; /* waiting */
540 printf("sending UDP to %08lx/%02x:%02x:%02x:%02x:%02x:%02x\n",
541 dest, ether[0], ether[1], ether[2], ether[3], ether[4], ether[5]);
544 NetSetEther (NetTxPacket, ether, PROT_IP);
545 NetSetIP (NetTxPacket + ETHER_HDR_SIZE, dest, dport, sport, len);
546 (void) eth_send(NetTxPacket, ETHER_HDR_SIZE + IP_HDR_SIZE + len);
548 return 0; /* transmited */
551 #if (CONFIG_COMMANDS & CFG_CMD_PING)
552 static ushort PingSeqNo;
560 /* XXX always send arp request */
562 memcpy(mac, NetEtherNullAddr, 6);
565 printf("sending ARP for %08lx\n", NetPingIP);
568 NetArpWaitPacketIP = NetPingIP;
569 NetArpWaitPacketMAC = mac;
571 NetSetEther(NetArpWaitTxPacket, mac, PROT_IP);
573 ip = (volatile IP_t *)(NetArpWaitTxPacket + ETHER_HDR_SIZE);
576 * Construct an IP and ICMP header. (need to set no fragment bit - XXX)
578 ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */
580 ip->ip_len = htons(IP_HDR_SIZE_NO_UDP + 8);
581 ip->ip_id = htons(NetIPID++);
582 ip->ip_off = htons(0x4000); /* No fragmentation */
584 ip->ip_p = 0x01; /* ICMP */
586 NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */
587 NetCopyIP((void*)&ip->ip_dst, &NetPingIP); /* - "" - */
588 ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
590 s = &ip->udp_src; /* XXX ICMP starts here */
591 s[0] = htons(0x0800); /* echo-request, code */
592 s[1] = 0; /* checksum */
593 s[2] = 0; /* identifier */
594 s[3] = htons(PingSeqNo++); /* sequence number */
595 s[1] = ~NetCksum((uchar *)s, 8/2);
597 /* size of the waiting packet */
598 NetArpWaitTxPacketSize = ETHER_HDR_SIZE + IP_HDR_SIZE_NO_UDP + 8;
600 /* and do the ARP request */
602 NetArpWaitTimerStart = get_timer(0);
604 return 1; /* waiting */
611 NetState = NETLOOP_FAIL; /* we did not get the reply */
615 PingHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
618 volatile IP_t *ip = (volatile IP_t *)pkt;
620 tmp = NetReadIP((void *)&ip->ip_src);
621 if (tmp != NetPingIP)
624 NetState = NETLOOP_SUCCESS;
627 static void PingStart(void)
629 NetSetTimeout (10 * CFG_HZ, PingTimeout);
630 NetSetHandler (PingHandler);
638 NetReceive(volatile uchar * pkt, int len)
648 et = (Ethernet_t *)pkt;
650 x = ntohs(et->et_protlen);
654 * Got a 802 packet. Check the other protocol field.
656 x = ntohs(et->et_prot);
657 ip = (IP_t *)(pkt + E802_HDR_SIZE);
658 len -= E802_HDR_SIZE;
660 ip = (IP_t *)(pkt + ETHER_HDR_SIZE);
661 len -= ETHER_HDR_SIZE;
665 printf("Receive from protocol 0x%x\n", x);
672 * We have to deal with two types of ARP packets:
673 * - REQUEST packets will be answered by sending our
674 * IP address - if we know it.
675 * - REPLY packates are expected only after we asked
676 * for the TFTP server's or the gateway's ethernet
677 * address; so if we receive such a packet, we set
678 * the server ethernet address
684 if (len < ARP_HDR_SIZE) {
685 printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
688 if (ntohs(arp->ar_hrd) != ARP_ETHER) {
691 if (ntohs(arp->ar_pro) != PROT_IP) {
694 if (arp->ar_hln != 6) {
697 if (arp->ar_pln != 4) {
705 if (NetReadIP(&arp->ar_data[16]) != NetOurIP) {
709 switch (ntohs(arp->ar_op)) {
710 case ARPOP_REQUEST: /* reply with our IP address */
712 printf("Got ARP REQUEST, return our IP\n");
714 NetSetEther((uchar *)et, et->et_src, PROT_ARP);
715 arp->ar_op = htons(ARPOP_REPLY);
716 memcpy (&arp->ar_data[10], &arp->ar_data[0], 6);
717 NetCopyIP(&arp->ar_data[16], &arp->ar_data[6]);
718 memcpy (&arp->ar_data[ 0], NetOurEther, 6);
719 NetCopyIP(&arp->ar_data[ 6], &NetOurIP);
720 (void) eth_send((uchar *)et, ((uchar *)arp-pkt) + ARP_HDR_SIZE);
723 case ARPOP_REPLY: /* arp reply */
724 /* are we waiting for a reply */
725 if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
728 printf("Got ARP REPLY, set server/gtwy eth addr (%02x:%02x:%02x:%02x:%02x:%02x)\n",
729 arp->ar_data[0], arp->ar_data[1],
730 arp->ar_data[2], arp->ar_data[3],
731 arp->ar_data[4], arp->ar_data[5]);
734 tmp = NetReadIP(&arp->ar_data[6]);
736 /* matched waiting packet's address */
737 if (tmp == NetArpWaitReplyIP) {
741 /* save address for later use */
742 memcpy(NetArpWaitPacketMAC, &arp->ar_data[0], 6);
744 /* modify header, and transmit it */
745 memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, NetArpWaitPacketMAC, 6);
746 (void) eth_send(NetArpWaitTxPacket, NetArpWaitTxPacketSize);
748 /* no arp request pending now */
749 NetArpWaitPacketIP = 0;
750 NetArpWaitTxPacketSize = 0;
751 NetArpWaitPacketMAC = NULL;
757 printf("Unexpected ARP opcode 0x%x\n", ntohs(arp->ar_op));
764 printf("Got RARP\n");
767 if (len < ARP_HDR_SIZE) {
768 printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
772 if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
773 (ntohs(arp->ar_hrd) != ARP_ETHER) ||
774 (ntohs(arp->ar_pro) != PROT_IP) ||
775 (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
777 printf("invalid RARP header\n");
779 NetCopyIP(&NetOurIP, &arp->ar_data[16]);
780 NetCopyIP(&NetServerIP, &arp->ar_data[ 6]);
781 memcpy (NetServerEther, &arp->ar_data[ 0], 6);
783 (*packetHandler)(0,0,0,0);
791 if (len < IP_HDR_SIZE) {
792 debug ("len bad %d < %d\n", len, IP_HDR_SIZE);
795 if (len < ntohs(ip->ip_len)) {
796 printf("len bad %d < %d\n", len, ntohs(ip->ip_len));
799 len = ntohs(ip->ip_len);
801 printf("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff);
803 if ((ip->ip_hl_v & 0xf0) != 0x40) {
806 if (ip->ip_off & htons(0x1fff)) { /* Can't deal w/ fragments */
809 if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2)) {
810 printf("checksum bad\n");
813 tmp = NetReadIP(&ip->ip_dst);
814 if (NetOurIP && tmp != NetOurIP && tmp != 0xFFFFFFFF) {
818 * watch for ICMP host redirects
820 * There is no real handler code (yet). We just watch
821 * for ICMP host redirect messages. In case anybody
822 * sees these messages: please contact me
823 * (wd@denx.de), or - even better - send me the
824 * necessary fixes :-)
826 * Note: in all cases where I have seen this so far
827 * it was a problem with the router configuration,
828 * for instance when a router was configured in the
829 * BOOTP reply, but the TFTP server was on the same
830 * subnet. So this is probably a warning that your
831 * configuration might be wrong. But I'm not really
832 * sure if there aren't any other situations.
834 if (ip->ip_p == IPPROTO_ICMP) {
835 ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);
837 switch (icmph->type) {
839 if (icmph->code != ICMP_REDIR_HOST)
841 puts (" ICMP Host Redirect to ");
842 print_IPaddr(icmph->un.gateway);
845 #if (CONFIG_COMMANDS & CFG_CMD_PING)
846 case ICMP_ECHO_REPLY:
848 * IP header OK. Pass the packet to the current handler.
850 /* XXX point to ip packet */
851 (*packetHandler)((uchar *)ip, 0, 0, 0);
857 } else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */
862 * IP header OK. Pass the packet to the current handler.
864 (*packetHandler)((uchar *)ip +IP_HDR_SIZE,
867 ntohs(ip->udp_len) - 8);
874 /**********************************************************************/
876 static int net_check_prereq (proto_t protocol)
880 #if (CONFIG_COMMANDS & CFG_CMD_PING)
882 if (NetPingIP == 0) {
883 puts ("*** ERROR: ping address not given\n");
889 if (NetServerIP == 0) {
890 puts ("*** ERROR: `serverip' not set\n");
894 #if (CONFIG_COMMANDS & CFG_CMD_PING)
899 puts ("*** ERROR: `ipaddr' not set\n");
907 if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
908 #ifdef CONFIG_NET_MULTI
909 extern int eth_get_dev_index (void);
910 int num = eth_get_dev_index();
914 puts ("*** ERROR: No ethernet found.\n");
917 puts ("*** ERROR: `ethaddr' not set\n");
920 printf ("*** ERROR: `eth%daddr' not set\n",
928 puts ("*** ERROR: `ethaddr' not set\n");
938 /**********************************************************************/
941 NetCksumOk(uchar * ptr, int len)
943 return !((NetCksum(ptr, len) + 1) & 0xfffe);
948 NetCksum(uchar * ptr, int len)
954 xsum += *((ushort *)ptr)++;
955 xsum = (xsum & 0xffff) + (xsum >> 16);
956 xsum = (xsum & 0xffff) + (xsum >> 16);
957 return (xsum & 0xffff);
962 NetSetEther(volatile uchar * xet, uchar * addr, uint prot)
964 Ethernet_t *et = (Ethernet_t *)xet;
966 memcpy (et->et_dest, addr, 6);
967 memcpy (et->et_src, NetOurEther, 6);
968 et->et_protlen = htons(prot);
973 NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len)
975 volatile IP_t *ip = (IP_t *)xip;
978 * If the data is an odd number of bytes, zero the
979 * byte after the last byte so that the checksum
983 xip[IP_HDR_SIZE + len] = 0;
986 * Construct an IP and UDP header.
987 (need to set no fragment bit - XXX)
989 ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */
991 ip->ip_len = htons(IP_HDR_SIZE + len);
992 ip->ip_id = htons(NetIPID++);
993 ip->ip_off = htons(0x4000); /* No fragmentation */
995 ip->ip_p = 17; /* UDP */
997 NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */
998 NetCopyIP((void*)&ip->ip_dst, &dest); /* - "" - */
999 ip->udp_src = htons(sport);
1000 ip->udp_dst = htons(dport);
1001 ip->udp_len = htons(8 + len);
1003 ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
1006 void copy_filename (uchar *dst, uchar *src, int size)
1008 if (*src && (*src == '"')) {
1013 while ((--size > 0) && *src && (*src != '"')) {
1019 #endif /* CFG_CMD_NET */
1021 void ip_to_string (IPaddr_t x, char *s)
1024 sprintf (s,"%d.%d.%d.%d",
1025 (int)((x >> 24) & 0xff),
1026 (int)((x >> 16) & 0xff),
1027 (int)((x >> 8) & 0xff),
1028 (int)((x >> 0) & 0xff)
1032 IPaddr_t string_to_ip(char *s)
1041 for (addr=0, i=0; i<4; ++i) {
1042 ulong val = s ? simple_strtoul(s, &e, 10) : 0;
1044 addr |= (val & 0xFF);
1050 return (htonl(addr));
1053 void print_IPaddr (IPaddr_t x)
1057 ip_to_string(x, tmp);
1062 IPaddr_t getenv_IPaddr (char *var)
1064 return (string_to_ip(getenv(var)));