소스 검색

[ipv4] Add IPv4 socket address converter

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 년 전
부모
커밋
365a09d867
1개의 변경된 파일37개의 추가작업 그리고 0개의 파일을 삭제
  1. 37
    0
      src/net/ipv4.c

+ 37
- 0
src/net/ipv4.c 파일 보기

@@ -524,6 +524,36 @@ static const char * ipv4_ntoa ( const void *net_addr ) {
524 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 557
 /** IPv4 protocol */
528 558
 struct net_protocol ipv4_protocol __net_protocol = {
529 559
 	.name = "IP",
@@ -546,6 +576,13 @@ struct arp_net_protocol ipv4_arp_protocol __arp_net_protocol = {
546 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 588
  * Settings

Loading…
취소
저장