xdr.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /*
  2. * linux/fs/lockd/xdr.c
  3. *
  4. * XDR support for lockd and the lock client.
  5. *
  6. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  7. */
  8. #include <linux/types.h>
  9. #include <linux/sched.h>
  10. #include <linux/utsname.h>
  11. #include <linux/nfs.h>
  12. #include <linux/sunrpc/xdr.h>
  13. #include <linux/sunrpc/clnt.h>
  14. #include <linux/sunrpc/svc.h>
  15. #include <linux/sunrpc/stats.h>
  16. #include <linux/lockd/lockd.h>
  17. #include <linux/lockd/sm_inter.h>
  18. #define NLMDBG_FACILITY NLMDBG_XDR
  19. static inline loff_t
  20. s32_to_loff_t(__s32 offset)
  21. {
  22. return (loff_t)offset;
  23. }
  24. static inline __s32
  25. loff_t_to_s32(loff_t offset)
  26. {
  27. __s32 res;
  28. if (offset >= NLM_OFFSET_MAX)
  29. res = NLM_OFFSET_MAX;
  30. else if (offset <= -NLM_OFFSET_MAX)
  31. res = -NLM_OFFSET_MAX;
  32. else
  33. res = offset;
  34. return res;
  35. }
  36. /*
  37. * XDR functions for basic NLM types
  38. */
  39. static __be32 *nlm_decode_cookie(__be32 *p, struct nlm_cookie *c)
  40. {
  41. unsigned int len;
  42. len = ntohl(*p++);
  43. if(len==0)
  44. {
  45. c->len=4;
  46. memset(c->data, 0, 4); /* hockeypux brain damage */
  47. }
  48. else if(len<=NLM_MAXCOOKIELEN)
  49. {
  50. c->len=len;
  51. memcpy(c->data, p, len);
  52. p+=XDR_QUADLEN(len);
  53. }
  54. else
  55. {
  56. dprintk("lockd: bad cookie size %d (only cookies under "
  57. "%d bytes are supported.)\n",
  58. len, NLM_MAXCOOKIELEN);
  59. return NULL;
  60. }
  61. return p;
  62. }
  63. static inline __be32 *
  64. nlm_encode_cookie(__be32 *p, struct nlm_cookie *c)
  65. {
  66. *p++ = htonl(c->len);
  67. memcpy(p, c->data, c->len);
  68. p+=XDR_QUADLEN(c->len);
  69. return p;
  70. }
  71. static __be32 *
  72. nlm_decode_fh(__be32 *p, struct nfs_fh *f)
  73. {
  74. unsigned int len;
  75. if ((len = ntohl(*p++)) != NFS2_FHSIZE) {
  76. dprintk("lockd: bad fhandle size %d (should be %d)\n",
  77. len, NFS2_FHSIZE);
  78. return NULL;
  79. }
  80. f->size = NFS2_FHSIZE;
  81. memset(f->data, 0, sizeof(f->data));
  82. memcpy(f->data, p, NFS2_FHSIZE);
  83. return p + XDR_QUADLEN(NFS2_FHSIZE);
  84. }
  85. static inline __be32 *
  86. nlm_encode_fh(__be32 *p, struct nfs_fh *f)
  87. {
  88. *p++ = htonl(NFS2_FHSIZE);
  89. memcpy(p, f->data, NFS2_FHSIZE);
  90. return p + XDR_QUADLEN(NFS2_FHSIZE);
  91. }
  92. /*
  93. * Encode and decode owner handle
  94. */
  95. static inline __be32 *
  96. nlm_decode_oh(__be32 *p, struct xdr_netobj *oh)
  97. {
  98. return xdr_decode_netobj(p, oh);
  99. }
  100. static inline __be32 *
  101. nlm_encode_oh(__be32 *p, struct xdr_netobj *oh)
  102. {
  103. return xdr_encode_netobj(p, oh);
  104. }
  105. static __be32 *
  106. nlm_decode_lock(__be32 *p, struct nlm_lock *lock)
  107. {
  108. struct file_lock *fl = &lock->fl;
  109. s32 start, len, end;
  110. if (!(p = xdr_decode_string_inplace(p, &lock->caller,
  111. &lock->len,
  112. NLM_MAXSTRLEN))
  113. || !(p = nlm_decode_fh(p, &lock->fh))
  114. || !(p = nlm_decode_oh(p, &lock->oh)))
  115. return NULL;
  116. lock->svid = ntohl(*p++);
  117. locks_init_lock(fl);
  118. fl->fl_owner = current->files;
  119. fl->fl_pid = (pid_t)lock->svid;
  120. fl->fl_flags = FL_POSIX;
  121. fl->fl_type = F_RDLCK; /* as good as anything else */
  122. start = ntohl(*p++);
  123. len = ntohl(*p++);
  124. end = start + len - 1;
  125. fl->fl_start = s32_to_loff_t(start);
  126. if (len == 0 || end < 0)
  127. fl->fl_end = OFFSET_MAX;
  128. else
  129. fl->fl_end = s32_to_loff_t(end);
  130. return p;
  131. }
  132. /*
  133. * Encode a lock as part of an NLM call
  134. */
  135. static __be32 *
  136. nlm_encode_lock(__be32 *p, struct nlm_lock *lock)
  137. {
  138. struct file_lock *fl = &lock->fl;
  139. __s32 start, len;
  140. if (!(p = xdr_encode_string(p, lock->caller))
  141. || !(p = nlm_encode_fh(p, &lock->fh))
  142. || !(p = nlm_encode_oh(p, &lock->oh)))
  143. return NULL;
  144. if (fl->fl_start > NLM_OFFSET_MAX
  145. || (fl->fl_end > NLM_OFFSET_MAX && fl->fl_end != OFFSET_MAX))
  146. return NULL;
  147. start = loff_t_to_s32(fl->fl_start);
  148. if (fl->fl_end == OFFSET_MAX)
  149. len = 0;
  150. else
  151. len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
  152. *p++ = htonl(lock->svid);
  153. *p++ = htonl(start);
  154. *p++ = htonl(len);
  155. return p;
  156. }
  157. /*
  158. * Encode result of a TEST/TEST_MSG call
  159. */
  160. static __be32 *
  161. nlm_encode_testres(__be32 *p, struct nlm_res *resp)
  162. {
  163. s32 start, len;
  164. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  165. return NULL;
  166. *p++ = resp->status;
  167. if (resp->status == nlm_lck_denied) {
  168. struct file_lock *fl = &resp->lock.fl;
  169. *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
  170. *p++ = htonl(resp->lock.svid);
  171. /* Encode owner handle. */
  172. if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
  173. return NULL;
  174. start = loff_t_to_s32(fl->fl_start);
  175. if (fl->fl_end == OFFSET_MAX)
  176. len = 0;
  177. else
  178. len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
  179. *p++ = htonl(start);
  180. *p++ = htonl(len);
  181. }
  182. return p;
  183. }
  184. /*
  185. * First, the server side XDR functions
  186. */
  187. int
  188. nlmsvc_decode_testargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  189. {
  190. u32 exclusive;
  191. if (!(p = nlm_decode_cookie(p, &argp->cookie)))
  192. return 0;
  193. exclusive = ntohl(*p++);
  194. if (!(p = nlm_decode_lock(p, &argp->lock)))
  195. return 0;
  196. if (exclusive)
  197. argp->lock.fl.fl_type = F_WRLCK;
  198. return xdr_argsize_check(rqstp, p);
  199. }
  200. int
  201. nlmsvc_encode_testres(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  202. {
  203. if (!(p = nlm_encode_testres(p, resp)))
  204. return 0;
  205. return xdr_ressize_check(rqstp, p);
  206. }
  207. int
  208. nlmsvc_decode_lockargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  209. {
  210. u32 exclusive;
  211. if (!(p = nlm_decode_cookie(p, &argp->cookie)))
  212. return 0;
  213. argp->block = ntohl(*p++);
  214. exclusive = ntohl(*p++);
  215. if (!(p = nlm_decode_lock(p, &argp->lock)))
  216. return 0;
  217. if (exclusive)
  218. argp->lock.fl.fl_type = F_WRLCK;
  219. argp->reclaim = ntohl(*p++);
  220. argp->state = ntohl(*p++);
  221. argp->monitor = 1; /* monitor client by default */
  222. return xdr_argsize_check(rqstp, p);
  223. }
  224. int
  225. nlmsvc_decode_cancargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  226. {
  227. u32 exclusive;
  228. if (!(p = nlm_decode_cookie(p, &argp->cookie)))
  229. return 0;
  230. argp->block = ntohl(*p++);
  231. exclusive = ntohl(*p++);
  232. if (!(p = nlm_decode_lock(p, &argp->lock)))
  233. return 0;
  234. if (exclusive)
  235. argp->lock.fl.fl_type = F_WRLCK;
  236. return xdr_argsize_check(rqstp, p);
  237. }
  238. int
  239. nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  240. {
  241. if (!(p = nlm_decode_cookie(p, &argp->cookie))
  242. || !(p = nlm_decode_lock(p, &argp->lock)))
  243. return 0;
  244. argp->lock.fl.fl_type = F_UNLCK;
  245. return xdr_argsize_check(rqstp, p);
  246. }
  247. int
  248. nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
  249. {
  250. struct nlm_lock *lock = &argp->lock;
  251. memset(lock, 0, sizeof(*lock));
  252. locks_init_lock(&lock->fl);
  253. lock->svid = ~(u32) 0;
  254. lock->fl.fl_pid = (pid_t)lock->svid;
  255. if (!(p = nlm_decode_cookie(p, &argp->cookie))
  256. || !(p = xdr_decode_string_inplace(p, &lock->caller,
  257. &lock->len, NLM_MAXSTRLEN))
  258. || !(p = nlm_decode_fh(p, &lock->fh))
  259. || !(p = nlm_decode_oh(p, &lock->oh)))
  260. return 0;
  261. argp->fsm_mode = ntohl(*p++);
  262. argp->fsm_access = ntohl(*p++);
  263. return xdr_argsize_check(rqstp, p);
  264. }
  265. int
  266. nlmsvc_encode_shareres(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  267. {
  268. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  269. return 0;
  270. *p++ = resp->status;
  271. *p++ = xdr_zero; /* sequence argument */
  272. return xdr_ressize_check(rqstp, p);
  273. }
  274. int
  275. nlmsvc_encode_res(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  276. {
  277. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  278. return 0;
  279. *p++ = resp->status;
  280. return xdr_ressize_check(rqstp, p);
  281. }
  282. int
  283. nlmsvc_decode_notify(struct svc_rqst *rqstp, __be32 *p, struct nlm_args *argp)
  284. {
  285. struct nlm_lock *lock = &argp->lock;
  286. if (!(p = xdr_decode_string_inplace(p, &lock->caller,
  287. &lock->len, NLM_MAXSTRLEN)))
  288. return 0;
  289. argp->state = ntohl(*p++);
  290. return xdr_argsize_check(rqstp, p);
  291. }
  292. int
  293. nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p, struct nlm_reboot *argp)
  294. {
  295. if (!(p = xdr_decode_string_inplace(p, &argp->mon, &argp->len, SM_MAXSTRLEN)))
  296. return 0;
  297. argp->state = ntohl(*p++);
  298. /* Preserve the address in network byte order */
  299. argp->addr = *p++;
  300. return xdr_argsize_check(rqstp, p);
  301. }
  302. int
  303. nlmsvc_decode_res(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
  304. {
  305. if (!(p = nlm_decode_cookie(p, &resp->cookie)))
  306. return 0;
  307. resp->status = *p++;
  308. return xdr_argsize_check(rqstp, p);
  309. }
  310. int
  311. nlmsvc_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  312. {
  313. return xdr_argsize_check(rqstp, p);
  314. }
  315. int
  316. nlmsvc_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  317. {
  318. return xdr_ressize_check(rqstp, p);
  319. }
  320. /*
  321. * Now, the client side XDR functions
  322. */
  323. #ifdef NLMCLNT_SUPPORT_SHARES
  324. static int
  325. nlmclt_decode_void(struct rpc_rqst *req, u32 *p, void *ptr)
  326. {
  327. return 0;
  328. }
  329. #endif
  330. static int
  331. nlmclt_encode_testargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  332. {
  333. struct nlm_lock *lock = &argp->lock;
  334. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  335. return -EIO;
  336. *p++ = (lock->fl.fl_type == F_WRLCK)? xdr_one : xdr_zero;
  337. if (!(p = nlm_encode_lock(p, lock)))
  338. return -EIO;
  339. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  340. return 0;
  341. }
  342. static int
  343. nlmclt_decode_testres(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  344. {
  345. if (!(p = nlm_decode_cookie(p, &resp->cookie)))
  346. return -EIO;
  347. resp->status = *p++;
  348. if (resp->status == nlm_lck_denied) {
  349. struct file_lock *fl = &resp->lock.fl;
  350. u32 excl;
  351. s32 start, len, end;
  352. memset(&resp->lock, 0, sizeof(resp->lock));
  353. locks_init_lock(fl);
  354. excl = ntohl(*p++);
  355. resp->lock.svid = ntohl(*p++);
  356. fl->fl_pid = (pid_t)resp->lock.svid;
  357. if (!(p = nlm_decode_oh(p, &resp->lock.oh)))
  358. return -EIO;
  359. fl->fl_flags = FL_POSIX;
  360. fl->fl_type = excl? F_WRLCK : F_RDLCK;
  361. start = ntohl(*p++);
  362. len = ntohl(*p++);
  363. end = start + len - 1;
  364. fl->fl_start = s32_to_loff_t(start);
  365. if (len == 0 || end < 0)
  366. fl->fl_end = OFFSET_MAX;
  367. else
  368. fl->fl_end = s32_to_loff_t(end);
  369. }
  370. return 0;
  371. }
  372. static int
  373. nlmclt_encode_lockargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  374. {
  375. struct nlm_lock *lock = &argp->lock;
  376. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  377. return -EIO;
  378. *p++ = argp->block? xdr_one : xdr_zero;
  379. *p++ = (lock->fl.fl_type == F_WRLCK)? xdr_one : xdr_zero;
  380. if (!(p = nlm_encode_lock(p, lock)))
  381. return -EIO;
  382. *p++ = argp->reclaim? xdr_one : xdr_zero;
  383. *p++ = htonl(argp->state);
  384. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  385. return 0;
  386. }
  387. static int
  388. nlmclt_encode_cancargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  389. {
  390. struct nlm_lock *lock = &argp->lock;
  391. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  392. return -EIO;
  393. *p++ = argp->block? xdr_one : xdr_zero;
  394. *p++ = (lock->fl.fl_type == F_WRLCK)? xdr_one : xdr_zero;
  395. if (!(p = nlm_encode_lock(p, lock)))
  396. return -EIO;
  397. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  398. return 0;
  399. }
  400. static int
  401. nlmclt_encode_unlockargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
  402. {
  403. struct nlm_lock *lock = &argp->lock;
  404. if (!(p = nlm_encode_cookie(p, &argp->cookie)))
  405. return -EIO;
  406. if (!(p = nlm_encode_lock(p, lock)))
  407. return -EIO;
  408. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  409. return 0;
  410. }
  411. static int
  412. nlmclt_encode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  413. {
  414. if (!(p = nlm_encode_cookie(p, &resp->cookie)))
  415. return -EIO;
  416. *p++ = resp->status;
  417. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  418. return 0;
  419. }
  420. static int
  421. nlmclt_encode_testres(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  422. {
  423. if (!(p = nlm_encode_testres(p, resp)))
  424. return -EIO;
  425. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  426. return 0;
  427. }
  428. static int
  429. nlmclt_decode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
  430. {
  431. if (!(p = nlm_decode_cookie(p, &resp->cookie)))
  432. return -EIO;
  433. resp->status = *p++;
  434. return 0;
  435. }
  436. #if (NLMCLNT_OHSIZE > XDR_MAX_NETOBJ)
  437. # error "NLM host name cannot be larger than XDR_MAX_NETOBJ!"
  438. #endif
  439. /*
  440. * Buffer requirements for NLM
  441. */
  442. #define NLM_void_sz 0
  443. #define NLM_cookie_sz 1+XDR_QUADLEN(NLM_MAXCOOKIELEN)
  444. #define NLM_caller_sz 1+XDR_QUADLEN(NLMCLNT_OHSIZE)
  445. #define NLM_owner_sz 1+XDR_QUADLEN(NLMCLNT_OHSIZE)
  446. #define NLM_fhandle_sz 1+XDR_QUADLEN(NFS2_FHSIZE)
  447. #define NLM_lock_sz 3+NLM_caller_sz+NLM_owner_sz+NLM_fhandle_sz
  448. #define NLM_holder_sz 4+NLM_owner_sz
  449. #define NLM_testargs_sz NLM_cookie_sz+1+NLM_lock_sz
  450. #define NLM_lockargs_sz NLM_cookie_sz+4+NLM_lock_sz
  451. #define NLM_cancargs_sz NLM_cookie_sz+2+NLM_lock_sz
  452. #define NLM_unlockargs_sz NLM_cookie_sz+NLM_lock_sz
  453. #define NLM_testres_sz NLM_cookie_sz+1+NLM_holder_sz
  454. #define NLM_res_sz NLM_cookie_sz+1
  455. #define NLM_norep_sz 0
  456. /*
  457. * For NLM, a void procedure really returns nothing
  458. */
  459. #define nlmclt_decode_norep NULL
  460. #define PROC(proc, argtype, restype) \
  461. [NLMPROC_##proc] = { \
  462. .p_proc = NLMPROC_##proc, \
  463. .p_encode = (kxdrproc_t) nlmclt_encode_##argtype, \
  464. .p_decode = (kxdrproc_t) nlmclt_decode_##restype, \
  465. .p_arglen = NLM_##argtype##_sz, \
  466. .p_replen = NLM_##restype##_sz, \
  467. .p_statidx = NLMPROC_##proc, \
  468. .p_name = #proc, \
  469. }
  470. static struct rpc_procinfo nlm_procedures[] = {
  471. PROC(TEST, testargs, testres),
  472. PROC(LOCK, lockargs, res),
  473. PROC(CANCEL, cancargs, res),
  474. PROC(UNLOCK, unlockargs, res),
  475. PROC(GRANTED, testargs, res),
  476. PROC(TEST_MSG, testargs, norep),
  477. PROC(LOCK_MSG, lockargs, norep),
  478. PROC(CANCEL_MSG, cancargs, norep),
  479. PROC(UNLOCK_MSG, unlockargs, norep),
  480. PROC(GRANTED_MSG, testargs, norep),
  481. PROC(TEST_RES, testres, norep),
  482. PROC(LOCK_RES, res, norep),
  483. PROC(CANCEL_RES, res, norep),
  484. PROC(UNLOCK_RES, res, norep),
  485. PROC(GRANTED_RES, res, norep),
  486. #ifdef NLMCLNT_SUPPORT_SHARES
  487. PROC(SHARE, shareargs, shareres),
  488. PROC(UNSHARE, shareargs, shareres),
  489. PROC(NM_LOCK, lockargs, res),
  490. PROC(FREE_ALL, notify, void),
  491. #endif
  492. };
  493. static struct rpc_version nlm_version1 = {
  494. .number = 1,
  495. .nrprocs = 16,
  496. .procs = nlm_procedures,
  497. };
  498. static struct rpc_version nlm_version3 = {
  499. .number = 3,
  500. .nrprocs = 24,
  501. .procs = nlm_procedures,
  502. };
  503. static struct rpc_version * nlm_versions[] = {
  504. [1] = &nlm_version1,
  505. [3] = &nlm_version3,
  506. #ifdef CONFIG_LOCKD_V4
  507. [4] = &nlm_version4,
  508. #endif
  509. };
  510. static struct rpc_stat nlm_stats;
  511. struct rpc_program nlm_program = {
  512. .name = "lockd",
  513. .number = NLM_PROGRAM,
  514. .nrvers = ARRAY_SIZE(nlm_versions),
  515. .version = nlm_versions,
  516. .stats = &nlm_stats,
  517. };
  518. #ifdef RPC_DEBUG
  519. const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
  520. {
  521. /*
  522. * We can get away with a static buffer because we're only
  523. * called with BKL held.
  524. */
  525. static char buf[2*NLM_MAXCOOKIELEN+1];
  526. unsigned int i, len = sizeof(buf);
  527. char *p = buf;
  528. len--; /* allow for trailing \0 */
  529. if (len < 3)
  530. return "???";
  531. for (i = 0 ; i < cookie->len ; i++) {
  532. if (len < 2) {
  533. strcpy(p-3, "...");
  534. break;
  535. }
  536. sprintf(p, "%02x", cookie->data[i]);
  537. p += 2;
  538. len -= 2;
  539. }
  540. *p = '\0';
  541. return buf;
  542. }
  543. #endif