Browse Source

[ipv4] Add IPv4 socket address converter

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
365a09d867
1 changed files with 37 additions and 0 deletions
  1. 37
    0
      src/net/ipv4.c

+ 37
- 0
src/net/ipv4.c View File

524
 	return inet_ntoa ( * ( ( struct in_addr * ) net_addr ) );
524
 	return inet_ntoa ( * ( ( struct in_addr * ) net_addr ) );
525
 }
525
 }
526
 
526
 
527
+/**
528
+ * Transcribe IPv4 socket address
529
+ *
530
+ * @v sa		Socket address
531
+ * @ret string		Socket address in standard notation
532
+ */
533
+static const char * ipv4_sock_ntoa ( struct sockaddr *sa ) {
534
+	struct sockaddr_in *sin = ( ( struct sockaddr_in * ) sa );
535
+
536
+	return inet_ntoa ( sin->sin_addr );
537
+}
538
+
539
+/**
540
+ * Parse IPv4 socket address
541
+ *
542
+ * @v string		Socket address string
543
+ * @v sa		Socket address to fill in
544
+ * @ret rc		Return status code
545
+ */
546
+static int ipv4_sock_aton ( const char *string, struct sockaddr *sa ) {
547
+	struct sockaddr_in *sin = ( ( struct sockaddr_in * ) sa );
548
+	struct in_addr in;
549
+
550
+	if ( inet_aton ( string, &in ) ) {
551
+		sin->sin_addr = in;
552
+		return 0;
553
+	}
554
+	return -EINVAL;
555
+}
556
+
527
 /** IPv4 protocol */
557
 /** IPv4 protocol */
528
 struct net_protocol ipv4_protocol __net_protocol = {
558
 struct net_protocol ipv4_protocol __net_protocol = {
529
 	.name = "IP",
559
 	.name = "IP",
546
 	.check = ipv4_arp_check,
576
 	.check = ipv4_arp_check,
547
 };
577
 };
548
 
578
 
579
+/** IPv4 socket address converter */
580
+struct sockaddr_converter ipv4_sockaddr_converter __sockaddr_converter = {
581
+	.family = AF_INET,
582
+	.ntoa = ipv4_sock_ntoa,
583
+	.aton = ipv4_sock_aton,
584
+};
585
+
549
 /******************************************************************************
586
 /******************************************************************************
550
  *
587
  *
551
  * Settings
588
  * Settings

Loading…
Cancel
Save