diff options
| author | Dave Hibberd <hibby@debian.org> | 2025-07-22 20:56:59 +0100 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2025-07-22 20:56:59 +0100 |
| commit | 1f40ff4a07793ecfa679a1384053451c4f3f536f (patch) | |
| tree | c0813999c7216f98b4ac66224bd01589baee84d1 /L2Code.c | |
| parent | b128f2a43a16acef50de045ae6526772c04c395e (diff) | |
New upstream version 6.0.24.77+repackupstream/6.0.24.77+repack
Diffstat (limited to 'L2Code.c')
| -rw-r--r-- | L2Code.c | 464 |
1 files changed, 431 insertions, 33 deletions
@@ -33,6 +33,15 @@ along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses #include "cheaders.h"
#include "tncinfo.h"
+// This is needed to link with a lib built from source
+
+#ifdef WIN32
+#define ZEXPORT __stdcall
+#endif
+
+#include <zlib.h>
+
+
#define PFBIT 0x10 // POLL/FINAL BIT IN CONTROL BYTE
#define REJSENT 1 // SET WHEN FIRST REJ IS SENT IN REPLY
@@ -111,7 +120,8 @@ int CheckKissInterlock(struct PORTCONTROL * MYPORT, int Exclusive); void hookL2SessionAccepted(int Port, char * fromCall, char * toCall, struct _LINKTABLE * LINK);
void hookL2SessionDeleted(struct _LINKTABLE * LINK);
void hookL2SessionAttempt(int Port, char * fromCall, char * toCall, struct _LINKTABLE * LINK);
-
+int L2Compressit(unsigned char * Out, int OutSize, unsigned char * In, int Len);
+VOID DeleteINP3Routes(struct ROUTE * Route);
extern int REALTIMETICKS;
@@ -126,7 +136,9 @@ extern int REALTIMETICKS; #define SDINVC 1 // INVALID COMMAND
#define SDNRER 8 // INVALID N(R)
-
+extern int L2Compress;
+extern int L2CompMaxframe;
+extern int L2CompPaclen;
UCHAR NO_CTEXT = 0;
UCHAR ALIASMSG = 0;
@@ -142,6 +154,8 @@ extern BOOL LogAllConnects; APPLCALLS * APPL;
+int SUPPORT2point2 = 1;
+
void SendL2ToMonMap(struct PORTCONTROL * PORT, char * ReportCall, char Mode, char Direction)
{
@@ -842,6 +856,7 @@ VOID ProcessXIDCommand(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESS while (xidlen > 0)
{
+ unsigned char * typeptr = ptr;
Type = *ptr++;
Len = *ptr++;
@@ -889,6 +904,23 @@ VOID ProcessXIDCommand(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESS case 8: //RX Window
break;
+
+ case 16:
+
+ // Compression
+
+ if (L2Compress)
+ {
+ LINK->AllowCompress = 1;
+ // return as 17
+ *typeptr = 17;
+ }
+ else
+ {
+ ptr = &ADJBUFFER->PID;
+ ptr[3] -= 2; // Length field - remove compress option
+ Buffer->LENGTH -=2;
+ }
}
}
@@ -900,6 +932,8 @@ VOID ProcessXIDCommand(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESS LINK->LINKPORT = PORT;
+ LINK->KILLTIMER = L2KILLTIME - 60*3; // Time out after 60 secs if SABM not received
+
// save calls so we can match up SABM when it comes
memcpy(LINK->LINKCALL, Buffer->ORIGIN, 7);
@@ -999,6 +1033,7 @@ VOID L2LINKACTIVE(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * // MESSAGE ON AN ACTIVE LINK
int CTLlessPF = CTL & ~PFBIT;
+ unsigned char * ptr;
PORT->L2FRAMESFORUS++;
@@ -1054,7 +1089,7 @@ VOID L2LINKACTIVE(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * LINK->L2STATE = 2;
LINK->Ver2point2 = FALSE;
- LINK->L2TIMER = 1; // USe retry to send SABM
+ LINK->L2TIMER = 1; // Use retry to send SABM
}
else if (CTLlessPF == XID)
{
@@ -1062,7 +1097,49 @@ VOID L2LINKACTIVE(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * LINK->L2STATE = 2;
LINK->Ver2point2 = TRUE;// Must support 2.2 if responded to XID
- LINK->L2TIMER = 1; // USe retry to send SABM
+
+ // if Compress enabled set it
+
+ ptr = &ADJBUFFER->PID;
+
+ if (*ptr++ == 0x82 && *ptr++ == 0x80)
+ {
+ int Type;
+ int Len;
+ unsigned int value;
+ int xidlen = *(ptr++) << 8;
+ xidlen += *ptr++;
+
+ // XID is set of Type, Len, Value n-tuples
+
+ while (xidlen > 0)
+ {
+ Type = *ptr++;
+ Len = *ptr++;
+
+ value = 0;
+ xidlen -= (Len + 2);
+
+ while (Len--)
+ {
+ value <<=8;
+ value += *ptr++;
+ }
+ switch(Type)
+ {
+ case 17:
+
+ // Compression
+
+ if (L2Compress)
+ LINK->AllowCompress = 1;
+
+ }
+ }
+
+ }
+
+ LINK->L2TIMER = 1; // Use retry to send SABM
}
ReleaseBuffer(Buffer);
@@ -1110,8 +1187,9 @@ VOID L2LINKACTIVE(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * // 2. OTHER END THINKS LINK HAS DIED
// 3. RECOVERY FROM FRMR CONDITION
// 4. REPEAT OF ORIGINAL SABM COS OTHER END MISSED UA
+ // 5. Other end has reloaded
- // FOR 1-3 IT IS REASONABLE TO FULLY RESET THE CIRCUIT, BUT IN 4
+ // FOR 1-3 and 5 IT IS REASONABLE TO FULLY RESET THE CIRCUIT, BUT IN 4
// SUCH ACTION WILL LOSE THE INITIAL SIGNON MSG IF CONNECTING TO A
// BBS. THE PROBLEM IS TELLING THE DIFFERENCE. I'M GOING TO SET A FLAG
// WHEN FIRST INFO RECEIVED - IF SABM REPEATED BEFORE THIS, I'LL ASSUME
@@ -1124,7 +1202,7 @@ VOID L2LINKACTIVE(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * return;
}
- InformPartner(LINK, NORMALCLOSE); // SEND DISC TO OTHER END
+ InformPartner(LINK, NORMALCLOSE); // SEND DISC TO OTHER END
LINK->CIRCUITPOINTER = 0;
L2SABM(LINK, PORT, Buffer, ADJBUFFER, MSGFLAG); // Process the SABM
@@ -1141,6 +1219,8 @@ VOID L2SABM(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * Buffe TRANSPORTENTRY * Session;
int CONERROR;
+ struct ROUTE * ROUTE = NULL;
+
char toCall[12], fromCall[12];
@@ -1198,6 +1278,18 @@ VOID L2SABM(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * Buffe if (PORT->TNC && PORT->TNC->Hardware == H_KISSHF)
AttachKISSHF(PORT, Buffer);
+ // if it is an INP3 connection tell INP3 it is up
+
+
+ if (FindNeighbour(LINK->LINKCALL, PORT->PORTNUMBER, &ROUTE))
+ {
+ if (ROUTE->INP3Node)
+ {
+ Debugprintf("INP3 Incoming connect from %s", fromCall);
+ DeleteINP3Routes(ROUTE);
+ }
+ }
+
if (NO_CTEXT == 1)
return;
@@ -1721,9 +1813,9 @@ BOOL InternalL2SETUPCROSSLINK(PROUTE ROUTE, int Retries) else
LINK->LINKWINDOW = PORT->PORTWINDOW;
-// if (SUPPORT2point2)
-// LINK->L2STATE = 1; // Send XID
-// else
+ if (SUPPORT2point2)
+ LINK->L2STATE = 1; // Send XID
+ else
LINK->L2STATE = 2;
memcpy(LINK->LINKCALL, ROUTE->NEIGHBOUR_CALL, 7);
@@ -1881,11 +1973,23 @@ VOID L2_PROCESS(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * B // RESPONSE TO SABM - SET LINK UP
char fromCall[12];
+ struct ROUTE * ROUTE;
fromCall[ConvFromAX25(Buffer->ORIGIN, fromCall)] = 0;
RESET2X(LINK); // LEAVE QUEUED STUFF
+ // See if INP3 route setup
+
+ if (FindNeighbour(Buffer->ORIGIN, PORT->PORTNUMBER, &ROUTE))
+ {
+ if (ROUTE->INP3Node)
+ {
+ Debugprintf("INP3 Route to %s connected", fromCall);
+ }
+ }
+
+
SendL2ToMonMap(PORT, fromCall, '+', 'O');
LINK->L2STATE = 5;
@@ -2018,7 +2122,6 @@ VOID SDUFRM(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * Buffe SDFRMR(LINK, PORT); // PROCESS FRAME REJECT CONDITION
}
-
ReleaseBuffer(Buffer);
}
@@ -2358,12 +2461,11 @@ CheckNSLoop: {
// Already have a copy, so discard old and keep this
- Debugprintf ("Frame %d out of seq but already have copy - release it", NS);
ReleaseBuffer(Q_REM(&LINK->RXFRAMES[NS]));
}
else
{
- Debugprintf ("Frame %d out of seq - save", NS);
+// Debugprintf ("Frame %d out of seq - save", NS);
}
Buffer->CHAIN = 0;
@@ -2450,6 +2552,8 @@ CheckPF: }
+int doinflate(unsigned char * source, unsigned char * dest, int Len, int destlen, int * outLen);
+
VOID PROC_I_FRAME(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * Buffer)
{
@@ -2479,6 +2583,7 @@ VOID PROC_I_FRAME(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * Info = &Buffer->PID;
LINK->bytesRXed += Length;
+ LINK->Received += Length - 1; // Exclude PID
// Adjust for DIGIS
@@ -2495,6 +2600,111 @@ VOID PROC_I_FRAME(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * switch(PID)
{
+ case 0xf2:
+
+ // Intermediate fragment of compressed. Save
+
+ // Length and Info include pid
+
+ Length--;
+ Info++;
+
+ if (LINK->unCompress == 0)
+ LINK->unCompress = malloc(8192);
+
+ // Save data
+
+ memcpy(&LINK->unCompress[LINK->unCompressLen], Info, Length);
+ LINK->unCompressLen += Length;
+
+ ReleaseBuffer(Buffer);
+
+ LINK->L2ACKREQ = PORT->PORTT2; // SET RR NEEDED
+ LINK->KILLTIMER = 0; // RESET IDLE LINK TIMER
+ return;
+
+
+ case 0xf1:
+
+ // Compressed last or only
+
+ {
+ char exBuffer[8192];
+ int Len;
+ int outLen;
+ int sendLen;
+ char * sendptr = exBuffer;
+
+ Length--;
+ Info++;
+
+ // we may have previous fragments
+
+ if (LINK->unCompressLen)
+ {
+ memcpy(&LINK->unCompress[LINK->unCompressLen], Info, Length);
+ LINK->unCompressLen += Length;
+ Len = doinflate(LINK->unCompress, exBuffer, LINK->unCompressLen, 8192, &outLen);
+ LINK->ReceivedAfterExpansion += outLen - 1;
+
+ LINK->unCompressLen = 0;
+ }
+ else
+ {
+ Len = doinflate(Info, exBuffer, Length, 8192, &outLen);
+ LINK->ReceivedAfterExpansion += outLen - 1;
+ }
+ sendLen = outLen;
+
+ // Send first bit in input buffer. If still some left get new buffers for it
+
+ if (sendLen > 257)
+ sendLen = 257;
+
+ // First byte is original PID
+
+ memcpy(&Msg->PID, exBuffer, sendLen);
+ Msg->LENGTH = sendLen + MSGHDDRLEN;
+
+ C_Q_ADD(&LINK->RX_Q, Msg);
+
+ outLen -= sendLen;
+ sendptr += sendLen;
+
+ while (outLen > 0)
+ {
+ sendLen = outLen;
+
+ if (sendLen > 236)
+ sendLen = 236;
+
+ Msg = GetBuff();
+
+ if (Msg)
+ {
+ // Just ignore if no buffers - shouldn't happen
+
+ Msg->PID = exBuffer[0];
+ Msg->PORT = LINK->LINKPORT->PORTNUMBER;
+
+ memcpy(Msg->L2DATA, sendptr, sendLen);
+ Length = sendLen + 1;
+
+ Msg->LENGTH = Length + MSGHDDRLEN;
+ C_Q_ADD(&LINK->RX_Q, Msg);
+ }
+
+ outLen -= sendLen;
+ sendptr += sendLen;
+ }
+
+ LINK->L2ACKREQ = PORT->PORTT2; // SET RR NEEDED
+ LINK->KILLTIMER = 0; // RESET IDLE LINK TIMER
+
+ return;
+ }
+
+
case 0xcc:
case 0xcd:
@@ -2544,6 +2754,7 @@ VOID PROC_I_FRAME(struct _LINKTABLE * LINK, struct PORTCONTROL * PORT, MESSAGE * // Copy Data back over
memmove(&Msg->PID, Info, Length);
+ LINK->ReceivedAfterExpansion += Length - 1;
Buffer->LENGTH = Length + MSGHDDRLEN;
@@ -2611,7 +2822,7 @@ VOID RESETNS(struct _LINKTABLE * LINK, UCHAR NS) int COUNT_AT_L2(struct _LINKTABLE * LINK)
{
- // COUNTS FRAMES QUEUED ON AN L2 SESSION (IN BX)
+ // COUNTS FRAMES QUEUED ON AN L2 SESSION (IN LINK)
int count = 0, abovelink = 0;
int n = 0;
@@ -2758,7 +2969,7 @@ VOID SDETX(struct _LINKTABLE * LINK) UCHAR * ptr1, * ptr2;
UCHAR CTL;
int count;
- MESSAGE * Msg;
+ struct DATAMESSAGE * Msg;
MESSAGE * Buffer;
// DONT SEND IF RESEQUENCING RECEIVED FRAMES - CAN CAUSE FRMR PROBLEMS
@@ -2766,11 +2977,6 @@ VOID SDETX(struct _LINKTABLE * LINK) // if (LINK->L2RESEQ_Q)
// return;
- if (LINK->LINKPORT->PORTNUMBER == 19)
- {
- int i = 0;
- }
-
Outstanding = LINK->LINKNS - LINK->LINKOWS; // Was WS not NS
if (Outstanding < 0)
@@ -2783,13 +2989,150 @@ VOID SDETX(struct _LINKTABLE * LINK) while (LINK->TX_Q && LINK->FRAMES[LINK->SDTSLOT] == NULL)
{
+ // Try compressing here. Only Compress PID 0xF0 frames - NETROM doesn't treat L2 session as a byte stream
+
Msg = Q_REM(&LINK->TX_Q);
Msg->CHAIN = NULL;
- LINK->FRAMES[LINK->SDTSLOT] = Msg;
- LINK->SDTSLOT ++;
- LINK->SDTSLOT &= 7;
- }
+
+ if (LINK->AllowCompress && Msg->LENGTH > 20 && LINK->TX_Q && Msg->PID == 240) // if short and no more not worth trying compression
+ {
+ int complen = 0;
+ int dataLen;
+ int savePort = Msg->PORT;
+ int savePID = Msg->PID;
+ unsigned char Compressed[8192];
+ unsigned char toCompress[8192];
+ int toCompressLen = 0;
+
+ int slots = 0;
+ int n = LINK->SDTSLOT;
+ int maxcompsize;
+ int PACLEN = LINK->LINKPORT->PORTPACLEN;
+ unsigned char * compdata;
+ int sendLen = complen;
+ int uncompressed = 0;
+
+ if (PACLEN == 0)
+ PACLEN = 256;
+
+ // I think I need to know how many slots are available, so I don't compress too much
+ // Then collect data, compressing after each frame to make sure will fit in available space
+
+ while (LINK->FRAMES[n] == NULL && slots < 8)
+ {
+ slots++;
+ n++;
+ n &= 7;
+ }
+
+ maxcompsize = slots * PACLEN;
+
+ // Save first packet, then see if more on TX_Q
+
+ toCompressLen = 0;
+
+ dataLen = Msg->LENGTH - MSGHDDRLEN;
+
+ LINK->Sent += dataLen;
+
+ memcpy(&toCompress[toCompressLen], &Msg->PID, dataLen);
+ toCompressLen += dataLen;
+
+ complen = L2Compressit(Compressed, 8192, toCompress, toCompressLen);
+
+ ReleaseBuffer(Msg);
+
+ while (LINK->TX_Q)
+ {
+ Msg = LINK->TX_Q; // Leave on queue until sure it will fit
+ dataLen = Msg->LENGTH - MSGHDDRLEN -1; // PID only on 1st fragment
+
+ memcpy(&toCompress[toCompressLen], &Msg->L2DATA, dataLen);
+ toCompressLen += dataLen;
+
+ // Need to make sure we don't go over maxcompsize
+
+ complen = L2Compressit(Compressed, 8192, toCompress, toCompressLen);
+
+ if (complen > maxcompsize)
+ {
+ // Remove last fragment and compress again
+
+ toCompressLen -= dataLen;
+ complen = L2Compressit(Compressed, 8192, toCompress, toCompressLen);
+ break;
+ }
+ else
+ {
+ LINK->Sent += dataLen;
+ Msg = Q_REM(&LINK->TX_Q);
+ Msg->CHAIN = NULL;
+
+ ReleaseBuffer(Msg);
+ }
+ }
+
+ if (complen >= toCompressLen)
+ {
+ // Won't compress, so just send original data
+ // May still need to fragment
+
+ memcpy(Compressed, toCompress, toCompressLen);
+ complen = toCompressLen - 1; // Remove leading PID
+ uncompressed = 1;
+ compdata = &Compressed[1];
+ }
+ else
+ compdata = Compressed;
+
+ // We now need to packetize and add to FRAMES
+
+ LINK->SentAfterCompression += complen;
+
+ sendLen = PACLEN;
+ while (complen > 0)
+ {
+ int PID = 0xF1;
+
+ if (complen > sendLen)
+ PID = 0xF2; // More to come
+ else
+ sendLen = complen;
+
+ if (uncompressed)
+ PID = Compressed[0];
+
+ Msg = GetBuff();
+
+ if (!Msg)
+ return;
+
+ Msg->PORT = savePort;
+ Msg->PID = PID;
+
+ memcpy(&Msg->L2DATA, compdata, sendLen);
+ Msg->LENGTH = sendLen + MSGHDDRLEN + 1;
+
+ LINK->FRAMES[LINK->SDTSLOT] = Msg;
+ LINK->SDTSLOT ++;
+ LINK->SDTSLOT &= 7;
+
+ compdata += sendLen;
+ complen -= sendLen;
+ }
+
+ toCompressLen = 0;
+
+ }
+ else
+ {
+ LINK->FRAMES[LINK->SDTSLOT] = Msg;
+ LINK->SDTSLOT ++;
+ LINK->SDTSLOT &= 7;
+ }
+ }
+
// dont send while poll outstanding
while ((LINK->L2FLAGS & POLLSENT) == 0)
@@ -2901,7 +3244,7 @@ VOID L2TimerProc() if (PORT == NULL)
{
LINK++;
- continue; // just ion case!!
+ continue; // just in case!!
}
if (LINK->L2TIMER)
@@ -3000,13 +3343,25 @@ VOID L2TimerProc() {
// CIRCUIT HAS BEEN IDLE TOO LONG - SHUT IT DOWN
- LINK->KILLTIMER = 0;
- LINK->L2TIMER = 1; // TO FORCE DISC
- LINK->L2STATE = 4; // DISCONNECTING
+ // if in XID received state session was never established so don't send DISC
+
+ if (LINK->L2STATE == 1)
+ {
+ if (PORT->TNC && PORT->TNC->Hardware == H_KISSHF)
+ DetachKISSHF(PORT);
+
+ CLEAROUTLINK(LINK);
+ }
+ else
+ {
+ LINK->KILLTIMER = 0;
+ LINK->L2TIMER = 1; // TO FORCE DISC
+ LINK->L2STATE = 4; // DISCONNECTING
- // TELL OTHER LEVELS
+ // TELL OTHER LEVELS
- InformPartner(LINK, NORMALCLOSE);
+ InformPartner(LINK, NORMALCLOSE);
+ }
}
LINK++;
}
@@ -3311,6 +3666,9 @@ VOID CLEAROUTLINK(struct _LINKTABLE * LINK) CLEARL2QUEUES(LINK); // TO RELEASE ANY BUFFERS
+ if (LINK->unCompress)
+ free(LINK->unCompress);
+
memset(LINK, 0, sizeof(struct _LINKTABLE));
}
@@ -3345,7 +3703,11 @@ VOID L2SENDXID(struct _LINKTABLE * LINK) *ptr++ = 0x82; // FI
*ptr++ = 0x80; // GI
*ptr++ = 0x0;
- *ptr++ = 0x10; // Length 16
+
+ if (L2Compress)
+ *ptr++ = 0x12; // Length 18
+ else
+ *ptr++ = 0x10; // Length 16
*ptr++ = 0x02; // Classes of Procedures
*ptr++ = 0x02; // Length
@@ -3375,6 +3737,14 @@ VOID L2SENDXID(struct _LINKTABLE * LINK) *ptr++ = 0x01; // Len
*ptr++ = 0x07; // 7
+ // if L2Compress Enabled request it
+
+ if (L2Compress)
+ {
+ *ptr++ = 0x10; // Compress
+ *ptr++ = 0x00; // Len
+ }
+
Buffer->LENGTH = (int)(ptr - (UCHAR *)Buffer); // SET LENGTH
LINK->L2TIMER = ONEMINUTE; // (RE)SET TIMER
@@ -3578,7 +3948,6 @@ CheckNSLoop2: struct PORTCONTROL * PORT = LINK->LINKPORT;
MESSAGE * OldBuffer = Q_REM(&LINK->RXFRAMES[LINK->LINKNR]);
- Debugprintf("L2 about to send REJ - process saved Frame %d", LINK->LINKNR);
PROC_I_FRAME(LINK, PORT, OldBuffer); // Passes on or releases Buffer
// NR has been updated.
@@ -3636,7 +4005,9 @@ VOID CONNECTREFUSED(struct _LINKTABLE * LINK) ConnectFailedOrRefused(LINK, "Busy from");
}
-VOID L3CONNECTFAILED(struct _LINKTABLE * LINK);
+
+VOID L3LINKSETUPFAILED(struct _LINKTABLE * LINK);
+
VOID ConnectFailedOrRefused(struct _LINKTABLE * LINK, char * Msg)
{
@@ -3651,7 +4022,7 @@ VOID ConnectFailedOrRefused(struct _LINKTABLE * LINK, char * Msg) if (LINK->LINKTYPE == 3)
{
- L3CONNECTFAILED(LINK); // REPORT TO LEVEL 3
+ L3LINKSETUPFAILED(LINK); // REPORT TO LEVEL 3
return;
}
@@ -4178,6 +4549,33 @@ int seeifUnlockneeded(struct _LINKTABLE * LINK) return 0;
}
+int L2Compressit(unsigned char * Out, int OutSize, unsigned char * In, int Len)
+{
+ z_stream defstream;
+ int maxSize;
+
+ defstream.zalloc = Z_NULL;
+ defstream.zfree = Z_NULL;
+ defstream.opaque = Z_NULL;
+
+ defstream.avail_in = Len; // size of input
+ defstream.next_in = (Bytef *)In; // input char array
+
+ deflateInit(&defstream, Z_BEST_COMPRESSION);
+ maxSize = deflateBound(&defstream, Len);
+
+ if (maxSize > OutSize)
+ return 0;
+
+ defstream.avail_out = maxSize; // size of output
+ defstream.next_out = (Bytef *)Out; // output char array
+
+ deflate(&defstream, Z_FINISH);
+ deflateEnd(&defstream);
+
+ return defstream.total_out;
+}
+
|
