libxtables: xtables.c: Use getnameinfo()
PATCH 1/1 libxtables: xtables.c: Use getnameinfo()
Use getnameinfo() instead of deprecated gethostbyaddr()
--- libxtables/xtables.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
libxtables/xtables.c +20 -5
@@ -1210,13 +1210,28 @@ const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp)static const char *ipaddr_to_host (const struct in_addr *addr) { -struct hostent *host; +static char hostname[NI_MAXHOST ]; +struct sockaddr_in saddr; +int err; - host =gethostbyaddr (addr,sizeof (struct in_addr ),AF_INET ); -if (host ==NULL ) -return NULL ; +memset (&saddr,0 ,sizeof (struct sockaddr_in )); +memcpy (&saddr.sin_addr, addr,sizeof (*addr)); + saddr.sin_family =AF_INET ; + + err =getnameinfo ((const void *)&saddr,sizeof (struct sockaddr_in ), + hostname,sizeof (hostname) -1 ,NULL ,0 ,0 ); + +if (err !=0 ) { +#ifdef DEBUG +fprintf (stderr,"IP2Name: %s\n" ,gai_strerror (err)); +#endif +return NULL ; + } -return host->h_name; +#ifdef DEBUG +fprintf (stderr,"\naddr2host: %s\n" , hostname); +#endif +return hostname; }static const char *ipaddr_to_network (const struct in_addr *addr)
Signature · 1 line
2.7.4
Pablo Neira Ayuso
maintainerQuoted 15 lines · Shyam Saini
Use
getnameinfo()instead of deprecatedgethostbyaddr()Signed-off-by Shyam Saini <[email protected]>--- libxtables/xtables.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)libxtables/xtables.c +0
-0@@ -1210,13 +1210,28 @@ const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp)static const char *ipaddr_to_host (const struct in_addr *addr) {
libxtables/xtables.c const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) · line 1218
Quoted 10 lines
libxtables/xtables.c +5
-4-struct hostent *host; +static char hostname[NI_MAXHOST ]; +struct sockaddr_in saddr; +int err; - host =gethostbyaddr (addr,sizeof (struct in_addr ),AF_INET ); -if (host ==NULL ) -return NULL ; +memset (&saddr,0 ,sizeof (struct sockaddr_in )); +memcpy (&saddr.sin_addr, addr,sizeof (*addr));
You can skip this by perfoming C99 initialization, eg.
struct sockaddr_in sin = { .sin_family = AF_INET, };
sin.sin_addr = *addr;Quoted 27 lines
libxtables/xtables.c +15
-1+ saddr.sin_family =AF_INET ; + + err =getnameinfo ((const void *)&saddr,sizeof (struct sockaddr_in ), + hostname,sizeof (hostname) -1 ,NULL ,0 ,0 ); + +if (err !=0 ) { +#ifdef DEBUG +fprintf (stderr,"IP2Name: %s\n" ,gai_strerror (err)); +#endif +return NULL ; + } -return host->h_name; +#ifdef DEBUG +fprintf (stderr,"\naddr2host: %s\n" , hostname); +#endif +return hostname; }static const char *ipaddr_to_network (const struct in_addr *addr)Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerQuoted 29 lines · Pablo Neira Ayuso
Quoted 15 lines · Shyam Saini
Use
getnameinfo()instead of deprecatedgethostbyaddr()Signed-off-by Shyam Saini <[email protected]>--- libxtables/xtables.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)libxtables/xtables.c +0
-0@@ -1210,13 +1210,28 @@ const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp)static const char *ipaddr_to_host (const struct in_addr *addr) {libxtables/xtables.c const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) · line 1218
Quoted 10 lines
libxtables/xtables.c +5
-4-struct hostent *host; +static char hostname[NI_MAXHOST ]; +struct sockaddr_in saddr; +int err; - host =gethostbyaddr (addr,sizeof (struct in_addr ),AF_INET ); -if (host ==NULL ) -return NULL ; +memset (&saddr,0 ,sizeof (struct sockaddr_in )); +memcpy (&saddr.sin_addr, addr,sizeof (*addr));You can skip this by perfoming C99 initialization, eg.
Quoted 2 lines
struct sockaddr_in sin = { .sin_family = AF_INET, };
sin.sin_addr = *addr;One more comment below.
Quoted 9 lines
libxtables/xtables.c const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) · line 1227
Quoted 9 lines
libxtables/xtables.c +9
-0+ saddr.sin_family =AF_INET ; + + err =getnameinfo ((const void *)&saddr,sizeof (struct sockaddr_in ), + hostname,sizeof (hostname) -1 ,NULL ,0 ,0 ); + +if (err !=0 ) { +#ifdef DEBUG +fprintf (stderr,"IP2Name: %s\n" ,gai_strerror (err)); +#endif
I don't remember to have used this debugging this ever, probably it is good to remove it.
Quoted 8 lines
libxtables/xtables.c const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) · line 1234
Quoted 8 lines
libxtables/xtables.c +6
-1+return NULL ; + } -return host->h_name; +#ifdef DEBUG +fprintf (stderr,"\naddr2host: %s\n" , hostname); +#endif +return hostname;
^^^^^^^^^^^
Minor nitpick: indentation is not correct here.
Quoted 35 lines · Pablo Neira Ayuso
Quoted 29 lines · Pablo Neira Ayuso
Quoted 15 lines · Shyam Saini
Use
getnameinfo()instead of deprecatedgethostbyaddr()Signed-off-by Shyam Saini <[email protected]>--- libxtables/xtables.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)libxtables/xtables.c +0
-0@@ -1210,13 +1210,28 @@ const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp)static const char *ipaddr_to_host (const struct in_addr *addr) {libxtables/xtables.c const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) · line 1218
Quoted 10 lines
libxtables/xtables.c +5
-4-struct hostent *host; +static char hostname[NI_MAXHOST ]; +struct sockaddr_in saddr; +int err; - host =gethostbyaddr (addr,sizeof (struct in_addr ),AF_INET ); -if (host ==NULL ) -return NULL ; +memset (&saddr,0 ,sizeof (struct sockaddr_in )); +memcpy (&saddr.sin_addr, addr,sizeof (*addr));You can skip this by perfoming C99 initialization, eg.
Quoted 2 lines
struct sockaddr_in sin = { .sin_family = AF_INET, }; sin.sin_addr = *addr;One more comment below.
Quoted 13 lines
Quoted 9 lines
libxtables/xtables.c const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) · line 1227
Quoted 9 lines
libxtables/xtables.c +9
-0+ saddr.sin_family =AF_INET ; + + err =getnameinfo ((const void *)&saddr,sizeof (struct sockaddr_in ), + hostname,sizeof (hostname) -1 ,NULL ,0 ,0 ); + +if (err !=0 ) { +#ifdef DEBUG +fprintf (stderr,"IP2Name: %s\n" ,gai_strerror (err)); +#endif I don't remember to have used this debugging this ever, probably it is good to remove it.
Debugging code has been in this applied patch too:
http://git.netfilter.org/iptables/commit/?id=2d2b5e046aa56a518160716a9ddf9df53fc79c1f.
Maybe its good to remove it as well then?
Quoted 15 lines
Quoted 8 lines
libxtables/xtables.c const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) · line 1234
Quoted 8 lines
libxtables/xtables.c +6
-1+return NULL ; + } -return host->h_name; +#ifdef DEBUG +fprintf (stderr,"\naddr2host: %s\n" , hostname); +#endif +return hostname;^^^^^^^^^^^Minor nitpick: indentation is not correct here.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerQuoted 50 lines · Shivani Bhardwaj
Quoted 35 lines · Pablo Neira Ayuso
Quoted 29 lines · Pablo Neira Ayuso
Quoted 15 lines · Shyam Saini
Use
getnameinfo()instead of deprecatedgethostbyaddr()Signed-off-by Shyam Saini <[email protected]>--- libxtables/xtables.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)libxtables/xtables.c +0
-0@@ -1210,13 +1210,28 @@ const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp)static const char *ipaddr_to_host (const struct in_addr *addr) {libxtables/xtables.c const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) · line 1218
Quoted 10 lines
libxtables/xtables.c +5
-4-struct hostent *host; +static char hostname[NI_MAXHOST ]; +struct sockaddr_in saddr; +int err; - host =gethostbyaddr (addr,sizeof (struct in_addr ),AF_INET ); -if (host ==NULL ) -return NULL ; +memset (&saddr,0 ,sizeof (struct sockaddr_in )); +memcpy (&saddr.sin_addr, addr,sizeof (*addr));You can skip this by perfoming C99 initialization, eg.
Quoted 2 lines
struct sockaddr_in sin = { .sin_family = AF_INET, }; sin.sin_addr = *addr;One more comment below.
Quoted 13 lines
Quoted 9 lines
libxtables/xtables.c const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) · line 1227
Quoted 9 lines
libxtables/xtables.c +9
-0+ saddr.sin_family =AF_INET ; + + err =getnameinfo ((const void *)&saddr,sizeof (struct sockaddr_in ), + hostname,sizeof (hostname) -1 ,NULL ,0 ,0 ); + +if (err !=0 ) { +#ifdef DEBUG +fprintf (stderr,"IP2Name: %s\n" ,gai_strerror (err)); +#endif I don't remember to have used this debugging this ever, probably it is good to remove it.
Quoted 3 lines
Debugging code has been in this applied patch too:
http://git.netfilter.org/iptables/commit/?id=2d2b5e046aa56a518160716a9ddf9df53fc79c1f.
Maybe its good to remove it as well then?
Yes, please remove all debugging in libxtables/xtables.c, in an initial patch.
Thanks.