Authen-Smb
view release on metacpan or search on metacpan
smbval/rfcnb-io.c view on Meta::CPAN
We read the first 4 bytes, that tells us the length, then read the
rest. We should implement a timeout, but we don't just yet
*/
int RFCNB_Get_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len)
{ int read_len, pkt_len;
char hdr[RFCNB_Pkt_Hdr_Len]; /* Local space for the header */
struct RFCNB_Pkt *pkt_frag;
int more, this_time, offset, frag_len, this_len;
BOOL seen_keep_alive = TRUE;
/* Read that header straight into the buffer */
if (len < RFCNB_Pkt_Hdr_Len) { /* What a bozo */
#ifdef RFCNB_DEBUG
fprintf(stderr, "Trying to read less than a packet:");
perror("");
#endif
smbval/rfcnb-io.c view on Meta::CPAN
#ifdef RFCNB_DEBUG
fprintf(stderr, "Reading Pkt: Length = %i\n", pkt_len);
#endif
/* Now copy in the hdr */
memcpy(pkt -> data, hdr, sizeof(hdr));
/* Get the rest of the packet ... first figure out how big our buf is? */
/* And make sure that we handle the fragments properly ... Sure should */
/* use an iovec ... */
if (len < pkt_len) /* Only get as much as we have space for */
more = len - RFCNB_Pkt_Hdr_Len;
else
more = pkt_len;
this_time = 0;
/* We read for each fragment ... */
if (pkt -> len == read_len){ /* If this frag was exact size */
pkt_frag = pkt -> next; /* Stick next lot in next frag */
offset = 0; /* then we start at 0 in next */
}
else {
pkt_frag = pkt; /* Otherwise use rest of this frag */
offset = RFCNB_Pkt_Hdr_Len; /* Otherwise skip the header */
}
frag_len = pkt_frag -> len;
if (more <= frag_len) /* If len left to get less than frag space */
this_len = more; /* Get the rest ... */
else
this_len = frag_len - offset;
while (more > 0) {
if ((this_time = read(con -> fd, (pkt_frag -> data) + offset, this_len)) <= 0) { /* Problems */
if (errno == EINTR) {
RFCNB_errno = RFCNB_Timeout;
}
else {
if (this_time < 0)
RFCNB_errno = RFCNBE_BadRead;
else
RFCNB_errno = RFCNBE_ConGone;
}
RFCNB_saved_errno = errno;
return(RFCNBE_Bad);
}
#ifdef RFCNB_DEBUG
fprintf(stderr, "Frag_Len = %i, this_time = %i, this_len = %i, more = %i\n", frag_len,
this_time, this_len, more);
#endif
read_len = read_len + this_time; /* How much have we read ... */
/* Now set up the next part */
if (pkt_frag -> next == NULL) break; /* That's it here */
pkt_frag = pkt_frag -> next;
this_len = pkt_frag -> len;
offset = 0;
more = more - this_time;
}
#ifdef RFCNB_DEBUG
fprintf(stderr,"Pkt Len = %i, read_len = %i\n", pkt_len, read_len);
RFCNB_Print_Pkt(stderr, "rcvd", pkt, read_len + sizeof(hdr));
#endif
smbval/rfcnb-util.c view on Meta::CPAN
}
return 0;
}
/* Print an RFCNB packet */
void RFCNB_Print_Pkt(FILE *fd, char *dirn, struct RFCNB_Pkt *pkt, int len)
{ char lname[17];
/* We assume that the first fragment is the RFCNB Header */
/* We should loop through the fragments printing them out */
fprintf(fd, "RFCNB Pkt %s:", dirn);
switch (RFCNB_Pkt_Type(pkt -> data)) {
case RFCNB_SESSION_MESSAGE:
fprintf(fd, "SESSION MESSAGE: Length = %i\n", RFCNB_Pkt_Len(pkt -> data));
RFCNB_Print_Hex(fd, pkt, RFCNB_Pkt_Hdr_Len,
#ifdef RFCNB_PRINT_DATA
smbval/smblib-priv.h view on Meta::CPAN
typedef unsigned short WORD;
typedef unsigned short UWORD;
typedef unsigned int ULONG;
typedef unsigned char BYTE;
typedef unsigned char UCHAR;
/* Some macros to allow access to actual packet data so that we */
/* can change the underlying representation of packets. */
/* */
/* The current formats vying for attention are a fragment */
/* approach where the SMB header is a fragment linked to the */
/* data portion with the transport protocol (rfcnb or whatever) */
/* being linked on the front. */
/* */
/* The other approach is where the whole packet is one array */
/* of bytes with space allowed on the front for the packet */
/* headers. */
#define SMB_Hdr(p) (char *)(p -> data)
/* SMB Hdr def for File Sharing Protocol? From MS and Intel, */
( run in 0.915 second using v1.01-cache-2.11-cpan-364913b4093 )