|
@@ -588,11 +588,43 @@ static int ipv4_arp_check ( struct net_device *netdev, const void *net_addr ) {
|
588
|
588
|
return -ENOENT;
|
589
|
589
|
}
|
590
|
590
|
|
|
591
|
+/**
|
|
592
|
+ * Parse IPv4 address
|
|
593
|
+ *
|
|
594
|
+ * @v string IPv4 address string
|
|
595
|
+ * @ret in IPv4 address to fill in
|
|
596
|
+ * @ret ok IPv4 address is valid
|
|
597
|
+ *
|
|
598
|
+ * Note that this function returns nonzero iff the address is valid,
|
|
599
|
+ * to match the standard BSD API function of the same name. Unlike
|
|
600
|
+ * most other iPXE functions, a zero therefore indicates failure.
|
|
601
|
+ */
|
|
602
|
+int inet_aton ( const char *string, struct in_addr *in ) {
|
|
603
|
+ const char *separator = "...";
|
|
604
|
+ uint8_t *byte = ( ( uint8_t * ) in );
|
|
605
|
+ char *endp;
|
|
606
|
+ unsigned long value;
|
|
607
|
+
|
|
608
|
+ while ( 1 ) {
|
|
609
|
+ value = strtoul ( string, &endp, 0 );
|
|
610
|
+ if ( string == endp )
|
|
611
|
+ return 0;
|
|
612
|
+ if ( value > 0xff )
|
|
613
|
+ return 0;
|
|
614
|
+ *(byte++) = value;
|
|
615
|
+ if ( *endp != *separator )
|
|
616
|
+ return 0;
|
|
617
|
+ if ( ! *(separator++) )
|
|
618
|
+ return 1;
|
|
619
|
+ string = ( endp + 1 );
|
|
620
|
+ }
|
|
621
|
+}
|
|
622
|
+
|
591
|
623
|
/**
|
592
|
624
|
* Convert IPv4 address to dotted-quad notation
|
593
|
625
|
*
|
594
|
|
- * @v in IP address
|
595
|
|
- * @ret string IP address in dotted-quad notation
|
|
626
|
+ * @v in IPv4 address
|
|
627
|
+ * @ret string IPv4 address in dotted-quad notation
|
596
|
628
|
*/
|
597
|
629
|
char * inet_ntoa ( struct in_addr in ) {
|
598
|
630
|
static char buf[16]; /* "xxx.xxx.xxx.xxx" */
|
|
@@ -603,10 +635,10 @@ char * inet_ntoa ( struct in_addr in ) {
|
603
|
635
|
}
|
604
|
636
|
|
605
|
637
|
/**
|
606
|
|
- * Transcribe IP address
|
|
638
|
+ * Transcribe IPv4 address
|
607
|
639
|
*
|
608
|
|
- * @v net_addr IP address
|
609
|
|
- * @ret string IP address in dotted-quad notation
|
|
640
|
+ * @v net_addr IPv4 address
|
|
641
|
+ * @ret string IPv4 address in dotted-quad notation
|
610
|
642
|
*
|
611
|
643
|
*/
|
612
|
644
|
static const char * ipv4_ntoa ( const void *net_addr ) {
|