4 Copyright 1995 Philip Homburg
18 PUBLIC ipaddr_t
ip_get_netmask (hostaddr
)
21 return ip_netmask(ip_nettype(hostaddr
));
24 PUBLIC
int ip_chk_hdropt (opt
, optlen
)
28 int i
, security_present
= FALSE
, lose_source_present
= FALSE
,
29 strict_source_present
= FALSE
, record_route_present
= FALSE
,
30 timestamp_present
= FALSE
;
32 assert (!(optlen
& 3));
36 DBLOCK(2, printf("*opt= %d\n", *opt
));
40 case IP_OPT_EOL
: /* End of Option list */
42 case IP_OPT_NOP
: /* No Operation */
46 case IP_OPT_SEC
: /* Security */
49 security_present
= TRUE
;
55 case IP_OPT_LSRR
: /* Lose Source and Record Route */
56 if (lose_source_present
)
58 DBLOCK(1, printf("2nd lose soruce route\n"));
61 lose_source_present
= TRUE
;
65 printf("wrong length in source route\n"));
71 case IP_OPT_SSRR
: /* Strict Source and Record Route */
72 if (strict_source_present
)
74 strict_source_present
= TRUE
;
80 case IP_OPT_RR
: /* Record Route */
81 if (record_route_present
)
83 record_route_present
= TRUE
;
89 case IP_OPT_TS
: /* Timestamp */
90 if (timestamp_present
)
92 timestamp_present
= TRUE
;
95 switch (opt
[3] & 0xff)
119 DBLOCK(1, printf("option of wrong length\n"));
125 PUBLIC
void ip_print_frags(acc
)
135 for (first
= 1; acc
; acc
= acc
->acc_ext_link
, first
= 0)
137 assert (acc
->acc_length
>= IP_MIN_HDR_SIZE
);
138 ip_hdr
= (ip_hdr_t
*)ptr2acc_data(acc
);
141 writeIpAddr(ip_hdr
->ih_src
);
143 writeIpAddr(ip_hdr
->ih_dst
);
145 printf(" {%x:%d@%d%c}", ntohs(ip_hdr
->ih_id
),
146 ntohs(ip_hdr
->ih_length
),
147 (ntohs(ip_hdr
->ih_flags_fragoff
) & IH_FRAGOFF_MASK
)*8,
148 (ntohs(ip_hdr
->ih_flags_fragoff
) & IH_MORE_FRAGS
) ?
154 PUBLIC ipaddr_t
ip_get_ifaddr(port_nr
)
157 assert(port_nr
>= 0 && port_nr
< ip_conf_nr
);
159 return ip_port_table
[port_nr
].ip_ipaddr
;
162 PUBLIC nettype_t
ip_nettype(ipaddr
)
168 ipaddr
= ntohl(ipaddr
);
169 highbyte
= (ipaddr
>> 24) & 0xff;
175 nettype
= IPNT_MARTIAN
;
177 else if (highbyte
< 127)
178 nettype
= IPNT_CLASS_A
;
179 else if (highbyte
== 127)
181 else if (highbyte
< 192)
182 nettype
= IPNT_CLASS_B
;
183 else if (highbyte
< 224)
184 nettype
= IPNT_CLASS_C
;
185 else if (highbyte
< 240)
186 nettype
= IPNT_CLASS_D
;
187 else if (highbyte
< 248)
188 nettype
= IPNT_CLASS_E
;
189 else if (highbyte
< 255)
190 nettype
= IPNT_MARTIAN
;
193 if (ipaddr
== (ipaddr_t
)-1)
194 nettype
= IPNT_BROADCAST
;
196 nettype
= IPNT_MARTIAN
;
201 PUBLIC ipaddr_t
ip_netmask(nettype
)
206 case IPNT_ZERO
: return HTONL(0x00000000);
208 case IPNT_LOCAL
: return HTONL(0xff000000);
209 case IPNT_CLASS_B
: return HTONL(0xffff0000);
210 case IPNT_CLASS_C
: return HTONL(0xffffff00);
211 default: return HTONL(0xffffffff);
216 PUBLIC
char *ip_nettoa(nettype
)
221 case IPNT_ZERO
: return "zero";
222 case IPNT_CLASS_A
: return "class A";
223 case IPNT_LOCAL
: return "local";
224 case IPNT_CLASS_B
: return "class B";
225 case IPNT_CLASS_C
: return "class C";
226 case IPNT_CLASS_D
: return "class D";
227 case IPNT_CLASS_E
: return "class E";
228 case IPNT_MARTIAN
: return "martian";
229 case IPNT_BROADCAST
: return "broadcast";
230 default: return "<unknown>";
236 * $PchId: ip_lib.c,v 1.10 2002/06/08 21:35:52 philip Exp $