diff options
author | Michael Brown <mcb30@ipxe.org> | 2013-10-21 14:05:40 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2013-10-21 14:34:08 +0100 |
commit | 365a09d867da20029fdf2f05a6e90f4fc7c51793 (patch) | |
tree | 35a664a3b32a6c3db47c9e5c3e01ca3fa4e87fbb /src/net | |
parent | b6a9152f8c48a3ab9a337e1f40d0cb390c7d533d (diff) | |
download | ipxe-365a09d867da20029fdf2f05a6e90f4fc7c51793.zip ipxe-365a09d867da20029fdf2f05a6e90f4fc7c51793.tar.gz ipxe-365a09d867da20029fdf2f05a6e90f4fc7c51793.tar.bz2 |
[ipv4] Add IPv4 socket address converter
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/ipv4.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/net/ipv4.c b/src/net/ipv4.c index 46f774e..7956d18 100644 --- a/src/net/ipv4.c +++ b/src/net/ipv4.c @@ -524,6 +524,36 @@ static const char * ipv4_ntoa ( const void *net_addr ) { return inet_ntoa ( * ( ( struct in_addr * ) net_addr ) ); } +/** + * Transcribe IPv4 socket address + * + * @v sa Socket address + * @ret string Socket address in standard notation + */ +static const char * ipv4_sock_ntoa ( struct sockaddr *sa ) { + struct sockaddr_in *sin = ( ( struct sockaddr_in * ) sa ); + + return inet_ntoa ( sin->sin_addr ); +} + +/** + * Parse IPv4 socket address + * + * @v string Socket address string + * @v sa Socket address to fill in + * @ret rc Return status code + */ +static int ipv4_sock_aton ( const char *string, struct sockaddr *sa ) { + struct sockaddr_in *sin = ( ( struct sockaddr_in * ) sa ); + struct in_addr in; + + if ( inet_aton ( string, &in ) ) { + sin->sin_addr = in; + return 0; + } + return -EINVAL; +} + /** IPv4 protocol */ struct net_protocol ipv4_protocol __net_protocol = { .name = "IP", @@ -546,6 +576,13 @@ struct arp_net_protocol ipv4_arp_protocol __arp_net_protocol = { .check = ipv4_arp_check, }; +/** IPv4 socket address converter */ +struct sockaddr_converter ipv4_sockaddr_converter __sockaddr_converter = { + .family = AF_INET, + .ntoa = ipv4_sock_ntoa, + .aton = ipv4_sock_aton, +}; + /****************************************************************************** * * Settings |