From 96e27c9928b5078526f2a7564700dbdafe2c8d42 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 5 Oct 2004 14:33:43 +0000 Subject: 2004-10-05 Paul Jakma * sockopt.{c,h}: add sockopt_iphdrincl_swab_{htosys,systoh}, functions to change byte order between system IP_HDRINCL order and host order. --- lib/ChangeLog | 6 ++++++ lib/sockopt.c | 26 ++++++++++++++++++++++++++ lib/sockopt.h | 7 +++++++ 3 files changed, 39 insertions(+) (limited to 'lib') diff --git a/lib/ChangeLog b/lib/ChangeLog index eec006c9..2bbda12b 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2004-10-05 Paul Jakma + + * sockopt.{c,h}: add sockopt_iphdrincl_swab_{htosys,systoh}, + functions to change byte order between system IP_HDRINCL order + and host order. + 2004-10-04 Hasso Tepper * memory.c, memory.h: Make char * argument of strdup functions const. diff --git a/lib/sockopt.c b/lib/sockopt.c index 1a7524b5..5936d661 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -360,3 +360,29 @@ getsockopt_ifindex (int af, struct msghdr *msgh) return (ifindex = 0); } } + +/* swab iph between order system uses for IP_HDRINCL and host order */ +void +sockopt_iphdrincl_swab_htosys (struct ip *iph) +{ + /* BSD and derived take iph in network order, except for + * ip_len and ip_off + */ +#ifndef HAVE_IP_HDRINCL_BSD_ORDER + iph->ip_len = htons(iph->ip_len); + iph->ip_off = htons(iph->ip_off); +#endif /* HAVE_IP_HDRINCL_BSD_ORDER */ + + iph->ip_id = htons(iph->ip_id); +} + +void +sockopt_iphdrincl_swab_systoh (struct ip *iph) +{ +#ifndef HAVE_IP_HDRINCL_BSD_ORDER + iph->ip_len = ntohs(iph->ip_len); + iph->ip_off = ntohs(iph->ip_off); +#endif /* HAVE_IP_HDRINCL_BSD_ORDER */ + + iph->ip_id = ntohs(iph->ip_id); +} diff --git a/lib/sockopt.h b/lib/sockopt.h index 3f4a7050..f6a43158 100644 --- a/lib/sockopt.h +++ b/lib/sockopt.h @@ -92,4 +92,11 @@ int setsockopt_pktinfo (int, int, int); /* Ask for, and get, ifindex, by whatever method is supported. */ int setsockopt_ifindex (int, int, int); int getsockopt_ifindex (int, struct msghdr *); + +/* swab the fields in iph between the host order and system order expected + * for IP_HDRINCL. + */ +void sockopt_iphdrincl_swab_htosys (struct ip *iph); +void sockopt_iphdrincl_swab_systoh (struct ip *iph); + #endif /*_ZEBRA_SOCKOPT_H */ -- cgit v1.2.1