LIB.T
资源名称:os_source.zip [点击查看]
上传用户:datang2001
上传日期:2007-02-01
资源大小:53269k
文件大小:969k
源码类别:
操作系统开发
开发平台:
C/C++
- 21015 SINGLE s1,s2;
- 21016 {
- 21017 EXTEND e1,e2;
- 21018
- 21019 extend(&s1,&e1,sizeof(SINGLE));
- 21020 extend(&s2,&e2,sizeof(SINGLE));
- 21021 /* do a multiply */
- 21022 mul_ext(&e1,&e2);
- 21023 compact(&e1,&s1,sizeof(SINGLE));
- 21024 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/mlf8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 21100 /*
- 21101 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 21102 See the copyright notice in the ACK home directory, in the file "Copyright".
- 21103 */
- 21104
- 21105 /* $Header: mlf8.c,v 1.4 93/01/05 12:05:44 ceriel Exp $ */
- 21106
- 21107 /*
- 21108 * Multiply Double Precision Float (MLF 8)
- 21109 */
- 21110
- 21111 #include "FP_types.h"
- 21112
- 21113 void
- 21114 mlf8(s2,s1)
- 21115 DOUBLE s1,s2;
- 21116 {
- 21117 EXTEND e1,e2;
- 21118
- 21119 extend(&s1.d[0],&e1,sizeof(DOUBLE));
- .Op 189 src/lib/float/mlf8.c
- 21120 extend(&s2.d[0],&e2,sizeof(DOUBLE));
- 21121 /* do a multiply */
- 21122 mul_ext(&e1,&e2);
- 21123 compact(&e1,&s1.d[0],sizeof(DOUBLE));
- 21124 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/mul_ext.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 21200 /*
- 21201 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 21202 See the copyright notice in the ACK home directory, in the file "Copyright".
- 21203 */
- 21204
- 21205 /* $Header: mul_ext.c,v 1.6 93/01/05 12:05:51 ceriel Exp $ */
- 21206
- 21207 /*
- 21208 ROUTINE TO MULTIPLY TWO EXTENDED FORMAT NUMBERS
- 21209 */
- 21210
- 21211 # include "FP_bias.h"
- 21212 # include "FP_trap.h"
- 21213 # include "FP_types.h"
- 21214 # include "FP_shift.h"
- 21215
- 21216 void
- 21217 mul_ext(e1,e2)
- 21218 EXTEND *e1,*e2;
- 21219 {
- 21220 register int i,j; /* loop control */
- 21221 unsigned short mp[4]; /* multiplier */
- 21222 unsigned short mc[4]; /* multipcand */
- 21223 unsigned short result[8]; /* result */
- 21224 register unsigned short *pres;
- 21225
- 21226 /* first save the sign (XOR) */
- 21227 e1->sign ^= e2->sign;
- 21228
- 21229 /* compute new exponent */
- 21230 e1->exp += e2->exp + 1;
- 21231 /* 128 bit multiply of mantissas */
- 21232
- 21233 /* assign unknown long formats */
- 21234 /* to known unsigned word formats */
- 21235 mp[0] = e1->m1 >> 16;
- 21236 mp[1] = (unsigned short) e1->m1;
- 21237 mp[2] = e1->m2 >> 16;
- 21238 mp[3] = (unsigned short) e1->m2;
- 21239 mc[0] = e2->m1 >> 16;
- 21240 mc[1] = (unsigned short) e2->m1;
- 21241 mc[2] = e2->m2 >> 16;
- 21242 mc[3] = (unsigned short) e2->m2;
- 21243 for (i = 8; i--;) {
- 21244 result[i] = 0;
- .Ep 190 src/lib/float/mul_ext.c
- 21245 }
- 21246 /*
- 21247 * fill registers with their components
- 21248 */
- 21249 for(i=4, pres = &result[4];i--;pres--) if (mp[i]) {
- 21250 unsigned short k = 0;
- 21251 unsigned long mpi = mp[i];
- 21252 for(j=4;j--;) {
- 21253 unsigned long tmp = (unsigned long)pres[j] + k;
- 21254 if (mc[j]) tmp += mpi * mc[j];
- 21255 pres[j] = tmp;
- 21256 k = tmp >> 16;
- 21257 }
- 21258 pres[-1] = k;
- 21259 }
- 21260 if (! (result[0] & 0x8000)) {
- 21261 e1->exp--;
- 21262 for (i = 0; i <= 3; i++) {
- 21263 result[i] <<= 1;
- 21264 if (result[i+1]&0x8000) result[i] |= 1;
- 21265 }
- 21266 result[4] <<= 1;
- 21267 }
- 21268
- 21269 /*
- 21270 * combine the registers to a total
- 21271 */
- 21272 e1->m1 = ((unsigned long)(result[0]) << 16) + result[1];
- 21273 e1->m2 = ((unsigned long)(result[2]) << 16) + result[3];
- 21274 if (result[4] & 0x8000) {
- 21275 if (++e1->m2 == 0)
- 21276 if (++e1->m1 == 0) {
- 21277 e1->m1 = NORMBIT;
- 21278 e1->exp++;
- 21279 }
- 21280 }
- 21281
- 21282 /* check for overflow */
- 21283 if (e1->exp >= EXT_MAX) {
- 21284 trap(EFOVFL);
- 21285 /* if caught */
- 21286 /* return signed infinity */
- 21287 e1->exp = EXT_MAX;
- 21288 infinity: e1->m1 = e1->m2 =0L;
- 21289 return;
- 21290 }
- 21291 /* check for underflow */
- 21292 if (e1->exp < EXT_MIN) {
- 21293 trap(EFUNFL);
- 21294 e1->exp = EXT_MIN;
- 21295 goto infinity;
- 21296 }
- 21297 }
- .Op 191 src/lib/float/ngf4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/ngf4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 21300 /*
- 21301 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 21302 See the copyright notice in the ACK home directory, in the file "Copyright".
- 21303 */
- 21304
- 21305 /* $Header: ngf4.c,v 1.7 93/01/05 12:05:57 ceriel Exp $ */
- 21306
- 21307 /*
- 21308 NEGATE A FLOATING POINT (NGF 4)
- 21309 */
- 21310 /********************************************************/
- 21311
- 21312 #include "FP_types.h"
- 21313 #include "get_put.h"
- 21314
- 21315 #define OFF ((FL_MSW_AT_LOW_ADDRESS ? 0 : 2) + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
- 21316 void
- 21317 ngf4(f)
- 21318 SINGLE f;
- 21319 {
- 21320 unsigned char *p;
- 21321
- 21322 if (f != (SINGLE) 0) {
- 21323 p = (unsigned char *) &f + OFF;
- 21324 *p ^= 0x80;
- 21325 }
- 21326 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/ngf8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 21400 /*
- 21401 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 21402 See the copyright notice in the ACK home directory, in the file "Copyright".
- 21403 */
- 21404
- 21405 /* $Header: ngf8.c,v 1.8 93/01/05 12:06:05 ceriel Exp $ */
- 21406
- 21407 /*
- 21408 NEGATE A FLOATING POINT (NGF 8)
- 21409 */
- 21410 /********************************************************/
- 21411
- 21412 #include "FP_types.h"
- 21413 #include "get_put.h"
- 21414
- 21415 #define OFF ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
- 21416
- 21417 void
- 21418 ngf8(f)
- 21419 DOUBLE f;
- .Ep 192 src/lib/float/ngf8.c
- 21420 {
- 21421 unsigned char *p;
- 21422
- 21423 if (f.d[0] != 0 || f.d[1] != 0) {
- 21424 p = (unsigned char *) &f + OFF;
- 21425 *p ^= 0x80;
- 21426 }
- 21427 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/nrm_ext.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 21500 /*
- 21501 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 21502 See the copyright notice in the ACK home directory, in the file "Copyright".
- 21503 */
- 21504
- 21505 /* $Header: nrm_ext.c,v 1.5 93/01/05 12:06:11 ceriel Exp $ */
- 21506
- 21507 /********************************************************/
- 21508 /*
- 21509 NORMALIZE an EXTENDED FORMAT NUMBER
- 21510 */
- 21511 /********************************************************/
- 21512
- 21513 #include "FP_shift.h"
- 21514 #include "FP_types.h"
- 21515
- 21516 void
- 21517 nrm_ext(e1)
- 21518 EXTEND *e1;
- 21519 {
- 21520 /* we assume that the mantissa != 0 */
- 21521 /* if it is then just return */
- 21522 /* to let it be a problem elsewhere */
- 21523 /* THAT IS, The exponent is not set to */
- 21524 /* zero. If we don't test here an */
- 21525 /* infinite loop is generated when */
- 21526 /* mantissa is zero */
- 21527
- 21528 if ((e1->m1 | e1->m2) == 0L)
- 21529 return;
- 21530
- 21531 /* if top word is zero mov low word */
- 21532 /* to top word, adjust exponent value */
- 21533 if (e1->m1 == 0L) {
- 21534 e1->m1 = e1->m2;
- 21535 e1->m2 = 0L;
- 21536 e1->exp -= 32;
- 21537 }
- 21538 if ((e1->m1 & NORMBIT) == 0) {
- 21539 unsigned long l = ((unsigned long)NORMBIT >> 1);
- 21540 int cnt = -1;
- 21541
- 21542 while (! (l & e1->m1)) {
- 21543 l >>= 1;
- 21544 cnt--;
- .Op 193 src/lib/float/nrm_ext.c
- 21545 }
- 21546 e1->exp += cnt;
- 21547 b64_sft(&(e1->mantissa), cnt);
- 21548 }
- 21549 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/sbf4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 21600 /*
- 21601 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 21602 See the copyright notice in the ACK home directory, in the file "Copyright".
- 21603 */
- 21604
- 21605 /* $Header: sbf4.c,v 1.8 93/01/05 12:06:16 ceriel Exp $ */
- 21606
- 21607 /*
- 21608 SUBTRACT TWO FLOATS - SINGLE Precision (SBF 4)
- 21609 */
- 21610
- 21611 #include "FP_types.h"
- 21612
- 21613 void
- 21614 sbf4(s2,s1)
- 21615 SINGLE s1,s2;
- 21616 {
- 21617 EXTEND e1,e2;
- 21618
- 21619 if (s2 == (SINGLE) 0) {
- 21620 return;
- 21621 }
- 21622 extend(&s1,&e1,sizeof(SINGLE));
- 21623 extend(&s2,&e2,sizeof(SINGLE));
- 21624 sub_ext(&e1,&e2);
- 21625 compact(&e1,&s1,sizeof(SINGLE));
- 21626 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/sbf8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 21700 /*
- 21701 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 21702 See the copyright notice in the ACK home directory, in the file "Copyright".
- 21703 */
- 21704
- 21705 /* $Header: sbf8.c,v 1.8 93/01/05 12:06:22 ceriel Exp $ */
- 21706
- 21707 /*
- 21708 SUBTRACT TWO FLOATS - DOUBLE Precision (SBF 8)
- 21709 */
- .Ep 194 src/lib/float/sbf8.c
- 21710
- 21711 #include "FP_types.h"
- 21712
- 21713 void
- 21714 sbf8(s2,s1)
- 21715 DOUBLE s1,s2;
- 21716 {
- 21717 EXTEND e1, e2;
- 21718
- 21719 if (s2.d[0] == 0 && s2.d[1] == 0) {
- 21720 return;
- 21721 }
- 21722 extend(&s1.d[0],&e1,sizeof(DOUBLE));
- 21723 extend(&s2.d[0],&e2,sizeof(DOUBLE));
- 21724 sub_ext(&e1,&e2);
- 21725 compact(&e1,&s1.d[0],sizeof(DOUBLE));
- 21726 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/sft_ext.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 21800 /*
- 21801 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 21802 See the copyright notice in the ACK home directory, in the file "Copyright".
- 21803 */
- 21804
- 21805 /* $Header: sft_ext.c,v 1.5 93/01/05 12:06:28 ceriel Exp $ */
- 21806
- 21807 /*
- 21808 SHIFT TWO EXTENDED NUMBERS INTO PROPER
- 21809 ALIGNMENT FOR ADDITION (exponents are equal)
- 21810 Numbers should not be zero on entry.
- 21811 */
- 21812
- 21813 #include "FP_types.h"
- 21814
- 21815 void
- 21816 sft_ext(e1,e2)
- 21817 EXTEND *e1,*e2;
- 21818 {
- 21819 register EXTEND *s;
- 21820 register int diff;
- 21821
- 21822 diff = e1->exp - e2->exp;
- 21823
- 21824 if (!diff)
- 21825 return; /* exponents are equal */
- 21826
- 21827 if (diff < 0) { /* e2 is larger */
- 21828 /* shift e1 */
- 21829 diff = -diff;
- 21830 s = e1;
- 21831 }
- 21832 else /* e1 is larger */
- 21833 /* shift e2 */
- 21834 s = e2;
- .Op 195 src/lib/float/sft_ext.c
- 21835
- 21836 s->exp += diff;
- 21837 b64_sft(&(s->mantissa), diff);
- 21838 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/shifter.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 21900 /*
- 21901 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 21902 See the copyright notice in the ACK home directory, in the file "Copyright".
- 21903 */
- 21904
- 21905 /* $Header: shifter.c,v 1.6 93/01/05 12:06:34 ceriel Exp $ */
- 21906
- 21907 # include "FP_types.h"
- 21908
- 21909 void
- 21910 b64_sft(e1,n)
- 21911 B64 *e1;
- 21912 int n;
- 21913 {
- 21914 if (n > 0) {
- 21915 if (n > 63) {
- 21916 e1->l_32 = 0;
- 21917 e1->h_32 = 0;
- 21918 return;
- 21919 }
- 21920 if (n >= 32) {
- 21921 e1->l_32 = e1->h_32;
- 21922 e1->h_32 = 0;
- 21923 n -= 32;
- 21924 }
- 21925 if (n > 0) {
- 21926 e1->l_32 >>= n;
- 21927 if (e1->h_32 != 0) {
- 21928 e1->l_32 |= (e1->h_32 << (32 - n));
- 21929 e1->h_32 >>= n;
- 21930 }
- 21931 }
- 21932 return;
- 21933 }
- 21934 n = -n;
- 21935 if (n > 0) {
- 21936 if (n > 63) {
- 21937 e1->l_32 = 0;
- 21938 e1->h_32 = 0;
- 21939 return;
- 21940 }
- 21941 if (n >= 32) {
- 21942 e1->h_32 = e1->l_32;
- 21943 e1->l_32 = 0;
- 21944 n -= 32;
- 21945 }
- 21946 if (n > 0) {
- 21947 e1->h_32 <<= n;
- 21948 if (e1->l_32 != 0) {
- 21949 e1->h_32 |= (e1->l_32 >> (32 - n));
- .Ep 196 src/lib/float/shifter.c
- 21950 e1->l_32 <<= n;
- 21951 }
- 21952 }
- 21953 }
- 21954 }
- 21956 void
- 21957 b64_lsft(e1)
- 21958 B64 *e1;
- 21959 {
- 21960 /* shift left 1 bit */
- 21961 e1->h_32 <<= 1;
- 21962 if (e1->l_32 & 0x80000000L) e1->h_32 |= 1;
- 21963 e1->l_32 <<= 1;
- 21964 }
- 21966 void
- 21967 b64_rsft(e1)
- 21968 B64 *e1;
- 21969 {
- 21970 /* shift right 1 bit */
- 21971 e1->l_32 >>= 1;
- 21972 if (e1->h_32 & 1) e1->l_32 |= 0x80000000L;
- 21973 e1->h_32 >>= 1;
- 21974 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/sub_ext.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 22000 /*
- 22001 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 22002 See the copyright notice in the ACK home directory, in the file "Copyright".
- 22003 */
- 22004
- 22005 /* $Header: sub_ext.c,v 1.6 93/01/05 12:06:40 ceriel Exp $ */
- 22006
- 22007 /*
- 22008 SUBTRACT 2 EXTENDED FORMAT NUMBERS
- 22009 */
- 22010
- 22011 #include "FP_types.h"
- 22012
- 22013 void
- 22014 sub_ext(e1,e2)
- 22015 EXTEND *e1,*e2;
- 22016 {
- 22017 if ((e2->m1 | e2->m2) == 0L) {
- 22018 return;
- 22019 }
- 22020 if ((e1->m1 | e1->m2) == 0L) {
- 22021 *e1 = *e2;
- 22022 e1->sign = e2->sign ? 0 : 1;
- 22023 return;
- 22024 }
- .Op 197 src/lib/float/sub_ext.c
- 22025 sft_ext(e1, e2);
- 22026 if (e1->sign != e2->sign) {
- 22027 /* e1 - e2 = e1 + (-e2) */
- 22028 if (b64_add(&e1->mantissa,&e2->mantissa)) { /* addition carry */
- 22029 b64_rsft(&e1->mantissa); /* shift mantissa one bit RIGHT */
- 22030 e1->m1 |= 0x80000000L; /* set max bit */
- 22031 e1->exp++; /* increase the exponent */
- 22032 }
- 22033 }
- 22034 else if (e2->m1 > e1->m1 ||
- 22035 (e2->m1 == e1->m1 && e2->m2 > e1->m2)) {
- 22036 /* abs(e2) > abs(e1) */
- 22037 if (e1->m2 > e2->m2) {
- 22038 e2->m1 -= 1; /* carry in */
- 22039 }
- 22040 e2->m1 -= e1->m1;
- 22041 e2->m2 -= e1->m2;
- 22042 *e1 = *e2;
- 22043 e1->sign = e2->sign ? 0 : 1;
- 22044 }
- 22045 else {
- 22046 if (e2->m2 > e1->m2)
- 22047 e1->m1 -= 1; /* carry in */
- 22048 e1->m1 -= e2->m1;
- 22049 e1->m2 -= e2->m2;
- 22050 }
- 22051 nrm_ext(e1);
- 22052 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/zrf4.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 22100 /*
- 22101 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 22102 See the copyright notice in the ACK home directory, in the file "Copyright".
- 22103 */
- 22104
- 22105 /* $Header: zrf4.c,v 1.5 93/01/05 12:06:46 ceriel Exp $ */
- 22106
- 22107 /*
- 22108 return a zero float (ZRF 4)
- 22109 */
- 22110
- 22111 #include "FP_types.h"
- 22112
- 22113 void
- 22114 zrf4(l)
- 22115 SINGLE *l;
- 22116 {
- 22117 *l = 0L;
- 22118 }
- .Ep 198 src/lib/float/zrf8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/zrf8.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 22200 /*
- 22201 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 22202 See the copyright notice in the ACK home directory, in the file "Copyright".
- 22203 */
- 22204
- 22205 /* $Header: zrf8.c,v 1.4 93/01/05 12:06:52 ceriel Exp $ */
- 22206
- 22207 /*
- 22208 return a zero double (ZRF 8)
- 22209 */
- 22210
- 22211 #include "FP_types.h"
- 22212
- 22213 void
- 22214 zrf8(z)
- 22215 DOUBLE *z;
- 22216 {
- 22217
- 22218 z->d[0] = 0L;
- 22219 z->d[1] = 0L;
- 22220 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/zrf_ext.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 22300 /*
- 22301 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 22302 See the copyright notice in the ACK home directory, in the file "Copyright".
- 22303 */
- 22304
- 22305 /* $Header: zrf_ext.c,v 1.5 93/01/05 12:06:58 ceriel Exp $ */
- 22306
- 22307 /*
- 22308 ZERO and return EXTEND FORMAT FLOAT
- 22309 */
- 22310
- 22311 #include "FP_types.h"
- 22312
- 22313 void
- 22314 zrf_ext(e)
- 22315 EXTEND *e;
- 22316 {
- 22317 e->m1 = 0;
- 22318 e->m2 = 0;
- 22319 e->exp = 0;
- 22320 e->sign = 0;
- 22321 }
- .Op 199 src/lib/float/fptrp.s
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/float/fptrp.s
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 22400 #
- 22401 .sect .text; .sect .rom; .sect .data; .sect .bss
- 22402 .define __fptrp
- 22403 .sect .text
- 22404 __fptrp:
- 22405 #if __i386
- 22406 push ebp
- 22407 mov ebp, esp
- 22408 mov eax, 8(bp)
- 22409 call .Xtrp
- 22410 leave
- 22411 ret
- 22412 #else /* i86 */
- 22413 push bp
- 22414 mov bp, sp
- 22415 mov ax, 4(bp)
- 22416 call .Xtrp
- 22417 jmp .cret
- 22418 #endif
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/fphook/fltpr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 22500 #include <stdio.h>
- 22501 #include <stdlib.h>
- 22502 #include "../stdio/loc_incl.h"
- 22503
- 22504 int _fp_hook = 1;
- 22505
- 22506 char *
- 22507 _f_print(va_list *ap, int flags, char *s, char c, int precision)
- 22508 {
- 22509 fprintf(stderr,"cannot print floating pointn");
- 22510 exit(EXIT_FAILURE);
- 22511 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/fphook/fphook.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 22600 /*
- 22601 * fltpr.c - print floating point numbers
- 22602 */
- 22603 /* $Header: fltpr.c,v 1.4 90/02/27 16:47:40 eck Exp $ */
- 22604
- 22605 #ifndef NOFLOAT
- 22606 #include <string.h>
- 22607 #include <stdarg.h>
- 22608 #include "../stdio/loc_incl.h"
- 22609 int _fp_hook = 1;
- .Ep 200 src/lib/fphook/fphook.c
- 22610
- 22611 static char *
- 22612 _pfloat(long double r, register char *s, int n, int flags)
- 22613 {
- 22614 register char *s1;
- 22615 int sign, dp;
- 22616 register int i;
- 22617
- 22618 s1 = _fcvt(r, n, &dp, &sign);
- 22619 if (sign)
- 22620 *s++ = '-';
- 22621 else if (flags & FL_SIGN)
- 22622 *s++ = '+';
- 22623 else if (flags & FL_SPACE)
- 22624 *s++ = ' ';
- 22625
- 22626 if (dp<=0)
- 22627 *s++ = '0';
- 22628 for (i=dp; i>0; i--)
- 22629 if (*s1) *s++ = *s1++;
- 22630 else *s++ = '0';
- 22631 if (((i=n) > 0) || (flags & FL_ALT))
- 22632 *s++ = '.';
- 22633 while (++dp <= 0) {
- 22634 if (--i<0)
- 22635 break;
- 22636 *s++ = '0';
- 22637 }
- 22638 while (--i >= 0)
- 22639 if (*s1) *s++ = *s1++;
- 22640 else *s++ = '0';
- 22641 return s;
- 22642 }
- 22644 static char *
- 22645 _pscien(long double r, register char *s, int n, int flags)
- 22646 {
- 22647 int sign, dp;
- 22648 register char *s1;
- 22649
- 22650 s1 = _ecvt(r, n + 1, &dp, &sign);
- 22651 if (sign)
- 22652 *s++ = '-';
- 22653 else if (flags & FL_SIGN)
- 22654 *s++ = '+';
- 22655 else if (flags & FL_SPACE)
- 22656 *s++ = ' ';
- 22657
- 22658 *s++ = *s1++;
- 22659 if ((n > 0) || (flags & FL_ALT))
- 22660 *s++ = '.';
- 22661 while (--n >= 0)
- 22662 if (*s1) *s++ = *s1++;
- 22663 else *s++ = '0';
- 22664 *s++ = 'e';
- 22665 if ( r != 0 ) --dp ;
- 22666 if ( dp<0 ) {
- 22667 *s++ = '-' ; dp= -dp ;
- 22668 } else {
- 22669 *s++ = '+' ;
- .Op 201 src/lib/fphook/fphook.c
- 22670 }
- 22671 if (dp >= 100) {
- 22672 *s++ = '0' + (dp / 100);
- 22673 dp %= 100;
- 22674 }
- 22675 *s++ = '0' + (dp/10);
- 22676 *s++ = '0' + (dp%10);
- 22677 return s;
- 22678 }
- 22680 #define NDIGINEXP(exp) (((exp) >= 100 || (exp) <= -100) ? 3 : 2)
- 22681 #define LOW_EXP -4
- 22682 #define USE_EXP(exp, ndigits) (((exp) < LOW_EXP + 1) || (exp >= ndigits + 1))
- 22683
- 22684 static char *
- 22685 _gcvt(long double value, int ndigit, char *s, int flags)
- 22686 {
- 22687 int sign, dp;
- 22688 register char *s1, *s2;
- 22689 register int i;
- 22690 register int nndigit = ndigit;
- 22691
- 22692 s1 = _ecvt(value, ndigit, &dp, &sign);
- 22693 s2 = s;
- 22694 if (sign) *s2++ = '-';
- 22695 else if (flags & FL_SIGN)
- 22696 *s2++ = '+';
- 22697 else if (flags & FL_SPACE)
- 22698 *s2++ = ' ';
- 22699
- 22700 if (!(flags & FL_ALT))
- 22701 for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--)
- 22702 nndigit--;
- 22703
- 22704 if (USE_EXP(dp,ndigit)) {
- 22705 /* Use E format */
- 22706 dp--;
- 22707 *s2++ = *s1++;
- 22708 if ((nndigit > 1) || (flags & FL_ALT)) *s2++ = '.';
- 22709 while (--nndigit > 0) *s2++ = *s1++;
- 22710 *s2++ = 'e';
- 22711 if (dp < 0) {
- 22712 *s2++ = '-';
- 22713 dp = -dp;
- 22714 }
- 22715 else *s2++ = '+';
- 22716 s2 += NDIGINEXP(dp);
- 22717 *s2 = 0;
- 22718 for (i = NDIGINEXP(dp); i > 0; i--) {
- 22719 *--s2 = dp % 10 + '0';
- 22720 dp /= 10;
- 22721 }
- 22722 return s;
- 22723 }
- 22724 /* Use f format */
- 22725 if (dp <= 0) {
- 22726 if (*s1 != '0') {
- 22727 /* otherwise the whole number is 0 */
- 22728 *s2++ = '0';
- 22729 *s2++ = '.';
- .Ep 202 src/lib/fphook/fphook.c
- 22730 }
- 22731 while (dp < 0) {
- 22732 dp++;
- 22733 *s2++ = '0';
- 22734 }
- 22735 }
- 22736 for (i = 1; i <= nndigit; i++) {
- 22737 *s2++ = *s1++;
- 22738 if (i == dp) *s2++ = '.';
- 22739 }
- 22740 if (i <= dp) {
- 22741 while (i++ <= dp) *s2++ = '0';
- 22742 *s2++ = '.';
- 22743 }
- 22744 if ((s2[-1]=='.') && !(flags & FL_ALT)) s2--;
- 22745 *s2 = ' ';
- 22746 return s;
- 22747 }
- 22749 char *
- 22750 _f_print(va_list *ap, int flags, char *s, char c, int precision)
- 22751 {
- 22752 register char *old_s = s;
- 22753 long double ld_val;
- 22754
- 22755 if (flags & FL_LONGDOUBLE) ld_val = va_arg(*ap, long double);
- 22756 else ld_val = (long double) va_arg(*ap, double);
- 22757
- 22758 switch(c) {
- 22759 case 'f':
- 22760 s = _pfloat(ld_val, s, precision, flags);
- 22761 break;
- 22762 case 'e':
- 22763 case 'E':
- 22764 s = _pscien(ld_val, s, precision , flags);
- 22765 break;
- 22766 case 'g':
- 22767 case 'G':
- 22768 s = _gcvt(ld_val, precision, s, flags);
- 22769 s += strlen(s);
- 22770 break;
- 22771 }
- 22772 if ( c == 'E' || c == 'G') {
- 22773 while (*old_s && *old_s != 'e') old_s++;
- 22774 if (*old_s == 'e') *old_s = 'E';
- 22775 }
- 22776 return s;
- 22777 }
- 22778 #endif /* NOFLOAT */
- 22779 /* $Header: strtod.c,v 1.3 90/09/07 11:00:24 eck Exp $ */
- 22780
- 22781 #include <stdlib.h>
- 22782 #include "../ansi/ext_fmt.h"
- 22783
- 22784 void _str_ext_cvt(const char *s, char **ss, struct EXTEND *e);
- 22785 double _ext_dbl_cvt(struct EXTEND *e);
- 22786
- 22787 double
- 22788 strtod(const char *p, char **pp)
- 22789 {
- .Op 203 src/lib/fphook/fphook.c
- 22790 struct EXTEND e;
- 22791
- 22792 _str_ext_cvt(p, pp, &e);
- 22793 return _ext_dbl_cvt(&e);
- 22794 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/fphook/strtod.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 22800 #include <stdio.h>
- 22801 #include <stdlib.h>
- 22802
- 22803 double
- 22804 strtod(const char *p, char **pp)
- 22805 {
- 22806 fprintf(stderr,"cannot print floating pointn");
- 22807 exit(EXIT_FAILURE);
- 22808 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/ether.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 22900 /* $Id: ether.h,v 2.2 89/10/23 15:42:19 dupuy Exp $ */
- 22901
- 22902 /* Interface definitions for ethernet access library */
- 22903
- 22904 typedef union etheraddr
- 22905 {
- 22906 unsigned char bytes[6]; /* byteorder safe initialization */
- 22907 unsigned short shorts[3]; /* force 2-byte alignment */
- 22908 }
- 22909 ether_addr;
- 22910
- 22911 typedef struct etherpacket
- 22912 {
- 22913 ether_addr dest;
- 22914 ether_addr src;
- 22915 unsigned char type[2]; /* in network byte order! */
- 22916 unsigned short pktlen; /* length of pktbuf ONLY */
- 22917 char *pktbuf;
- 22918 }
- 22919 ether_packet;
- 22920
- 22921 typedef struct ethervec
- 22922 {
- 22923 ether_addr dest;
- 22924 ether_addr src;
- 22925 unsigned char type[2]; /* in network byte order! */
- 22926 unsigned short iovcnt; /* number of iovec to use */
- 22927 struct iovec *iov; /* ptr to array of iovec */
- 22928 }
- 22929 ether_vec;
- .Ep 204 src/lib/ip/ether.h
- 22930
- 22931 #ifndef __ETHER_BCAST_ADDR__
- 22932 extern ether_addr ether_bcast_addr;
- 22933 #endif
- 22934
- 22935 #ifdef __STDC__
- 22936
- 22937 int ether_open (char *name, unsigned type, ether_addr * address);
- 22938
- 22939 ether_addr *ether_address (int fd, ether_addr * address);
- 22940
- 22941 ether_addr *ether_intfaddr (char *intf, ether_addr * address);
- 22942
- 22943 char **ether_interfaces (void);
- 22944
- 22945 int ether_write (int fd, ether_packet * packet);
- 22946
- 22947 int ether_writev (int fd, ether_vec * packet);
- 22948
- 22949 int ether_read (int fd, ether_packet * packet);
- 22950
- 22951 int ether_readv (int fd, ether_vec * packet);
- 22952
- 22953 int ether_blocking (int fd, int state);
- 22954
- 22955 int ether_send_self (int fd);
- 22956
- 22957 int ether_mcast_self (int fd);
- 22958
- 22959 int ether_bcast_self (int fd);
- 22960
- 22961 char *ether_ntoa (ether_addr *);
- 22962
- 22963 ether_addr *ether_aton (char *);
- 22964
- 22965 #ifdef __GNUC__
- 22966
- 22967 /*
- 22968 * Avoid stupid warnings if structs aren't defined
- 22969 */
- 22970
- 22971 typedef struct in_addr *_ether_NoNsEnSe;
- 22972 typedef struct hostent *_ether_nOnSeNsE;
- 22973
- 22974 #endif
- 22975
- 22976 char *ether_e2a (ether_addr *, char *);
- 22977
- 22978 ether_addr *ether_a2e (char *, ether_addr *);
- 22979
- 22980 struct in_addr *ether_e2ip (ether_addr *, struct in_addr *);
- 22981
- 22982 ether_addr *ether_ip2e (struct in_addr *, ether_addr *);
- 22983
- 22984 char *ether_e2host (ether_addr *, char *);
- 22985
- 22986 ether_addr *ether_host2e (char *, ether_addr *);
- 22987
- 22988 ether_addr *ether_hostent2e (struct hostent *, ether_addr *);
- 22989
- .Op 205 src/lib/ip/ether.h
- 22990 #else
- 22991
- 22992 int ether_open ();
- 22993 ether_addr *ether_address ();
- 22994 ether_addr *ether_intfaddr ();
- 22995 char **ether_interfaces ();
- 22996 int ether_write ();
- 22997 int ether_writev ();
- 22998 int ether_read ();
- 22999 int ether_readv ();
- 23000 int ether_blocking ();
- 23001 int ether_send_self ();
- 23002 int ether_mcast_self ();
- 23003 int ether_bcast_self ();
- 23004
- 23005 char *ether_ntoa ();
- 23006 ether_addr *ether_aton ();
- 23007 char *ether_e2a ();
- 23008 ether_addr *ether_a2e ();
- 23009 struct in_addr *ether_e2ip ();
- 23010 ether_addr *ether_ip2e ();
- 23011 char *ether_e2host ();
- 23012 ether_addr *ether_host2e ();
- 23013 ether_addr *ether_hostent2e ();
- 23014
- 23015 #endif
- 23016
- 23017 #undef ether_cmp /* lose def from netinet/if_ether.h */
- 23018
- 23019 #define ether_cmp(addr1,addr2)
- 23020 ((addr1)->shorts[0] != (addr2)->shorts[0]
- 23021 || (addr1)->shorts[1] != (addr2)->shorts[1]
- 23022 || (addr1)->shorts[2] != (addr2)->shorts[2])
- 23023
- 23024 #define ETHERSTRLEN 18 /* max length of "xx:xx:xx:xx:xx:xx" */
- 23025
- 23026 #ifdef NOFILE /* i.e. we have included sys/param.h */
- 23027 #ifndef MAXHOSTNAMELEN /* but MAXHOSTNAMELEN still isnt set */
- 23028 #define MAXHOSTNAMELEN 64
- 23029 #endif
- 23030 #endif
- 23031
- 23032 /* should be defined in terms of ether_packet struct; need offsetof() macro */
- 23033
- 23034 #define ETHER_DST 0
- 23035 #define ETHER_SRC 6
- 23036 #define ETHER_TYPE 12
- 23037 #define ETHER_PKT 14
- 23038 #define ETHER_MIN 46
- 23039 #define ETHER_MAX 1500
- 23040
- 23041 #define ETHER_MINTYPE 0x5DD /* lowest protocol not valid IEEE802 */
- 23042 #define ETHER_MAXTYPE 0xFFFF /* largest possible protocol */
- 23043
- 23044 #define ETHER_MCAST(addr) (((unsigned char *) (addr))[0] & 0x01)
- 23045
- 23046 #ifdef NT_ALLTYPES
- 23047 #define ETHER_ALLTYPES NT_ALLTYPES
- 23048 #else
- 23049 #define ETHER_ALLTYPES ((unsigned) -1)
- .Ep 206 src/lib/ip/ether.h
- 23050 #endif
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/domainname.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 23100 /*
- 23101 domainname.c
- 23102 */
- 23103
- 23104 #include <stdio.h>
- 23105 #include <string.h>
- 23106 #include <net/netlib.h>
- 23107
- 23108 int getdomainname(domain, size)
- 23109 char *domain;
- 23110 size_t size;
- 23111 {
- 23112 FILE *domainfile;
- 23113 char *line;
- 23114
- 23115 domainfile= fopen("/etc/domainname", "r");
- 23116 if (!domainfile)
- 23117 {
- 23118 return -1;
- 23119 }
- 23120
- 23121 line= fgets(domain, size, domainfile);
- 23122 fclose(domainfile);
- 23123 if (!line)
- 23124 return -1;
- 23125 line= strchr(domain, 'n');
- 23126 if (line)
- 23127 *line= ' ';
- 23128 return 0;
- 23129 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/ether_line.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 23200 /*
- 23201 ** ETHER_LINE
- 23202 **
- 23203 ** This routine parses the array pointed to by "line" (which should be
- 23204 ** from a file in the format of /etc/ethers) and returns in "eaddr" the
- 23205 ** ethernet address at the start of the line and the corresponding host
- 23206 ** name in "hostname". It assumes either tabs or spaces separate the
- 23207 ** two. The buffer pointed to by "hostname" must be big enough to hold
- 23208 ** the host name plus a NULL byte.
- 23209 ** The function returns 0 on success and 1 on failure.
- .Op 207 src/lib/ip/ether_line.c
- 23210 ** Arguments are assumed sensible. Null pointers will probably cause
- 23211 ** exceptions.
- 23212 ** Author: Gregory J. Sharp, July 1990
- 23213 ** Adapted to MINIX: Philip Homburg, May 1992
- 23214 */
- 23215
- 23216 #include <sys/types.h>
- 23217 #include <ctype.h>
- 23218 #include <stdlib.h>
- 23219 #include <net/gen/ether.h>
- 23220 #include <net/gen/if_ether.h>
- 23221
- 23222 int
- 23223 ether_line(line, eaddr, hostname)
- 23224 char * line;
- 23225 struct ether_addr * eaddr;
- 23226 char * hostname;
- 23227 {
- 23228 register int i;
- 23229 register unsigned long val;
- 23230
- 23231 /* skip leading white space */
- 23232 while (*line != 'n' && (*line == ' ' || *line == 't'))
- 23233 line++;
- 23234
- 23235 /* read the ethernet address */
- 23236 for (i = 0; i < 5; i++)
- 23237 {
- 23238 val = (unsigned long) strtol(line, &line, 16);
- 23239 if (val > 255 || *line++ != ':')
- 23240 return 1;
- 23241 eaddr->ea_addr[i] = val & 0xff;
- 23242 }
- 23243 val = (unsigned long) strtol(line, &line, 16);
- 23244 if (val > 255 || (*line != ' ' && *line != 't'))
- 23245 return 1;
- 23246 eaddr->ea_addr[i] = val & 0xff;
- 23247
- 23248 /* skip leading white space */
- 23249 while (*line != 'n' && (*line == ' ' || *line == 't'))
- 23250 line++;
- 23251
- 23252 /* read in the hostname */
- 23253 while (!isspace(*line))
- 23254 *hostname++ = *line++;
- 23255 *hostname = ' ';
- 23256 return 0;
- 23257 }
- .Ep 208 src/lib/ip/ethera2n.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/ethera2n.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 23300 /*
- 23301 ethera2n.c
- 23302
- 23303 Convert an ASCII string with an ethernet address into a struct ether_addr.
- 23304
- 23305 Created: Nov 17, 1992 by Philip Homburg
- 23306 */
- 23307
- 23308 #include <sys/types.h>
- 23309 #include <stdlib.h>
- 23310 #include <net/netlib.h>
- 23311 #include <net/gen/ether.h>
- 23312 #include <net/gen/if_ether.h>
- 23313
- 23314 struct ether_addr *ether_aton(s)
- 23315 char *s;
- 23316 {
- 23317 static struct ether_addr ea;
- 23318
- 23319 int i;
- 23320 long v;
- 23321 char *check;
- 23322
- 23323 if (s == NULL)
- 23324 return NULL;
- 23325
- 23326 for (i=0; i<6; i++)
- 23327 {
- 23328 v= strtol(s, &check, 16);
- 23329 if (v<0 || v>255)
- 23330 return NULL;
- 23331 if ((i<5 && check[0] != ':') || (i == 5 && check[0] != ' '))
- 23332 return NULL;
- 23333 ea.ea_addr[i]= v;
- 23334 s= check+1;
- 23335 }
- 23336 return &ea;
- 23337 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/ethere2a.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 23400 /* $Id: ethere2a.c,v 2.1 89/10/23 15:42:28 dupuy Exp $ */
- 23401 /* This file was part of the etherlib package. */
- 23402
- 23403 #include <stdio.h>
- 23404
- 23405 #ifdef _MINIX
- 23406 #include <sys/types.h>
- 23407 #include <stdlib.h>
- 23408
- 23409 #include <net/gen/ether.h>
- .Op 209 src/lib/ip/ethere2a.c
- 23410 #include <net/gen/if_ether.h>
- 23411
- 23412 #define ETHERSTRLEN 18 /* max length of "xx:xx:xx:xx:xx:xx" */
- 23413 #define ether_addr ether_addr_t
- 23414 #define bytes ea_addr
- 23415 char *ether_e2a _ARGS(( ether_addr_t *a, char *e ));
- 23416 #else
- 23417 #include "libether.h"
- 23418 #endif
- 23419
- 23420 char *
- 23421 ether_e2a (addr, estring)
- 23422 ether_addr *addr;
- 23423 char *estring;
- 23424 {
- 23425 #ifdef lint
- 23426 char *sprintf ();
- 23427 #endif
- 23428 if (estring == NULL)
- 23429 estring = (char *) malloc (ETHERSTRLEN);
- 23430
- 23431 if (estring != NULL)
- 23432 (void) sprintf (estring, "%x:%x:%x:%x:%x:%x",
- 23433 addr->bytes[0], addr->bytes[1], addr->bytes[2],
- 23434 addr->bytes[3], addr->bytes[4], addr->bytes[5]);
- 23435 return (estring);
- 23436 }
- 23438 #ifndef ETHERDB
- 23439
- 23440 char *
- 23441 ether_ntoa (addr)
- 23442 ether_addr *addr;
- 23443 {
- 23444 static char estring[ETHERSTRLEN];
- 23445
- 23446 return (ether_e2a (addr, estring));
- 23447 }
- 23449 #endif
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/etherh2n.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 23500 /*
- 23501 etherh2n.c
- 23502
- 23503 Created: May 20, 1992 by Philip Homburg
- 23504 */
- 23505
- 23506 #include <stdio.h>
- 23507 #include <string.h>
- 23508 #include <net/gen/if_ether.h>
- 23509
- .Ep 210 src/lib/ip/etherh2n.c
- 23510 int
- 23511 ether_hostton(hostname, e)
- 23512 char *hostname;
- 23513 struct ether_addr *e;
- 23514 {
- 23515 FILE *etherf;
- 23516 char b[256], hn[256];
- 23517
- 23518 etherf= fopen(_PATH_ETHERS, "r");
- 23519 if (etherf == NULL)
- 23520 return 1;
- 23521
- 23522 while(fgets(b, sizeof(b), etherf) != NULL)
- 23523 {
- 23524 if (ether_line(b, e, hn) == 0 && strcmp(hn, hostname) == 0)
- 23525 {
- 23526 fclose(etherf);
- 23527 return 0;
- 23528 }
- 23529 }
- 23530 fclose(etherf);
- 23531 return 1;
- 23532 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/ethern2h.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 23600 /*
- 23601 ethern2h.c
- 23602
- 23603 Created: Nov 12, 1992 by Philip Homburg
- 23604 */
- 23605
- 23606 #include <sys/types.h>
- 23607 #include <stdio.h>
- 23608 #include <string.h>
- 23609 #include <net/gen/ether.h>
- 23610 #include <net/gen/if_ether.h>
- 23611
- 23612 int
- 23613 ether_ntohost(hostname, e)
- 23614 char *hostname;
- 23615 struct ether_addr *e;
- 23616 {
- 23617 FILE *etherf;
- 23618 char b[256];
- 23619 struct ether_addr e_tmp;
- 23620
- 23621 etherf= fopen(_PATH_ETHERS, "r");
- 23622 if (etherf == NULL)
- 23623 return 1;
- 23624
- 23625 while(fgets(b, sizeof(b), etherf) != NULL)
- 23626 {
- 23627 if (ether_line(b, &e_tmp, hostname) == 0 &&
- 23628 memcmp(&e_tmp, e, sizeof(e_tmp)) == 0)
- 23629 {
- .Op 211 src/lib/ip/ethern2h.c
- 23630 fclose(etherf);
- 23631 return 0;
- 23632 }
- 23633 }
- 23634 fclose(etherf);
- 23635 return 1;
- 23636 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/getdomain.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 23700 /* getdomainname() Author: Kees J. Bot
- 23701 * 2 Dec 1994
- 23702 */
- 23703 #define nil 0
- 23704 #include <sys/types.h>
- 23705 #include <sys/utsname.h>
- 23706 #include <unistd.h>
- 23707 #include <string.h>
- 23708
- 23709 int getdomainname(char *domain, size_t size)
- 23710 {
- 23711 char nodename[256];
- 23712 char *dot;
- 23713
- 23714 if (gethostname(nodename, sizeof(nodename)) < 0)
- 23715 return -1;
- 23716 nodename[sizeof(nodename)-1]= 0;
- 23717 if ((dot= strchr(nodename, '.')) == nil) dot= ".";
- 23718
- 23719 strncpy(domain, dot+1, size);
- 23720 if (size > 0) domain[size-1]= 0;
- 23721 return 0;
- 23722 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/gethnmadr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 23800 /*
- 23801 * Copyright (c) 1985, 1988 Regents of the University of California.
- 23802 * All rights reserved.
- 23803 *
- 23804 * Redistribution and use in source and binary forms are permitted
- 23805 * provided that: (1) source distributions retain this entire copyright
- 23806 * notice and comment, and (2) distributions including binaries display
- 23807 * the following acknowledgement: ``This product includes software
- 23808 * developed by the University of California, Berkeley and its contributors''
- 23809 * in the documentation or other materials provided with the distribution
- 23810 * and in all advertising materials mentioning features or use of this
- 23811 * software. Neither the name of the University nor the names of its
- 23812 * contributors may be used to endorse or promote products derived
- 23813 * from this software without specific prior written permission.
- 23814 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- .Ep 212 src/lib/ip/gethnmadr.c
- 23815 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- 23816 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 23817 */
- 23818
- 23819 #if defined(LIBC_SCCS) && !defined(lint)
- 23820 static char sccsid[] = "@(#)gethostnamadr.c 6.41 (Berkeley) 6/1/90";
- 23821 #endif /* LIBC_SCCS and not lint */
- 23822
- 23823 #ifdef _MINIX
- 23824 #include <sys/types.h>
- 23825 #include <ctype.h>
- 23826 #include <errno.h>
- 23827 #include <stdio.h>
- 23828 #include <string.h>
- 23829
- 23830 #include <net/hton.h>
- 23831 #include <net/gen/nameser.h>
- 23832 #include <net/gen/netdb.h>
- 23833 #include <net/gen/in.h>
- 23834 #include <net/gen/inet.h>
- 23835 #include <net/gen/resolv.h>
- 23836 #include <net/gen/socket.h>
- 23837 #else
- 23838 #include <sys/param.h>
- 23839 #include <sys/socket.h>
- 23840 #include <netinet/in.h>
- 23841 #include <ctype.h>
- 23842 #include <netdb.h>
- 23843 #include <stdio.h>
- 23844 #include <errno.h>
- 23845 #include <arpa/inet.h>
- 23846 #include <arpa/nameser.h>
- 23847 #include <resolv.h>
- 23848 #endif /* AMOEABA */
- 23849
- 23850 #define MAXALIASES 35
- 23851 #define MAXADDRS 35
- 23852
- 23853 static char *h_addr_ptrs[MAXADDRS + 1];
- 23854
- 23855 #ifdef _MINIX
- 23856 struct in_addr
- 23857 {
- 23858 ipaddr_t s_addr;
- 23859 };
- 23860 typedef u32_t u_long;
- 23861 typedef u16_t u_short;
- 23862 typedef u8_t u_char;
- 23863 union querybuf;
- 23864
- 23865 extern int dn_skipname _ARGS(( const u_char *comp_dn, const u_char *eom ));
- 23866 #define getshort _getshort
- 23867 static struct hostent *getanswer _ARGS(( union querybuf *answer, int anslen,
- 23868 int iquery ));
- 23869 #define bcmp memcmp
- 23870 #define bcopy(s, d, l) memcpy(d, s, l)
- 23871 #endif /* _MINIX */
- 23872
- 23873 static struct hostent host;
- 23874 static char *host_aliases[MAXALIASES];
- .Op 213 src/lib/ip/gethnmadr.c
- 23875 static char hostbuf[BUFSIZ+1];
- 23876 static struct in_addr host_addr;
- 23877
- 23878 #ifndef _MINIX
- 23879 char *strpbrk();
- 23880 #endif /* !_MINIX */
- 23881
- 23882 #if PACKETSZ > 1024
- 23883 #define MAXPACKET PACKETSZ
- 23884 #else
- 23885 #define MAXPACKET 1024
- 23886 #endif
- 23887
- 23888 typedef union querybuf
- 23889 {
- 23890 dns_hdr_t hdr;
- 23891 u_char buf[MAXPACKET];
- 23892 } querybuf_t;
- 23893
- 23894 typedef union align {
- 23895 long al;
- 23896 char ac;
- 23897 } align_t;
- 23898
- 23899 static struct hostent *
- 23900 getanswer(answer, anslen, iquery)
- 23901 querybuf_t *answer;
- 23902 int anslen;
- 23903 int iquery;
- 23904 {
- 23905 register dns_hdr_t *hp;
- 23906 register u_char *cp;
- 23907 register int n;
- 23908 u_char *eom;
- 23909 char *bp, **ap;
- 23910 int type, class, buflen, ancount, qdcount;
- 23911 int haveanswer, getclass = C_ANY;
- 23912 char **hap;
- 23913
- 23914 eom = answer->buf + anslen;
- 23915 /*
- 23916 * find first satisfactory answer
- 23917 */
- 23918 hp = &answer->hdr;
- 23919 ancount = ntohs(hp->dh_ancount);
- 23920 qdcount = ntohs(hp->dh_qdcount);
- 23921 bp = hostbuf;
- 23922 buflen = sizeof(hostbuf);
- 23923 cp = answer->buf + sizeof(dns_hdr_t);
- 23924 if (qdcount) {
- 23925 if (iquery) {
- 23926 if ((n = dn_expand((u_char *)answer->buf, eom,
- 23927 cp, (u_char *)bp, buflen)) < 0) {
- 23928 h_errno = NO_RECOVERY;
- 23929 return ((struct hostent *) NULL);
- 23930 }
- 23931 cp += n + QFIXEDSZ;
- 23932 host.h_name = bp;
- 23933 n = strlen(bp) + 1;
- 23934 bp += n;
- .Ep 214 src/lib/ip/gethnmadr.c
- 23935 buflen -= n;
- 23936 } else
- 23937 cp += dn_skipname(cp, eom) + QFIXEDSZ;
- 23938 while (--qdcount > 0)
- 23939 cp += dn_skipname(cp, eom) + QFIXEDSZ;
- 23940 } else if (iquery) {
- 23941 if (hp->dh_flag1 & DHF_AA)
- 23942 h_errno = HOST_NOT_FOUND;
- 23943 else
- 23944 h_errno = TRY_AGAIN;
- 23945 return ((struct hostent *) NULL);
- 23946 }
- 23947 ap = host_aliases;
- 23948 *ap = NULL;
- 23949 host.h_aliases = host_aliases;
- 23950 hap = h_addr_ptrs;
- 23951 *hap = NULL;
- 23952 #if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
- 23953 host.h_addr_list = h_addr_ptrs;
- 23954 #endif
- 23955 haveanswer = 0;
- 23956 while (--ancount >= 0 && cp < eom) {
- 23957 if ((n = dn_expand((u_char *)answer->buf, eom, cp, (u_char *)bp,
- 23958 buflen)) < 0)
- 23959 break;
- 23960 cp += n;
- 23961 type = getshort(cp);
- 23962 cp += sizeof(u_short);
- 23963 class = getshort(cp);
- 23964 cp += sizeof(u_short) + sizeof(u_long);
- 23965 n = getshort(cp);
- 23966 cp += sizeof(u_short);
- 23967 if (type == T_CNAME) {
- 23968 cp += n;
- 23969 if (ap >= &host_aliases[MAXALIASES-1])
- 23970 continue;
- 23971 *ap++ = bp;
- 23972 n = strlen(bp) + 1;
- 23973 bp += n;
- 23974 buflen -= n;
- 23975 continue;
- 23976 }
- 23977 if (iquery && type == T_PTR) {
- 23978 if ((n = dn_expand((u8_t *)answer->buf, eom,
- 23979 cp, (u8_t *)bp, buflen)) < 0) {
- 23980 cp += n;
- 23981 continue;
- 23982 }
- 23983 cp += n;
- 23984 host.h_name = bp;
- 23985 return(&host);
- 23986 }
- 23987 if (iquery || type != T_A) {
- 23988 #ifdef DEBUG
- 23989 if (_res.options & RES_DEBUG)
- 23990 printf("unexpected answer type %d, size %dn",
- 23991 type, n);
- 23992 #endif
- 23993 cp += n;
- 23994 continue;
- .Op 215 src/lib/ip/gethnmadr.c
- 23995 }
- 23996 if (haveanswer) {
- 23997 if (n != host.h_length) {
- 23998 cp += n;
- 23999 continue;
- 24000 }
- 24001 if (class != getclass) {
- 24002 cp += n;
- 24003 continue;
- 24004 }
- 24005 } else {
- 24006 host.h_length = n;
- 24007 getclass = class;
- 24008 host.h_addrtype = (class == C_IN) ? AF_INET : AF_UNSPEC;
- 24009 if (!iquery) {
- 24010 host.h_name = bp;
- 24011 bp += strlen(bp) + 1;
- 24012 }
- 24013 }
- 24014
- 24015 bp += (size_t)(sizeof(align_t) -
- 24016 ((u_long)bp % sizeof(align_t)));
- 24017
- 24018 if (bp + n >= &hostbuf[sizeof(hostbuf)]) {
- 24019 #ifdef DEBUG
- 24020 if (_res.options & RES_DEBUG)
- 24021 printf("size (%d) too bign", n);
- 24022 #endif
- 24023 break;
- 24024 }
- 24025 bcopy(cp, *hap++ = bp, n);
- 24026 bp +=n;
- 24027 cp += n;
- 24028 haveanswer++;
- 24029 }
- 24030 if (haveanswer) {
- 24031 *ap = NULL;
- 24032 #if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
- 24033 *hap = NULL;
- 24034 #else
- 24035 host.h_addr = h_addr_ptrs[0];
- 24036 #endif
- 24037 return (&host);
- 24038 } else {
- 24039 h_errno = TRY_AGAIN;
- 24040 return ((struct hostent *) NULL);
- 24041 }
- 24042 }
- 24044 struct hostent *
- 24045 gethostbyname(name)
- 24046 char *name;
- 24047 {
- 24048 querybuf_t buf;
- 24049 register char *cp;
- 24050 int n;
- 24051
- 24052 /*
- 24053 * disallow names consisting only of digits/dots, unless
- 24054 * they end in a dot.
- .Ep 216 src/lib/ip/gethnmadr.c
- 24055 */
- 24056 if (isdigit(name[0]))
- 24057 for (cp = name;; ++cp) {
- 24058 if (!*cp) {
- 24059 if (*--cp == '.')
- 24060 break;
- 24061 /*
- 24062 * All-numeric, no dot at the end.
- 24063 * Fake up a hostent as if we'd actually
- 24064 * done a lookup. What if someone types
- 24065 * 255.255.255.255? The test below will
- 24066 * succeed spuriously... ???
- 24067 */
- 24068 if ((host_addr.s_addr = inet_addr(name)) == -1) {
- 24069 h_errno = HOST_NOT_FOUND;
- 24070 return((struct hostent *) NULL);
- 24071 }
- 24072 host.h_name = name;
- 24073 host.h_aliases = host_aliases;
- 24074 host_aliases[0] = NULL;
- 24075 host.h_addrtype = AF_INET;
- 24076 host.h_length = sizeof(u_long);
- 24077 h_addr_ptrs[0] = (char *)&host_addr;
- 24078 h_addr_ptrs[1] = (char *)0;
- 24079 #if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
- 24080 host.h_addr_list = h_addr_ptrs;
- 24081 #else
- 24082 host.h_addr = h_addr_ptrs[0];
- 24083 #endif
- 24084 return (&host);
- 24085 }
- 24086 if (!isdigit(*cp) && *cp != '.')
- 24087 break;
- 24088 }
- 24089
- 24090 if ((n = res_search(name, C_IN, T_A, buf.buf, sizeof(buf))) < 0) {
- 24091 #ifdef DEBUG
- 24092 if (_res.options & RES_DEBUG)
- 24093 printf("res_search failedn");
- 24094 #endif
- 24095 return ((struct hostent *) NULL);
- 24096 }
- 24097 return (getanswer(&buf, n, 0));
- 24098 }
- 24100 struct hostent *
- 24101 gethostbyaddr(addr, len, type)
- 24102 const char *addr;
- 24103 int len, type;
- 24104 {
- 24105 int n;
- 24106 querybuf_t buf;
- 24107 register struct hostent *hp;
- 24108 char qbuf[MAXDNAME];
- 24109
- 24110 if (type != AF_INET)
- 24111 return ((struct hostent *) NULL);
- 24112 (void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
- 24113 ((unsigned)addr[3] & 0xff),
- 24114 ((unsigned)addr[2] & 0xff),
- .Op 217 src/lib/ip/gethnmadr.c
- 24115 ((unsigned)addr[1] & 0xff),
- 24116 ((unsigned)addr[0] & 0xff));
- 24117 n = res_query(qbuf, C_IN, T_PTR, (u8_t *)&buf, sizeof(buf));
- 24118 if (n < 0) {
- 24119 #ifdef DEBUG
- 24120 if (_res.options & RES_DEBUG)
- 24121 printf("res_query failedn");
- 24122 #endif
- 24123 return ((struct hostent *) NULL);
- 24124 }
- 24125 hp = getanswer(&buf, n, 1);
- 24126 if (hp == NULL)
- 24127 return ((struct hostent *) NULL);
- 24128 hp->h_addrtype = type;
- 24129 hp->h_length = len;
- 24130 h_addr_ptrs[0] = (char *)&host_addr;
- 24131 h_addr_ptrs[1] = (char *)0;
- 24132 host_addr = *(struct in_addr *)addr;
- 24133 #if BSD < 43 && !defined(h_addr) /* new-style hostent structure */
- 24134 hp->h_addr = h_addr_ptrs[0];
- 24135 #endif
- 24136 return(hp);
- 24137 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/gethostent.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 24200 /*
- 24201 * Copyright (c) 1985, 1988 Regents of the University of California.
- 24202 * All rights reserved.
- 24203 *
- 24204 * Redistribution and use in source and binary forms are permitted
- 24205 * provided that: (1) source distributions retain this entire copyright
- 24206 * notice and comment, and (2) distributions including binaries display
- 24207 * the following acknowledgement: ``This product includes software
- 24208 * developed by the University of California, Berkeley and its contributors''
- 24209 * in the documentation or other materials provided with the distribution
- 24210 * and in all advertising materials mentioning features or use of this
- 24211 * software. Neither the name of the University nor the names of its
- 24212 * contributors may be used to endorse or promote products derived
- 24213 * from this software without specific prior written permission.
- 24214 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- 24215 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- 24216 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 24217 */
- 24218
- 24219 #if defined(LIBC_SCCS) && !defined(lint)
- 24220 static char sccsid[] = "@(#)gethostnamadr.c 6.41 (Berkeley) 6/1/90";
- 24221 #endif /* LIBC_SCCS and not lint */
- 24222
- 24223 /* Prefix the functions defined here with underscores to distinguish them
- 24224 * from the newer replacements in the resolver library.
- 24225 */
- 24226 #define sethostent _sethostent
- 24227 #define endhostent _endhostent
- 24228 #define gethostent _gethostent
- 24229 #define gethostbyname _gethostbyname
- .Ep 218 src/lib/ip/gethostent.c
- 24230 #define gethostbyaddr _gethostbyaddr
- 24231
- 24232 #ifdef _MINIX
- 24233 #include <sys/types.h>
- 24234 #include <ctype.h>
- 24235 #include <errno.h>
- 24236 #include <stdio.h>
- 24237 #include <string.h>
- 24238
- 24239 #include <net/hton.h>
- 24240 #include <net/gen/nameser.h>
- 24241 #include <net/gen/netdb.h>
- 24242 #include <net/gen/in.h>
- 24243 #include <net/gen/inet.h>
- 24244 #include <net/gen/resolv.h>
- 24245 #include <net/gen/socket.h>
- 24246 #else
- 24247 #include <sys/param.h>
- 24248 #include <sys/socket.h>
- 24249 #include <netinet/in.h>
- 24250 #include <ctype.h>
- 24251 #include <netdb.h>
- 24252 #include <stdio.h>
- 24253 #include <errno.h>
- 24254 #include <arpa/inet.h>
- 24255 #include <arpa/nameser.h>
- 24256 #include <resolv.h>
- 24257 #endif /* !_MINIX */
- 24258
- 24259 #define MAXALIASES 35
- 24260 #define MAXADDRS 35
- 24261
- 24262 #ifdef _MINIX
- 24263 typedef u32_t u_long;
- 24264 typedef u16_t u_short;
- 24265 typedef u8_t u_char;
- 24266
- 24267 #define bcmp memcmp
- 24268 #endif /* _MINIX */
- 24269
- 24270 static struct hostent host;
- 24271 static char *host_aliases[MAXALIASES];
- 24272 static char hostbuf[BUFSIZ+1];
- 24273 static FILE *hostf = NULL;
- 24274 static u_long hostaddr[(MAXADDRS+sizeof(u_long)-1)/sizeof(u_long)];
- 24275 static char *host_addrs[2];
- 24276 static int stayopen = 0;
- 24277
- 24278 #ifndef _MINIX
- 24279 char *strpbrk();
- 24280 #endif /* !_MINIX */
- 24281
- 24282 void
- 24283 sethostent(f)
- 24284 int f;
- 24285 {
- 24286 if (hostf == NULL)
- 24287 hostf = fopen(_PATH_HOSTS, "r" );
- 24288 else
- 24289 rewind(hostf);
- .Op 219 src/lib/ip/gethostent.c
- 24290 stayopen |= f;
- 24291 }
- 24293 void
- 24294 endhostent()
- 24295 {
- 24296 if (hostf && !stayopen) {
- 24297 (void) fclose(hostf);
- 24298 hostf = NULL;
- 24299 }
- 24300 }
- 24302 struct hostent *
- 24303 gethostent()
- 24304 {
- 24305 char *p;
- 24306 register char *cp, **q;
- 24307
- 24308 if (hostf == NULL && (hostf = fopen(_PATH_HOSTS, "r" )) == NULL)
- 24309 return (NULL);
- 24310 again:
- 24311 if ((p = fgets(hostbuf, BUFSIZ, hostf)) == NULL)
- 24312 return (NULL);
- 24313 if (*p == '#')
- 24314 goto again;
- 24315 cp = strpbrk(p, "#n");
- 24316 if (cp == NULL)
- 24317 goto again;
- 24318 *cp = ' ';
- 24319 cp = strpbrk(p, " t");
- 24320 if (cp == NULL)
- 24321 goto again;
- 24322 *cp++ = ' ';
- 24323 /* THIS STUFF IS INTERNET SPECIFIC */
- 24324 #if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
- 24325 host.h_addr_list = host_addrs;
- 24326 #endif
- 24327 host.h_addr = (char *) hostaddr;
- 24328 *((u_long *)host.h_addr) = inet_addr(p);
- 24329 host.h_length = sizeof (u_long);
- 24330 host.h_addrtype = AF_INET;
- 24331 while (*cp == ' ' || *cp == 't')
- 24332 cp++;
- 24333 host.h_name = cp;
- 24334 q = host.h_aliases = host_aliases;
- 24335 cp = strpbrk(cp, " t");
- 24336 if (cp != NULL)
- 24337 *cp++ = ' ';
- 24338 while (cp && *cp) {
- 24339 if (*cp == ' ' || *cp == 't') {
- 24340 cp++;
- 24341 continue;
- 24342 }
- 24343 if (q < &host_aliases[MAXALIASES - 1])
- 24344 *q++ = cp;
- 24345 cp = strpbrk(cp, " t");
- 24346 if (cp != NULL)
- 24347 *cp++ = ' ';
- 24348 }
- 24349 *q = NULL;
- .Ep 220 src/lib/ip/gethostent.c
- 24350 return (&host);
- 24351 }
- 24353 struct hostent *
- 24354 gethostbyname(name)
- 24355 char *name;
- 24356 {
- 24357 register struct hostent *p;
- 24358 register char **cp;
- 24359
- 24360 sethostent(0);
- 24361 while (p = gethostent()) {
- 24362 if (strcasecmp(p->h_name, name) == 0)
- 24363 break;
- 24364 for (cp = p->h_aliases; *cp != 0; cp++)
- 24365 if (strcasecmp(*cp, name) == 0)
- 24366 goto found;
- 24367 }
- 24368 found:
- 24369 endhostent();
- 24370 return (p);
- 24371 }
- 24373 struct hostent *
- 24374 gethostbyaddr(addr, len, type)
- 24375 const char *addr;
- 24376 int len, type;
- 24377 {
- 24378 register struct hostent *p;
- 24379
- 24380 sethostent(0);
- 24381 while (p = gethostent())
- 24382 if (p->h_addrtype == type && !bcmp(p->h_addr, addr, len))
- 24383 break;
- 24384 endhostent();
- 24385 return (p);
- 24386 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/gethostname.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 24400 /* gethostname(2) system call emulation */
- 24401
- 24402 #include <sys/types.h>
- 24403 #include <fcntl.h>
- 24404 #include <stdlib.h>
- 24405 #include <string.h>
- 24406 #include <unistd.h>
- 24407 #include <net/gen/netdb.h>
- 24408
- 24409 #define HOSTNAME_FILE "/etc/hostname.file"
- 24410
- 24411 int gethostname(char *buf, size_t len)
- 24412 {
- 24413 int fd;
- 24414 int r;
- .Op 221 src/lib/ip/gethostname.c
- 24415 char *nl;
- 24416
- 24417 if ((fd= open(HOSTNAME_FILE, O_RDONLY)) < 0) return -1;
- 24418
- 24419 r= read(fd, buf, len);
- 24420 close(fd);
- 24421 if (r == -1) return -1;
- 24422
- 24423 buf[len-1]= ' ';
- 24424 if ((nl= strchr(buf, 'n')) != NULL) *nl= ' ';
- 24425 return 0;
- 24426 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/getproto.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 24500 /*
- 24501 * Copyright (c) 1983 Regents of the University of California.
- 24502 * All rights reserved.
- 24503 *
- 24504 * Redistribution and use in source and binary forms are permitted
- 24505 * provided that: (1) source distributions retain this entire copyright
- 24506 * notice and comment, and (2) distributions including binaries display
- 24507 * the following acknowledgement: ``This product includes software
- 24508 * developed by the University of California, Berkeley and its contributors''
- 24509 * in the documentation or other materials provided with the distribution
- 24510 * and in all advertising materials mentioning features or use of this
- 24511 * software. Neither the name of the University nor the names of its
- 24512 * contributors may be used to endorse or promote products derived
- 24513 * from this software without specific prior written permission.
- 24514 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- 24515 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- 24516 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 24517 */
- 24518
- 24519 #if defined(LIBC_SCCS) && !defined(lint)
- 24520 static char sccsid[] = "@(#)getproto.c 5.6 (Berkeley) 6/1/90";
- 24521 #endif /* LIBC_SCCS and not lint */
- 24522
- 24523 #include <stddef.h>
- 24524
- 24525 #ifdef _MINIX
- 24526 #include <ansi.h>
- 24527 #include <net/gen/netdb.h>
- 24528 #endif
- 24529
- 24530 extern int _proto_stayopen;
- 24531
- 24532 struct protoent *
- 24533 getprotobynumber(proto)
- 24534 register int proto;
- 24535 {
- 24536 register struct protoent *p;
- 24537
- 24538 setprotoent(_proto_stayopen);
- 24539 while (p = getprotoent())
- .Ep 222 src/lib/ip/getproto.c
- 24540 if (p->p_proto == proto)
- 24541 break;
- 24542 if (!_proto_stayopen)
- 24543 endprotoent();
- 24544 return (p);
- 24545 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/getprotoent.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 24600 /*
- 24601 * Copyright (c) 1983 Regents of the University of California.
- 24602 * All rights reserved.
- 24603 *
- 24604 * Redistribution and use in source and binary forms are permitted
- 24605 * provided that: (1) source distributions retain this entire copyright
- 24606 * notice and comment, and (2) distributions including binaries display
- 24607 * the following acknowledgement: ``This product includes software
- 24608 * developed by the University of California, Berkeley and its contributors''
- 24609 * in the documentation or other materials provided with the distribution
- 24610 * and in all advertising materials mentioning features or use of this
- 24611 * software. Neither the name of the University nor the names of its
- 24612 * contributors may be used to endorse or promote products derived
- 24613 * from this software without specific prior written permission.
- 24614 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- 24615 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- 24616 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 24617 */
- 24618
- 24619 #if defined(LIBC_SCCS) && !defined(lint)
- 24620 static char sccsid[] = "@(#)getprotoent.c 5.7 (Berkeley) 6/1/90";
- 24621 #endif /* LIBC_SCCS and not lint */
- 24622
- 24623 #include <ctype.h>
- 24624 #include <stdio.h>
- 24625 #include <stdlib.h>
- 24626
- 24627 #ifdef _MINIX
- 24628 #include <net/gen/netdb.h>
- 24629
- 24630 static char *any _ARGS(( char *cp, char *match ));
- 24631 #endif
- 24632
- 24633 #define MAXALIASES 35
- 24634
- 24635 static FILE *protof = NULL;
- 24636 static char line[BUFSIZ+1];
- 24637 static struct protoent proto;
- 24638 static char *proto_aliases[MAXALIASES];
- 24639 int _proto_stayopen;
- 24640
- 24641 void
- 24642 setprotoent(f)
- 24643 int f;
- 24644 {
- .Op 223 src/lib/ip/getprotoent.c
- 24645 if (protof == NULL)
- 24646 protof = fopen(_PATH_PROTOCOLS, "r" );
- 24647 else
- 24648 rewind(protof);
- 24649 _proto_stayopen |= f;
- 24650 }
- 24652 void
- 24653 endprotoent()
- 24654 {
- 24655 if (protof) {
- 24656 fclose(protof);
- 24657 protof = NULL;
- 24658 }
- 24659 _proto_stayopen = 0;
- 24660 }
- 24662 struct protoent *
- 24663 getprotoent()
- 24664 {
- 24665 char *p;
- 24666 register char *cp, **q;
- 24667
- 24668 if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
- 24669 return (NULL);
- 24670 again:
- 24671 if ((p = fgets(line, BUFSIZ, protof)) == NULL)
- 24672 return (NULL);
- 24673 if (*p == '#')
- 24674 goto again;
- 24675 cp = any(p, "#n");
- 24676 if (cp == NULL)
- 24677 goto again;
- 24678 *cp = ' ';
- 24679 proto.p_name = p;
- 24680 cp = any(p, " t");
- 24681 if (cp == NULL)
- 24682 goto again;
- 24683 *cp++ = ' ';
- 24684 while (*cp == ' ' || *cp == 't')
- 24685 cp++;
- 24686 p = any(cp, " t");
- 24687 if (p != NULL)
- 24688 *p++ = ' ';
- 24689 proto.p_proto = atoi(cp);
- 24690 q = proto.p_aliases = proto_aliases;
- 24691 if (p != NULL) {
- 24692 cp = p;
- 24693 while (cp && *cp) {
- 24694 if (*cp == ' ' || *cp == 't') {
- 24695 cp++;
- 24696 continue;
- 24697 }
- 24698 if (q < &proto_aliases[MAXALIASES - 1])
- 24699 *q++ = cp;
- 24700 cp = any(cp, " t");
- 24701 if (cp != NULL)
- 24702 *cp++ = ' ';
- 24703 }
- 24704 }
- .Ep 224 src/lib/ip/getprotoent.c
- 24705 *q = NULL;
- 24706 return (&proto);
- 24707 }
- 24709 static char *
- 24710 any(cp, match)
- 24711 register char *cp;
- 24712 char *match;
- 24713 {
- 24714 register char *mp, c;
- 24715
- 24716 while (c = *cp) {
- 24717 for (mp = match; *mp; mp++)
- 24718 if (*mp == c)
- 24719 return (cp);
- 24720 cp++;
- 24721 }
- 24722 return ((char *)0);
- 24723 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/getservent.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 24800 /*
- 24801 * Copyright (c) 1983 Regents of the University of California.
- 24802 * All rights reserved.
- 24803 *
- 24804 * Redistribution and use in source and binary forms are permitted
- 24805 * provided that: (1) source distributions retain this entire copyright
- 24806 * notice and comment, and (2) distributions including binaries display
- 24807 * the following acknowledgement: ``This product includes software
- 24808 * developed by the University of California, Berkeley and its contributors''
- 24809 * in the documentation or other materials provided with the distribution
- 24810 * and in all advertising materials mentioning features or use of this
- 24811 * software. Neither the name of the University nor the names of its
- 24812 * contributors may be used to endorse or promote products derived
- 24813 * from this software without specific prior written permission.
- 24814 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- 24815 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- 24816 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 24817 */
- 24818
- 24819 #if defined(LIBC_SCCS) && !defined(lint)
- 24820 static char sccsid[] = "@(#)getservent.c 5.8 (Berkeley) 6/1/90";
- 24821 #endif /* LIBC_SCCS and not lint */
- 24822
- 24823 #include <sys/types.h>
- 24824 #include <ctype.h>
- 24825 #include <stdio.h>
- 24826 #include <stdlib.h>
- 24827
- 24828 #include <net/hton.h>
- 24829 #include <net/gen/netdb.h>
- 24830
- 24831 #define MAXALIASES 35
- 24832
- 24833 static FILE *servf = NULL;
- 24834 static char line[BUFSIZ+1];
- .Op 225 src/lib/ip/getservent.c
- 24835 static struct servent serv;
- 24836 static char *serv_aliases[MAXALIASES];
- 24837 int _serv_stayopen;
- 24838
- 24839 static char *any _ARGS(( char *cp, char *match ));
- 24840
- 24841 void
- 24842 setservent(f)
- 24843 int f;
- 24844 {
- 24845 if (servf == NULL)
- 24846 servf = fopen(_PATH_SERVICES, "r" );
- 24847 else
- 24848 rewind(servf);
- 24849 _serv_stayopen |= f;
- 24850 }
- 24852 void
- 24853 endservent()
- 24854 {
- 24855 if (servf) {
- 24856 fclose(servf);
- 24857 servf = NULL;
- 24858 }
- 24859 _serv_stayopen = 0;
- 24860 }
- 24862 struct servent *
- 24863 getservent()
- 24864 {
- 24865 char *p;
- 24866 register char *cp, **q;
- 24867
- 24868 if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
- 24869 return (NULL);
- 24870 again:
- 24871 if ((p = fgets(line, BUFSIZ, servf)) == NULL)
- 24872 return (NULL);
- 24873 if (*p == '#')
- 24874 goto again;
- 24875 cp = any(p, "#n");
- 24876 if (cp == NULL)
- 24877 goto again;
- 24878 *cp = ' ';
- 24879 serv.s_name = p;
- 24880 p = any(p, " t");
- 24881 if (p == NULL)
- 24882 goto again;
- 24883 *p++ = ' ';
- 24884 while (*p == ' ' || *p == 't')
- 24885 p++;
- 24886 cp = any(p, ",/");
- 24887 if (cp == NULL)
- 24888 goto again;
- 24889 *cp++ = ' ';
- 24890 serv.s_port = htons((u16_t)atoi(p));
- 24891 serv.s_proto = cp;
- 24892 q = serv.s_aliases = serv_aliases;
- 24893 cp = any(cp, " t");
- 24894 if (cp != NULL)
- .Ep 226 src/lib/ip/getservent.c
- 24895 *cp++ = ' ';
- 24896 while (cp && *cp) {
- 24897 if (*cp == ' ' || *cp == 't') {
- 24898 cp++;
- 24899 continue;
- 24900 }
- 24901 if (q < &serv_aliases[MAXALIASES - 1])
- 24902 *q++ = cp;
- 24903 cp = any(cp, " t");
- 24904 if (cp != NULL)
- 24905 *cp++ = ' ';
- 24906 }
- 24907 *q = NULL;
- 24908 return (&serv);
- 24909 }
- 24911 static char *
- 24912 any(cp, match)
- 24913 register char *cp;
- 24914 char *match;
- 24915 {
- 24916 register char *mp, c;
- 24917
- 24918 while (c = *cp) {
- 24919 for (mp = match; *mp; mp++)
- 24920 if (*mp == c)
- 24921 return (cp);
- 24922 cp++;
- 24923 }
- 24924 return ((char *)0);
- 24925 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/getsrvbyname.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 25000 /*
- 25001 * Copyright (c) 1983 Regents of the University of California.
- 25002 * All rights reserved.
- 25003 *
- 25004 * Redistribution and use in source and binary forms are permitted
- 25005 * provided that: (1) source distributions retain this entire copyright
- 25006 * notice and comment, and (2) distributions including binaries display
- 25007 * the following acknowledgement: ``This product includes software
- 25008 * developed by the University of California, Berkeley and its contributors''
- 25009 * in the documentation or other materials provided with the distribution
- 25010 * and in all advertising materials mentioning features or use of this
- 25011 * software. Neither the name of the University nor the names of its
- 25012 * contributors may be used to endorse or promote products derived
- 25013 * from this software without specific prior written permission.
- 25014 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- 25015 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- 25016 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 25017 */
- 25018
- 25019 #if defined(LIBC_SCCS) && !defined(lint)
- .Op 227 src/lib/ip/getsrvbyname.c
- 25020 static char sccsid[] = "@(#)getservbyname.c 5.6 (Berkeley) 6/1/90";
- 25021 #endif /* LIBC_SCCS and not lint */
- 25022
- 25023 #include <string.h>
- 25024
- 25025 #include <net/gen/netdb.h>
- 25026
- 25027 extern int _serv_stayopen;
- 25028
- 25029 struct servent *
- 25030 getservbyname(name, proto)
- 25031 const char *name, *proto;
- 25032 {
- 25033 register struct servent *p;
- 25034 register char **cp;
- 25035
- 25036 setservent(_serv_stayopen);
- 25037 while (p = getservent()) {
- 25038 if (strcmp(name, p->s_name) == 0)
- 25039 goto gotname;
- 25040 for (cp = p->s_aliases; *cp; cp++)
- 25041 if (strcmp(name, *cp) == 0)
- 25042 goto gotname;
- 25043 continue;
- 25044 gotname:
- 25045 if (proto == 0 || strcmp(p->s_proto, proto) == 0)
- 25046 break;
- 25047 }
- 25048 if (!_serv_stayopen)
- 25049 endservent();
- 25050 return (p);
- 25051 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/getsrvbyport.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 25100 /*
- 25101 * Copyright (c) 1983 Regents of the University of California.
- 25102 * All rights reserved.
- 25103 *
- 25104 * Redistribution and use in source and binary forms are permitted
- 25105 * provided that: (1) source distributions retain this entire copyright
- 25106 * notice and comment, and (2) distributions including binaries display
- 25107 * the following acknowledgement: ``This product includes software
- 25108 * developed by the University of California, Berkeley and its contributors''
- 25109 * in the documentation or other materials provided with the distribution
- 25110 * and in all advertising materials mentioning features or use of this
- 25111 * software. Neither the name of the University nor the names of its
- 25112 * contributors may be used to endorse or promote products derived
- 25113 * from this software without specific prior written permission.
- 25114 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- 25115 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- 25116 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 25117 */
- 25118
- 25119 #if defined(LIBC_SCCS) && !defined(lint)
- .Ep 228 src/lib/ip/getsrvbyport.c
- 25120 static char sccsid[] = "@(#)getservbyport.c 5.6 (Berkeley) 6/1/90";
- 25121 #endif /* LIBC_SCCS and not lint */
- 25122
- 25123 #include <stddef.h>
- 25124 #include <string.h>
- 25125
- 25126 #ifdef _MINIX
- 25127 #include <net/gen/netdb.h>
- 25128 #endif
- 25129
- 25130 extern int _serv_stayopen;
- 25131
- 25132 struct servent *
- 25133 getservbyport(port, proto)
- 25134 int port;
- 25135 const char *proto;
- 25136 {
- 25137 register struct servent *p;
- 25138
- 25139 setservent(_serv_stayopen);
- 25140 while (p = getservent()) {
- 25141 if (p->s_port != port)
- 25142 continue;
- 25143 if (proto == 0 || strcmp(p->s_proto, proto) == 0)
- 25144 break;
- 25145 }
- 25146 if (!_serv_stayopen)
- 25147 endservent();
- 25148 return (p);
- 25149 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/hton.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 25200 /*
- 25201 hton.c
- 25202 */
- 25203
- 25204 #include <sys/types.h>
- 25205 #include <minix/config.h>
- 25206 #include <net/hton.h>
- 25207
- 25208 u16_t _tmp;
- 25209 u32_t _tmp_l;
- .Op 229 src/lib/ip/inet_addr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/inet_addr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 25300 /*
- 25301 * Copyright (c) 1983, 1990 Regents of the University of California.
- 25302 * All rights reserved.
- 25303 *
- 25304 * Redistribution and use in source and binary forms are permitted provided
- 25305 * that: (1) source distributions retain this entire copyright notice and
- 25306 * comment, and (2) distributions including binaries display the following
- 25307 * acknowledgement: ``This product includes software developed by the
- 25308 * University of California, Berkeley and its contributors'' in the
- 25309 * documentation or other materials provided with the distribution and in
- 25310 * all advertising materials mentioning features or use of this software.
- 25311 * Neither the name of the University nor the names of its contributors may
- 25312 * be used to endorse or promote products derived from this software without
- 25313 * specific prior written permission.
- 25314 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- 25315 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- 25316 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 25317 */
- 25318
- 25319 #if defined(LIBC_SCCS) && !defined(lint)
- 25320 static char sccsid[] = "@(#)inet_addr.c 5.8 (Berkeley) 6/23/90";
- 25321 #endif /* LIBC_SCCS and not lint */
- 25322
- 25323 #if _MINIX
- 25324 #include <sys/types.h>
- 25325 #include <ctype.h>
- 25326 #include <errno.h>
- 25327
- 25328 #include <net/hton.h>
- 25329 #include <net/gen/in.h>
- 25330 #include <net/gen/inet.h>
- 25331 #endif
- 25332
- 25333 #ifdef __STDC__
- 25334 #define _CONST const
- 25335 #else
- 25336 #define _CONST
- 25337 #endif
- 25338
- 25339 /*
- 25340 * Ascii internet address interpretation routine.
- 25341 * The value returned is in network order.
- 25342 */
- 25343 ipaddr_t
- 25344 inet_addr(cp)
- 25345 register _CONST char *cp;
- 25346 {
- 25347 ipaddr_t val;
- 25348
- 25349 if (inet_aton(cp, &val))
- 25350 return (val);
- 25351 errno= EINVAL;
- 25352 return (ipaddr_t)-1;
- 25353 }
- .Ep 230 src/lib/ip/inet_addr.c
- 25355 /*
- 25356 * Check whether "cp" is a valid ascii representation
- 25357 * of an Internet address and convert to a binary address.
- 25358 * Returns 1 if the address is valid, 0 if not.
- 25359 * This replaces inet_addr, the return value from which
- 25360 * cannot distinguish between failure and a local broadcast address.
- 25361 */
- 25362
- 25363 int
- 25364 inet_aton(cp, addr)
- 25365 register _CONST char *cp;
- 25366 ipaddr_t *addr;
- 25367 {
- 25368 register u32_t val, base, n;
- 25369 register char c;
- 25370 u32_t parts[4], *pp = parts;
- 25371
- 25372 for (;;) {
- 25373 /*
- 25374 * Collect number up to ``.''.
- 25375 * Values are specified as for C:
- 25376 * 0x=hex, 0=octal, other=decimal.
- 25377 */
- 25378 val = 0; base = 10;
- 25379 if (*cp == '0') {
- 25380 if (*++cp == 'x' || *cp == 'X')
- 25381 base = 16, cp++;
- 25382 else
- 25383 base = 8;
- 25384 }
- 25385 while ((c = *cp) != ' ') {
- 25386 if (isascii(c) && isdigit(c)) {
- 25387 val = (val * base) + (c - '0');
- 25388 cp++;
- 25389 continue;
- 25390 }
- 25391 if (base == 16 && isascii(c) && isxdigit(c)) {
- 25392 val = (val << 4) +
- 25393 (c + 10 - (islower(c) ? 'a' : 'A'));
- 25394 cp++;
- 25395 continue;
- 25396 }
- 25397 break;
- 25398 }
- 25399 if (*cp == '.') {
- 25400 /*
- 25401 * Internet format:
- 25402 * a.b.c.d
- 25403 * a.b.c (with c treated as 16-bits)
- 25404 * a.b (with b treated as 24 bits)
- 25405 */
- 25406 if (pp >= parts + 3 || val > 0xff)
- 25407 return (0);
- 25408 *pp++ = val, cp++;
- 25409 } else
- 25410 break;
- 25411 }
- 25412 /*
- 25413 * Check for trailing characters.
- 25414 */
- .Op 231 src/lib/ip/inet_addr.c
- 25415 if (*cp && (!isascii(*cp) || !isspace(*cp)))
- 25416 return (0);
- 25417 /*
- 25418 * Concoct the address according to
- 25419 * the number of parts specified.
- 25420 */
- 25421 n = pp - parts + 1;
- 25422 switch (n) {
- 25423
- 25424 case 1: /* a -- 32 bits */
- 25425 break;
- 25426
- 25427 case 2: /* a.b -- 8.24 bits */
- 25428 if (val > 0xffffff)
- 25429 return (0);
- 25430 val |= parts[0] << 24;
- 25431 break;
- 25432
- 25433 case 3: /* a.b.c -- 8.8.16 bits */
- 25434 if (val > 0xffff)
- 25435 return (0);
- 25436 val |= (parts[0] << 24) | (parts[1] << 16);
- 25437 break;
- 25438
- 25439 case 4: /* a.b.c.d -- 8.8.8.8 bits */
- 25440 if (val > 0xff)
- 25441 return (0);
- 25442 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
- 25443 break;
- 25444 }
- 25445 if (addr)
- 25446 *addr = htonl(val);
- 25447 return (1);
- 25448 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/inet_ntoa.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 25500 /*
- 25501 * Copyright (c) 1983 Regents of the University of California.
- 25502 * All rights reserved.
- 25503 *
- 25504 * Redistribution and use in source and binary forms are permitted
- 25505 * provided that: (1) source distributions retain this entire copyright
- 25506 * notice and comment, and (2) distributions including binaries display
- 25507 * the following acknowledgement: ``This product includes software
- 25508 * developed by the University of California, Berkeley and its contributors''
- 25509 * in the documentation or other materials provided with the distribution
- 25510 * and in all advertising materials mentioning features or use of this
- 25511 * software. Neither the name of the University nor the names of its
- 25512 * contributors may be used to endorse or promote products derived
- 25513 * from this software without specific prior written permission.
- 25514 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- 25515 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- 25516 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 25517 */
- 25518
- 25519 #if defined(LIBC_SCCS) && !defined(lint)
- .Ep 232 src/lib/ip/inet_ntoa.c
- 25520 static char sccsid[] = "@(#)inet_ntoa.c 5.5 (Berkeley) 6/1/90";
- 25521 #endif /* LIBC_SCCS and not lint */
- 25522
- 25523 /*
- 25524 * Convert network-format internet address
- 25525 * to base 256 d.d.d.d representation.
- 25526 */
- 25527
- 25528 #include <sys/types.h>
- 25529 #include <stdio.h>
- 25530
- 25531 #include <net/gen/in.h>
- 25532 #include <net/gen/inet.h>
- 25533
- 25534 char *
- 25535 inet_ntoa(in)
- 25536 ipaddr_t in;
- 25537 {
- 25538 static char b[18];
- 25539 register u8_t *p;
- 25540
- 25541 p = (u8_t *)∈
- 25542 sprintf(b, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
- 25543 return (b);
- 25544 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/memcspn.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 25600 /*
- 25601 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 25602 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 25603 */
- 25604 /* $Header: strcspn.c,v 1.1 91/12/19 13:20:40 philip Exp $ */
- 25605
- 25606 #include <string.h>
- 25607
- 25608 size_t
- 25609 memcspn(const char *string, size_t strlen, const char *notin, size_t notinlen)
- 25610 {
- 25611 register const char *s1, *s2;
- 25612 int i,j;
- 25613
- 25614 for (s1 = string, i = 0; i<strlen; s1++, i++) {
- 25615 for(s2 = notin, j = 0; *s2 != *s1 && j < notinlen; s2++, j++)
- 25616 /* EMPTY */ ;
- 25617 if (j != notinlen)
- 25618 break;
- 25619 }
- 25620 return s1 - string;
- 25621 }
- .Op 233 src/lib/ip/oneC_sum.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/oneC_sum.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 25700 /* oneC_sum() - One complement's checksum Author: Kees J. Bot
- 25701 * 8 May 1995
- 25702 * See RFC 1071, "Computing the Internet checksum"
- 25703 */
- 25704
- 25705 #include <sys/types.h>
- 25706 #include <net/gen/oneCsum.h>
- 25707
- 25708 u16_t oneC_sum(U16_t prev, void *data, size_t size)
- 25709 {
- 25710 u8_t *dptr;
- 25711 size_t n;
- 25712 u16_t word;
- 25713 u32_t sum;
- 25714 int swap= 0;
- 25715
- 25716 sum= prev;
- 25717 dptr= data;
- 25718 n= size;
- 25719
- 25720 swap= ((size_t) dptr & 1);
- 25721 if (swap) {
- 25722 sum= ((sum & 0xFF) << 8) | ((sum & 0xFF00) >> 8);
- 25723 if (n > 0) {
- 25724 ((u8_t *) &word)[0]= 0;
- 25725 ((u8_t *) &word)[1]= dptr[0];
- 25726 sum+= (u32_t) word;
- 25727 dptr+= 1;
- 25728 n-= 1;
- 25729 }
- 25730 }
- 25731
- 25732 while (n >= 8) {
- 25733 sum+= (u32_t) ((u16_t *) dptr)[0]
- 25734 + (u32_t) ((u16_t *) dptr)[1]
- 25735 + (u32_t) ((u16_t *) dptr)[2]
- 25736 + (u32_t) ((u16_t *) dptr)[3];
- 25737 dptr+= 8;
- 25738 n-= 8;
- 25739 }
- 25740
- 25741 while (n >= 2) {
- 25742 sum+= (u32_t) ((u16_t *) dptr)[0];
- 25743 dptr+= 2;
- 25744 n-= 2;
- 25745 }
- 25746
- 25747 if (n > 0) {
- 25748 ((u8_t *) &word)[0]= dptr[0];
- 25749 ((u8_t *) &word)[1]= 0;
- 25750 sum+= (u32_t) word;
- 25751 }
- 25752
- 25753 sum= (sum & 0xFFFF) + (sum >> 16);
- 25754 if (sum > 0xFFFF) sum++;
- .Ep 234 src/lib/ip/oneC_sum.c
- 25755
- 25756 if (swap) {
- 25757 sum= ((sum & 0xFF) << 8) | ((sum & 0xFF00) >> 8);
- 25758 }
- 25759 return sum;
- 25760 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/rcmd.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 25800 /*
- 25801 * Copyright (c) 1983 Regents of the University of California.
- 25802 * All rights reserved.
- 25803 *
- 25804 * Redistribution and use in source and binary forms are permitted
- 25805 * provided that: (1) source distributions retain this entire copyright
- 25806 * notice and comment, and (2) distributions including binaries display
- 25807 * the following acknowledgement: ``This product includes software
- 25808 * developed by the University of California, Berkeley and its contributors''
- 25809 * in the documentation or other materials provided with the distribution
- 25810 * and in all advertising materials mentioning features or use of this
- 25811 * software. Neither the name of the University nor the names of its
- 25812 * contributors may be used to endorse or promote products derived
- 25813 * from this software without specific prior written permission.
- 25814 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- 25815 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- 25816 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 25817 */
- 25818
- 25819 #if defined(LIBC_SCCS) && !defined(lint)
- 25820 static char sccsid[] = "@(#)rcmd.c 5.22 (Berkeley) 6/1/90";
- 25821 #endif /* LIBC_SCCS and not lint */
- 25822
- 25823 #if _MINIX
- 25824 #include <sys/types.h>
- 25825 #include <sys/stat.h>
- 25826 #include <sys/ioctl.h>
- 25827 #include <ctype.h>
- 25828 #include <errno.h>
- 25829 #include <fcntl.h>
- 25830 #include <limits.h>
- 25831 #include <pwd.h>
- 25832 #include <stdio.h>
- 25833 #include <stdlib.h>
- 25834 #include <signal.h>
- 25835 #include <string.h>
- 25836 #include <unistd.h>
- 25837 #include <net/gen/netdb.h>
- 25838 #include <net/gen/in.h>
- 25839 #include <net/gen/tcp.h>
- 25840 #include <net/gen/tcp_io.h>
- 25841 #include <net/hton.h>
- 25842 #include <net/netlib.h>
- 25843
- 25844 #define MAXHOSTNAMELEN 256
- .Op 235 src/lib/ip/rcmd.c
- 25845 #define MAXPATHLEN PATH_MAX
- 25846 #else
- 25847 #include <stdio.h>
- 25848 #include <ctype.h>
- 25849 #include <pwd.h>
- 25850 #include <sys/param.h>
- 25851 #include <sys/file.h>
- 25852 #include <sys/signal.h>
- 25853 #include <sys/socket.h>
- 25854 #include <sys/stat.h>
- 25855
- 25856 #include <netinet/in.h>
- 25857
- 25858 #include <netdb.h>
- 25859 #include <errno.h>
- 25860 #endif
- 25861
- 25862 #ifdef __STDC__
- 25863 #define CONST const
- 25864 #else
- 25865 #define CONST
- 25866 #endif
- 25867
- 25868 extern errno;
- 25869 #if _MINIX
- 25870 int _validuser _ARGS(( FILE *hostf, const char *rhost, const char *luser,
- 25871 const char *ruser, int baselen ));
- 25872 static int _checkhost _ARGS(( const char *rhost, const char *lhost, int len ));
- 25873 #else
- 25874 char *index();
- 25875 #endif
- 25876
- 25877 #if _MINIX
- 25878 int rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
- 25879 char **ahost;
- 25880 int rport;
- 25881 CONST char *locuser, *remuser, *cmd;
- 25882 int *fd2p;
- 25883 {
- 25884 int fd, fd2, result;
- 25885 struct hostent *hp;
- 25886 tcpport_t lport;
- 25887 nwio_tcpconf_t tcpconf;
- 25888 nwio_tcpcl_t tcpconnopt;
- 25889 pid_t pid;
- 25890 char num[8];
- 25891 char c;
- 25892 char *tcp_device;
- 25893
- 25894 fd= -1;
- 25895 fd2= -1;
- 25896
- 25897 tcp_device= getenv("TCP_DEVICE");
- 25898 if (tcp_device == NULL)
- 25899 tcp_device= TCP_DEVICE;
- 25900 hp= gethostbyname(*ahost);
- 25901 if (!hp)
- 25902 {
- 25903 fprintf(stderr, "%s: unknown hostn", *ahost);
- 25904 return -1;
- .Ep 236 src/lib/ip/rcmd.c
- 25905 }
- 25906 *ahost= hp->h_name;
- 25907 for (lport= TCPPORT_RESERVED-1; lport >= TCPPORT_RESERVED/2; lport--)
- 25908 {
- 25909 fd= open (tcp_device, O_RDWR);
- 25910 if (fd<0)
- 25911 {
- 25912 fprintf(stderr, "unable to open %s: %sn",
- 25913 tcp_device, strerror(errno));
- 25914 goto bad;
- 25915 }
- 25916 tcpconf.nwtc_flags= NWTC_LP_SET | NWTC_SET_RA | NWTC_SET_RP |
- 25917 NWTC_EXCL;
- 25918 tcpconf.nwtc_locport= htons(lport);
- 25919 tcpconf.nwtc_remport= rport;
- 25920 tcpconf.nwtc_remaddr= *(ipaddr_t *)hp->h_addr;
- 25921
- 25922 result= ioctl(fd, NWIOSTCPCONF, &tcpconf);
- 25923 if (result<0)
- 25924 {
- 25925 if (errno == EADDRINUSE)
- 25926 {
- 25927 close(fd);
- 25928 continue;
- 25929 }
- 25930 fprintf(stderr, "unable to ioctl(NWIOSTCPCONF): %sn",
- 25931 strerror(errno));
- 25932 goto bad;
- 25933 }
- 25934 tcpconf.nwtc_flags= NWTC_SHARED;
- 25935 result= ioctl(fd, NWIOSTCPCONF, &tcpconf);
- 25936 if (result<0)
- 25937 {
- 25938 fprintf(stderr, "unable to ioctl(NWIOSTCPCONF): %sn",
- 25939 strerror(errno));
- 25940 goto bad;
- 25941 }
- 25942 tcpconnopt.nwtcl_flags= 0;
- 25943
- 25944 do
- 25945 {
- 25946 result= ioctl (fd, NWIOTCPCONN, &tcpconnopt);
- 25947 if (result<0 && errno == EAGAIN)
- 25948 {
- 25949 sleep(2);
- 25950 }
- 25951 } while (result<0 && errno == EAGAIN);
- 25952 if (result<0 && errno != EADDRINUSE)
- 25953 {
- 25954 fprintf(stderr,
- 25955 "unable to ioctl(NWIOTCPCONN): %sn",
- 25956 strerror(errno));
- 25957 goto bad;
- 25958 }
- 25959 if (result>=0)
- 25960 break;
- 25961 }
- 25962 if (lport<TCPPORT_RESERVED/2)
- 25963 {
- 25964 fprintf(stderr, "can't get portn");
- .Op 237 src/lib/ip/rcmd.c
- 25965 return -1;
- 25966 }
- 25967 if (!fd2p)
- 25968 {
- 25969 if (write(fd, "", 1) != 1)
- 25970 {
- 25971 fprintf(stderr, "unable to write: %s", strerror(errno));
- 25972 goto bad;
- 25973 }
- 25974 }
- 25975 else
- 25976 {
- 25977 fd2= open (tcp_device, O_RDWR);
- 25978 if (fd2<0)
- 25979 {
- 25980 fprintf(stderr, "unable to open %s: %sn",
- 25981 tcp_device, strerror(errno));
- 25982 goto bad;
- 25983 }
- 25984 tcpconf.nwtc_flags= NWTC_LP_SET | NWTC_UNSET_RA |
- 25985 NWTC_UNSET_RP | NWTC_SHARED;
- 25986 tcpconf.nwtc_locport= htons(lport);
- 25987
- 25988 result= ioctl(fd2, NWIOSTCPCONF, &tcpconf);
- 25989 if (result<0)
- 25990 {
- 25991 fprintf(stderr,
- 25992 "unable to ioctl(NWIOSTCPCONF): %sn",
- 25993 strerror(errno));
- 25994 goto bad;
- 25995 }
- 25996 pid= fork();
- 25997 if (pid<0)
- 25998 {
- 25999 fprintf(stderr, "unable to fork: %sn",
- 26000 strerror(errno));
- 26001 goto bad;
- 26002 }
- 26003 if (!pid)
- 26004 {
- 26005 alarm(0);
- 26006 signal(SIGALRM, SIG_DFL);
- 26007 alarm(30); /* give up after half a minute */
- 26008 tcpconnopt.nwtcl_flags= 0;
- 26009
- 26010 do
- 26011 {
- 26012 result= ioctl (fd2, NWIOTCPLISTEN,
- 26013 &tcpconnopt);
- 26014 if (result<0 && errno == EAGAIN)
- 26015 {
- 26016 sleep(2);
- 26017 }
- 26018 } while (result<0 && errno == EAGAIN);
- 26019 if (result<0 && errno != EADDRINUSE)
- 26020 {
- 26021 fprintf(stderr,
- 26022 "unable to ioctl(NWIOTCPLISTEN): %sn",
- 26023 strerror(errno));
- 26024 exit(1);
- .Ep 238 src/lib/ip/rcmd.c
- 26025 }
- 26026 if (result>=0)
- 26027 exit(0);
- 26028 else
- 26029 exit(1);
- 26030 }
- 26031 /*
- 26032 * This sleep is a HACK. The command that we are starting
- 26033 * will try to connect to the fd2 port. It seems that for
- 26034 * this to succeed the child process must have already made
- 26035 * the call to ioctl above (the NWIOTCPLISTEN) call.
- 26036 * The sleep gives the child a chance to make the call
- 26037 * before the parent sends the port number to the
- 26038 * command being started.
- 26039 */
- 26040 sleep(1);
- 26041
- 26042 sprintf(num, "%d", lport);
- 26043 if (write(fd, num, strlen(num)+1) != strlen(num)+1)
- 26044 {
- 26045 fprintf(stderr, "unable to write: %sn",
- 26046 strerror(errno));
- 26047 goto bad;
- 26048 }
- 26049
- 26050 }
- 26051 write (fd, locuser, strlen(locuser)+1);
- 26052 write (fd, remuser, strlen(remuser)+1);
- 26053 write (fd, cmd, strlen(cmd)+1);
- 26054 if (read(fd, &c, 1) != 1)
- 26055 {
- 26056 fprintf(stderr, "unable to read: %sn", strerror(errno) );
- 26057 goto bad;
- 26058 }
- 26059 if (c != 0)
- 26060 {
- 26061 while (read(fd, &c, 1) == 1)
- 26062 {
- 26063 write(2, &c, 1);
- 26064 if (c == 'n')
- 26065 break;
- 26066 }
- 26067 goto bad;
- 26068 }
- 26069 if (fd2p)
- 26070 {
- 26071 *fd2p= fd2;
- 26072 result= ioctl(fd2, NWIOGTCPCONF, &tcpconf);
- 26073 if (result<0)
- 26074 {
- 26075 fprintf(stderr, "unable to ioctl(NWIOGTCPCONF): %sn",
- 26076 strerror(errno) );
- 26077 goto bad;
- 26078 }
- 26079 if (ntohs(tcpconf.nwtc_remport) >= TCPPORT_RESERVED)
- 26080 {
- 26081 fprintf(stderr, "unable to setup 2nd channeln");
- 26082 goto bad;
- 26083 }
- 26084 }
- .Op 239 src/lib/ip/rcmd.c
- 26085 return fd;
- 26086
- 26087 bad:
- 26088 if (fd>=0)
- 26089 close(fd);
- 26090 if (fd2>=0)
- 26091 close(fd2);
- 26092 return -1;
- 26093 }
- 26094 #else /* _MINIX */
- 26095 rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
- 26096 char **ahost;
- 26097 u_short rport;
- 26098 char *locuser, *remuser, *cmd;
- 26099 int *fd2p;
- 26100 {
- 26101 int s, timo = 1, pid;
- 26102 long oldmask;
- 26103 struct sockaddr_in sin, sin2, from;
- 26104 char c;
- 26105 int lport = IPPORT_RESERVED - 1;
- 26106 struct hostent *hp;
- 26107 fd_set reads;
- 26108
- 26109 pid = getpid();
- 26110 hp = gethostbyname(*ahost);
- 26111 if (hp == 0) {
- 26112 herror(*ahost);
- 26113 return (-1);
- 26114 }
- 26115 *ahost = hp->h_name;
- 26116 oldmask = sigblock(sigmask(SIGURG));
- 26117 for (;;) {
- 26118 s = rresvport(&lport);
- 26119 if (s < 0) {
- 26120 if (errno == EAGAIN)
- 26121 fprintf(stderr, "socket: All ports in usen");
- 26122 else
- 26123 perror("rcmd: socket");
- 26124 sigsetmask(oldmask);
- 26125 return (-1);
- 26126 }
- 26127 fcntl(s, F_SETOWN, pid);
- 26128 sin.sin_family = hp->h_addrtype;
- 26129 bcopy(hp->h_addr_list[0], (caddr_t)&sin.sin_addr, hp->h_length);
- 26130 sin.sin_port = rport;
- 26131 if (connect(s, (caddr_t)&sin, sizeof (sin), 0) >= 0)
- 26132 break;
- 26133 (void) close(s);
- 26134 if (errno == EADDRINUSE) {
- 26135 lport--;
- 26136 continue;
- 26137 }
- 26138 if (errno == ECONNREFUSED && timo <= 16) {
- 26139 sleep(timo);
- 26140 timo *= 2;
- 26141 continue;
- 26142 }
- 26143 if (hp->h_addr_list[1] != NULL) {
- 26144 int oerrno = errno;
- .Ep 240 src/lib/ip/rcmd.c
- 26145
- 26146 fprintf(stderr,
- 26147 "connect to address %s: ", inet_ntoa(sin.sin_addr));
- 26148 errno = oerrno;
- 26149 perror(0);
- 26150 hp->h_addr_list++;
- 26151 bcopy(hp->h_addr_list[0], (caddr_t)&sin.sin_addr,
- 26152 hp->h_length);
- 26153 fprintf(stderr, "Trying %s...n",
- 26154 inet_ntoa(sin.sin_addr));
- 26155 continue;
- 26156 }
- 26157 perror(hp->h_name);
- 26158 sigsetmask(oldmask);
- 26159 return (-1);
- 26160 }
- 26161 lport--;
- 26162 if (fd2p == 0) {
- 26163 write(s, "", 1);
- 26164 lport = 0;
- 26165 } else {
- 26166 char num[8];
- 26167 int s2 = rresvport(&lport), s3;
- 26168 int len = sizeof (from);
- 26169
- 26170 if (s2 < 0)
- 26171 goto bad;
- 26172 listen(s2, 1);
- 26173 (void) sprintf(num, "%d", lport);
- 26174 if (write(s, num, strlen(num)+1) != strlen(num)+1) {
- 26175 perror("write: setting up stderr");
- 26176 (void) close(s2);
- 26177 goto bad;
- 26178 }
- 26179 FD_ZERO(&reads);
- 26180 FD_SET(s, &reads);
- 26181 FD_SET(s2, &reads);
- 26182 errno = 0;
- 26183 if (select(32, &reads, 0, 0, 0) < 1 ||
- 26184 !FD_ISSET(s2, &reads)) {
- 26185 if (errno != 0)
- 26186 perror("select: setting up stderr");
- 26187 else
- 26188 fprintf(stderr,
- 26189 "select: protocol failure in circuit setup.n");
- 26190 (void) close(s2);
- 26191 goto bad;
- 26192 }
- 26193 s3 = accept(s2, &from, &len, 0);
- 26194 (void) close(s2);
- 26195 if (s3 < 0) {
- 26196 perror("accept");
- 26197 lport = 0;
- 26198 goto bad;
- 26199 }
- 26200 *fd2p = s3;
- 26201 from.sin_port = ntohs((u_short)from.sin_port);
- 26202 if (from.sin_family != AF_INET ||
- 26203 from.sin_port >= IPPORT_RESERVED ||
- 26204 from.sin_port < IPPORT_RESERVED / 2) {
- .Op 241 src/lib/ip/rcmd.c
- 26205 fprintf(stderr,
- 26206 "socket: protocol failure in circuit setup.n");
- 26207 goto bad2;
- 26208 }
- 26209 }
- 26210 (void) write(s, locuser, strlen(locuser)+1);
- 26211 (void) write(s, remuser, strlen(remuser)+1);
- 26212 (void) write(s, cmd, strlen(cmd)+1);
- 26213 if (read(s, &c, 1) != 1) {
- 26214 perror(*ahost);
- 26215 goto bad2;
- 26216 }
- 26217 if (c != 0) {
- 26218 while (read(s, &c, 1) == 1) {
- 26219 (void) write(2, &c, 1);
- 26220 if (c == 'n')
- 26221 break;
- 26222 }
- 26223 goto bad2;
- 26224 }
- 26225 sigsetmask(oldmask);
- 26226 return (s);
- 26227 bad2:
- 26228 if (lport)
- 26229 (void) close(*fd2p);
- 26230 bad:
- 26231 (void) close(s);
- 26232 sigsetmask(oldmask);
- 26233 return (-1);
- 26234 }
- 26236 rresvport(alport)
- 26237 int *alport;
- 26238 {
- 26239 struct sockaddr_in sin;
- 26240 int s;
- 26241
- 26242 sin.sin_family = AF_INET;
- 26243 sin.sin_addr.s_addr = INADDR_ANY;
- 26244 s = socket(AF_INET, SOCK_STREAM, 0);
- 26245 if (s < 0)
- 26246 return (-1);
- 26247 for (;;) {
- 26248 sin.sin_port = htons((u_short)*alport);
- 26249 if (bind(s, (caddr_t)&sin, sizeof (sin)) >= 0)
- 26250 return (s);
- 26251 if (errno != EADDRINUSE) {
- 26252 (void) close(s);
- 26253 return (-1);
- 26254 }
- 26255 (*alport)--;
- 26256 if (*alport == IPPORT_RESERVED/2) {
- 26257 (void) close(s);
- 26258 errno = EAGAIN; /* close */
- 26259 return (-1);
- 26260 }
- 26261 }
- 26262 }
- 26263 #endif /* _MINIX */
- 26264
- .Ep 242 src/lib/ip/rcmd.c
- 26265 int _check_rhosts_file = 1;
- 26266
- 26267 ruserok(rhost, superuser, ruser, luser)
- 26268 CONST char *rhost;
- 26269 int superuser;
- 26270 CONST char *ruser, *luser;
- 26271 {
- 26272 FILE *hostf;
- 26273 char fhost[MAXHOSTNAMELEN];
- 26274 int first = 1;
- 26275 register CONST char *sp;
- 26276 register char *p;
- 26277 int baselen = -1;
- 26278
- 26279 sp = rhost;
- 26280 p = fhost;
- 26281 while (*sp) {
- 26282 if (*sp == '.') {
- 26283 if (baselen == -1)
- 26284 baselen = sp - rhost;
- 26285 *p++ = *sp++;
- 26286 } else {
- 26287 *p++ = isupper(*sp) ? tolower(*sp++) : *sp++;
- 26288 }
- 26289 }
- 26290 *p = ' ';
- 26291 hostf = superuser ? (FILE *)0 : fopen(_PATH_HEQUIV, "r");
- 26292 again:
- 26293 if (hostf) {
- 26294 if (!_validuser(hostf, fhost, luser, ruser, baselen)) {
- 26295 (void) fclose(hostf);
- 26296 return(0);
- 26297 }
- 26298 (void) fclose(hostf);
- 26299 }
- 26300 if (first == 1 && (_check_rhosts_file || superuser)) {
- 26301 struct stat sbuf;
- 26302 struct passwd *pwd;
- 26303 char pbuf[MAXPATHLEN];
- 26304
- 26305 first = 0;
- 26306 if ((pwd = getpwnam(luser)) == NULL)
- 26307 return(-1);
- 26308 (void)strcpy(pbuf, pwd->pw_dir);
- 26309 (void)strcat(pbuf, "/.rhosts");
- 26310 if ((hostf = fopen(pbuf, "r")) == NULL)
- 26311 return(-1);
- 26312 /*
- 26313 * if owned by someone other than user or root or if
- 26314 * writeable by anyone but the owner, quit
- 26315 */
- 26316 if (fstat(fileno(hostf), &sbuf) ||
- 26317 sbuf.st_uid && sbuf.st_uid != pwd->pw_uid ||
- 26318 sbuf.st_mode&022) {
- 26319 fclose(hostf);
- 26320 return(-1);
- 26321 }
- 26322 goto again;
- 26323 }
- 26324 return (-1);
- .Op 243 src/lib/ip/rcmd.c
- 26325 }
- 26327 /* don't make static, used by lpd(8) */
- 26328 int _validuser(hostf, rhost, luser, ruser, baselen)
- 26329 FILE *hostf;
- 26330 CONST char *rhost, *luser, *ruser;
- 26331 int baselen;
- 26332 {
- 26333 char *user;
- 26334 char ahost[MAXHOSTNAMELEN];
- 26335 register char *p;
- 26336
- 26337 while (fgets(ahost, sizeof (ahost), hostf)) {
- 26338 p = ahost;
- 26339 while (*p != 'n' && *p != ' ' && *p != 't' && *p != ' ') {
- 26340 *p = isupper(*p) ? tolower(*p) : *p;
- 26341 p++;
- 26342 }
- 26343 if (*p == ' ' || *p == 't') {
- 26344 *p++ = ' ';
- 26345 while (*p == ' ' || *p == 't')
- 26346 p++;
- 26347 user = p;
- 26348 while (*p != 'n' && *p != ' ' && *p != 't' && *p != ' ')
- 26349 p++;
- 26350 } else
- 26351 user = p;
- 26352 *p = ' ';
- 26353 if (_checkhost(rhost, ahost, baselen) &&
- 26354 !strcmp(ruser, *user ? user : luser)) {
- 26355 return (0);
- 26356 }
- 26357 }
- 26358 return (-1);
- 26359 }
- 26361 static int
- 26362 _checkhost(rhost, lhost, len)
- 26363 CONST char *rhost, *lhost;
- 26364 int len;
- 26365 {
- 26366 static char ldomain[MAXHOSTNAMELEN + 1];
- 26367 static char *domainp = NULL;
- 26368 static int nodomain = 0;
- 26369 register char *cp;
- 26370
- 26371 if (len == -1)
- 26372 return(!strcmp(rhost, lhost));
- 26373 if (strncmp(rhost, lhost, len))
- 26374 return(0);
- 26375 if (!strcmp(rhost, lhost))
- 26376 return(1);
- 26377 if (*(lhost + len) != ' ')
- 26378 return(0);
- 26379 if (nodomain)
- 26380 return(0);
- 26381 if (!domainp) {
- 26382 if (gethostname(ldomain, sizeof(ldomain)) == -1) {
- 26383 nodomain = 1;
- 26384 return(0);
- .Ep 244 src/lib/ip/rcmd.c
- 26385 }
- 26386 ldomain[MAXHOSTNAMELEN] = 0;
- 26387 if ((domainp = index(ldomain, '.')) == (char *)NULL) {
- 26388 nodomain = 1;
- 26389 return(0);
- 26390 }
- 26391 for (cp = ++domainp; *cp; ++cp)
- 26392 if (isupper(*cp))
- 26393 *cp = tolower(*cp);
- 26394 }
- 26395 return(!strcmp(domainp, rhost + len +1));
- 26396 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ip/res_comp.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 26400 /*
- 26401 * Copyright (c) 1985 Regents of the University of California.
- 26402 * All rights reserved.
- 26403 *
- 26404 * Redistribution and use in source and binary forms are permitted provided
- 26405 * that: (1) source distributions retain this entire copyright notice and
- 26406 * comment, and (2) distributions including binaries display the following
- 26407 * acknowledgement: ``This product includes software developed by the
- 26408 * University of California, Berkeley and its contributors'' in the
- 26409 * documentation or other materials provided with the distribution and in
- 26410 * all advertising materials mentioning features or use of this software.
- 26411 * Neither the name of the University nor the names of its contributors may
- 26412 * be used to endorse or promote products derived from this software without
- 26413 * specific prior written permission.
- 26414 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- 26415 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- 26416 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- 26417 */
- 26418
- 26419 #if defined(LIBC_SCCS) && !defined(lint)
- 26420 static char sccsid[] = "@(#)res_comp.c 6.18 (Berkeley) 6/27/90";
- 26421 #endif /* LIBC_SCCS and not lint */
- 26422
- 26423 #if _MINIX
- 26424 #include <sys/types.h>
- 26425 #include <stdlib.h>
- 26426
- 26427 #include <net/gen/in.h>
- 26428 #include <net/gen/nameser.h>
- 26429 #include <net/gen/resolv.h>
- 26430
- 26431 typedef u8_t u_char;
- 26432 typedef u16_t u_short;
- 26433 typedef u32_t u_long;
- 26434
- 26435 static int dn_find _ARGS(( const u_char *exp_dn, const u_char *msg,
- 26436 u_char **dnptrs, u_char **lastdnptr ));
- 26437 int dn_skipname _ARGS(( const u_char *comp_dn, const u_char *eom ));
- 26438
- 26439 #define getshort _getshort
- .Op 245 src/lib/ip/res_comp.c
- 26440 #define getlong _getlong
- 26441 #define putshort __putshort
- 26442 #define putlong __putlong
- 26443 #else
- 26444 #include <sys/types.h>
- 26445 #include <stdio.h>
- 26446 #include <arpa/nameser.h>
- 26447
- 26448 static dn_find();
- 26449 #endif
- 26450
- 26451 #ifdef __STDC__
- 26452 #define CONST const
- 26453 #else
- 26454 #define CONST
- 26455 #endif
- 26456
- 26457 /*
- 26458 * Expand compressed domain name 'comp_dn' to full domain name.
- 26459 * 'msg' is a pointer to the begining of the message,
- 26460 * 'eomorig' points to the first location after the message,
- 26461 * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
- 26462 * Return size of compressed name or -1 if there was an error.
- 26463 */
- 26464 dn_expand(msg, eomorig, comp_dn, exp_dn, length)
- 26465 CONST u_char *msg, *eomorig, *comp_dn;
- 26466 u_char *exp_dn;
- 26467 int length;
- 26468 {
- 26469 register CONST u_char *cp;
- 26470 register u_char *dn;
- 26471 register int n, c;
- 26472 CONST u_char *eom;
- 26473 int len = -1, checked = 0;
- 26474
- 26475 dn = exp_dn;
- 26476 cp = comp_dn;
- 26477 eom = exp_dn + length;
- 26478 /*
- 26479 * fetch next label in domain name
- 26480 */
- 26481 while (n = *cp++) {
- 26482 /*
- 26483 * Check for indirection
- 26484 */
- 26485 switch (n & INDIR_MASK) {
- 26486 case 0:
- 26487 if (dn != exp_dn) {
- 26488 if (dn >= eom)
- 26489 return (-1);
- 26490 *dn++ = '.';
- 26491 }
- 26492 if (dn+n >= eom)
- 26493 return (-1);
- 26494 checked += n + 1;
- 26495 while (--n >= 0) {
- 26496 if ((c = *cp++) == '.') {
- 26497 if (dn + n + 2 >= eom)
- 26498 return (-1);
- 26499 *dn++ = '\';
- .Ep 246 src/lib/ip/res_comp.c
- 26500 }
- 26501 *dn++ = c;
- 26502 if (cp >= eomorig) /* out of range */
- 26503 return(-1);
- 26504 }
- 26505 break;
- 26506
- 26507 case INDIR_MASK:
- 26508 if (len < 0)
- 26509 len = cp - comp_dn + 1;
- 26510 cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff));
- 26511 if (cp < msg || cp >= eomorig) /* out of range */
- 26512 return(-1);
- 26513 checked += 2;
- 26514 /*
- 26515 * Check for loops in the compressed name;
- 26516 * if we've looked at the whole message,
- 26517 * there must be a loop.
- 26518 */
- 26519 if (checked >= eomorig - msg)
- 26520 return (-1);
- 26521 break;
- 26522
- 26523 default:
- 26524 return (-1); /* flag error */
- 26525 }
- 26526 }
- 26527 *dn = ' ';
- 26528 if (len < 0)
- 26529 len = cp - comp_dn;
- 26530 return (len);
- 26531 }
- 26533 /*
- 26534 * Compress domain name 'exp_dn' into 'comp_dn'.
- 26535 * Return the size of the compressed name or -1.
- 26536 * 'length' is the size of the array pointed to by 'comp_dn'.
- 26537 * 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0]
- 26538 * is a pointer to the beginning of the message. The list ends with NULL.
- 26539 * 'lastdnptr' is a pointer to the end of the arrary pointed to
- 26540 * by 'dnptrs'. Side effect is to update the list of pointers for
- 26541 * labels inserted into the message as we compress the name.
- 26542 * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
- 26543 * is NULL, we don't update the list.
- 26544 */
- 26545 int
- 26546 dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
- 26547 CONST u_char *exp_dn;
- 26548 u_char *comp_dn;
- 26549 int length;
- 26550 u_char **dnptrs, **lastdnptr;
- 26551 {
- 26552 register u_char *cp;
- 26553 register CONST u_char *dn;
- 26554 register int c, l;
- 26555 u_char **cpp, **lpp, *sp, *eob;
- 26556 u_char *msg;
- 26557
- 26558 dn = exp_dn;
- 26559 cp = comp_dn;
- .Op 247 src/lib/ip/res_comp.c
- 26560 eob = cp + length;
- 26561 if (dnptrs != NULL) {
- 26562 if ((msg = *dnptrs++) != NULL) {
- 26563 for (cpp = dnptrs; *cpp != NULL; cpp++)
- 26564 ;
- 26565 lpp = cpp; /* end of list to search */
- 26566 }
- 26567 } else
- 26568 msg = NULL;
- 26569 for (c = *dn++; c != ' '; ) {
- 26570 /* look to see if we can use pointers */
- 26571 if (msg != NULL) {
- 26572 if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) {
- 26573 if (cp+1 >= eob)
- 26574 return (-1);
- 26575 *cp++ = (l >> 8) | INDIR_MASK;
- 26576 *cp++ = l % 256;
- 26577 return (cp - comp_dn);
- 26578 }
- 26579 /* not found, save it */
- 26580 if (lastdnptr != NULL && cpp < lastdnptr-1) {
- 26581 *cpp++ = cp;
- 26582 *cpp = NULL;
- 26583 }
- 26584 }
- 26585 sp = cp++; /* save ptr to length byte */
- 26586 do {
- 26587 if (c == '.') {
- 26588 c = *dn++;
- 26589 break;
- 26590 }
- 26591 if (c == '\') {
- 26592 if ((c = *dn++) == ' ')
- 26593 break;
- 26594 }
- 26595 if (cp >= eob) {
- 26596 if (msg != NULL)
- 26597 *lpp = NULL;
- 26598 return (-1);
- 26599 }
- 26600 *cp++ = c;
- 26601 } while ((c = *dn++) != ' ');
- 26602 /* catch trailing '.'s but not '..' */
- 26603 if ((l = cp - sp - 1) == 0 && c == ' ') {
- 26604 cp--;
- 26605 break;
- 26606 }
- 26607 if (l <= 0 || l > MAXLABEL) {
- 26608 if (msg != NULL)
- 26609 *lpp = NULL;
- 26610 return (-1);
- 26611 }
- 26612 *sp = l;
- 26613 }
- 26614 if (cp >= eob) {
- 26615 if (msg != NULL)
- 26616 *lpp = NULL;
- 26617 return (-1);
- 26618 }
- 26619 *cp++ = ' ';
- .Ep 248 src/lib/ip/res_comp.c
- 26620 return (cp - comp_dn);
- 26621 }
- 26623 /*
- 26624 * Skip over a compressed domain name. Return the size or -1.
- 26625 */
- 26626 dn_skipname(comp_dn, eom)
- 26627 CONST u_char *comp_dn, *eom;
- 26628 {
- 26629 register CONST u_char *cp;
- 26630 register int n;
- 26631
- 26632 cp = comp_dn;
- 26633 while (cp < eom && (n = *cp++)) {
- 26634 /*
- 26635 * check for indirection
- 26636 */
- 26637 switch (n & INDIR_MASK) {
- 26638 case 0: /* normal case, n == len */
- 26639 cp += n;
- 26640 continue;
- 26641 default: /* illegal type */
- 26642 return (-1);
- 26643 case INDIR_MASK: /* indirection */
- 26644 cp++;
- 26645 }
- 26646 break;
- 26647 }
- 26648 return (cp - comp_dn);
- 26649 }
- 26651 /*
- 26652 * Search for expanded name from a list of previously compressed names.
- 26653 * Return the offset from msg if found or -1.
- 26654 * dnptrs is the pointer to the first name on the list,
- 26655 * not the pointer to the start of the message.
- 26656 */
- 26657 static int
- 26658 dn_find(exp_dn, msg, dnptrs, lastdnptr)
- 26659 CONST u_char *exp_dn, *msg;
- 26660 u_char **dnptrs, **lastdnptr;
- 26661 {
- 26662 CONST register u_char *dn, *cp;
- 26663 register u_char **cpp;
- 26664 register int n;
- 26665 CONST u_char *sp;
- 26666
- 26667 for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
- 26668 dn = exp_dn;
- 26669 sp = cp = *cpp;
- 26670 while (n = *cp++) {
- 26671 /*
- 26672 * check for indirection
- 26673 */
- 26674 switch (n & INDIR_MASK) {
- 26675 case 0: /* normal case, n == len */
- 26676 while (--n >= 0) {
- 26677 if (*dn == '.')
- 26678 goto next;
- 26679 if (*dn == '\')
- .Op 249 src/lib/ip/res_comp.c
- 26680 dn++;
- 26681 if (*dn++ != *cp++)
- 26682 goto next;
- 26683 }
- 26684 if ((n = *dn++) == ' ' && *cp == ' ')
- 26685 return (sp - msg);
- 26686 if (n == '.')
- 26687 continue;
- 26688 goto next;
- 26689
- 26690 default: /* illegal type */
- 26691 return (-1);
- 26692
- 26693 case INDIR_MASK: /* indirection */
- 26694 cp = msg + (((n & 0x3f) << 8) | *cp);
- 26695 }
- 26696 }
- 26697 if (*dn == ' ')
- 26698 return (sp - msg);
- 26699 next: ;
- 26700 }
- 26701 return (-1);
- 26702 }
- 26704 /*
- 26705 * Routines to insert/extract short/long's. Must account for byte
- 26706 * order and non-alignment problems. This code at least has the
- 26707 * advantage of being portable.
- 26708 *
- 26709 * used by sendmail.
- 26710 */
- 26711
- 26712 u16_t
- 26713 getshort(msgp)
- 26714 CONST u8_t *msgp;
- 26715 {
- 26716 return ((msgp[0] << 8) | (msgp[1] << 0));
- 26717 }
- 26719 u32_t
- 26720 getlong(msgp)
- 26721 CONST u8_t *msgp;
- 26722 {
- 26723 return ( ((u32_t) msgp[0] << 24)
- 26724 | ((u32_t) msgp[1] << 16)
- 26725 | ((u32_t) msgp[2] << 8)
- 26726 | ((u32_t) msgp[3] << 0));
- 26727 }
- 26730 void
- 26731 putshort(s, msgp)
- 26732 register U16_t s;
- 26733 register u8_t *msgp;
- 26734 {
- 26735