|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T s
Length: 3403 (0xd4b) Types: TextFile Names: »str2tpkt.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« └─⟦d3ac74d73⟧ └─⟦this⟧ »isode-5.0/tsap/str2tpkt.c«
/* str2tpkt.c - read/write a TPDU thru a string */ #ifndef lint static char *rcsid = "$Header: /f/osi/tsap/RCS/str2tpkt.c,v 6.0 89/03/18 23:45:13 mrose Rel $"; #endif /* * $Header: /f/osi/tsap/RCS/str2tpkt.c,v 6.0 89/03/18 23:45:13 mrose Rel $ * * * $Log: str2tpkt.c,v $ * Revision 6.0 89/03/18 23:45:13 mrose * Release 5.0 * */ /* * NOTICE * * Acquisition, use, and distribution of this module and related * materials are subject to the restrictions of a license agreement. * Consult the Preface in the User's Manual for the full terms of * this agreement. * */ /* LINTLIBRARY */ #include <stdio.h> #include "tpkt.h" #include "tailor.h" int readfnx (), getfnx (), writefnx (), putfnx (); /* \f */ char *tpkt2str (t) struct tsapkt *t; { char packet[BUFSIZ]; static char buffer[2 * sizeof packet + 1]; (void) writefnx (NOTOK, packet, 0); if (tpkt2fd (0, t, putfnx) == NOTOK) return NULLCP; buffer[explode (buffer, (u_char *) packet, writefnx (NOTOK, NULLCP, 0))] = NULL; DLOG (tsap_log, LLOG_PDUS, ("write %d bytes, \"%s\"", strlen (buffer), buffer)); return buffer; } /* \f */ struct tsapkt *str2tpkt (buffer) char *buffer; { char packet[BUFSIZ]; register struct tsapkt *t; DLOG (tsap_log, LLOG_PDUS, ("read %d bytes, \"%s\"", strlen (buffer), buffer)); (void) getfnx (NOTOK, NULLPKT, packet, implode ((u_char *) packet, buffer, strlen (buffer))); t = fd2tpkt (0, getfnx, readfnx); return t; } /* \f */ static int getfnx (fd, t, buffer, n) int fd; register struct tsapkt *t; char *buffer; int n; { static int cc; if (fd == NOTOK) { (void) readfnx (NOTOK, buffer, cc = n); return OK; } t -> t_length = cc + sizeof t -> t_pkthdr; t -> t_vrsn = TPKT_VRSN; if (readfnx (fd, (char *) &t -> t_li, sizeof t -> t_li) != sizeof t -> t_li) return DR_LENGTH; if (readfnx (fd, (char *) &t -> t_code, sizeof t -> t_code) != sizeof t -> t_code) return DR_LENGTH; return OK; } static int readfnx (fd, buffer, n) int fd, n; char *buffer; { register int i; static int cc; static char *bp; if (fd == NOTOK) { bp = buffer, cc = n; return OK; } if ((i = min (cc, n)) > 0) { bcopy (bp, buffer, n); bp += i, cc -= i; } return i; } /* \f */ static int putfnx (fd, t, cp, n) int fd; register struct tsapkt *t; char *cp; int n; { register int cc; register struct udvec *uv; cc = sizeof t -> t_li; if (writefnx (fd, (char *) &t -> t_li, cc) != cc) return NOTOK; if (writefnx (fd, (char *) &t -> t_code, sizeof t -> t_code) != sizeof t -> t_code) return NOTOK; cc += sizeof t -> t_code; if (writefnx (fd, cp, n) != n) return NOTOK; cc += n; if (t -> t_vdata && writefnx (fd, t -> t_vdata, t -> t_vlen) != t -> t_vlen) return NOTOK; cc += t -> t_vlen; for (uv = t -> t_udvec; uv -> uv_base; uv++) { if (writefnx (fd, uv -> uv_base, uv -> uv_len) != uv -> uv_len) return NOTOK; cc += uv -> uv_len; } return cc; } static int writefnx (fd, buffer, n) int fd, n; char *buffer; { static int cc; static char *bp; if (fd == NOTOK) { if (buffer == NULLCP) return cc; bp = buffer, cc = 0; return OK; } bcopy (buffer, bp, n); bp += n, cc += n; return n; }