]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - lib/rfcnb/rfcnb-util.c
Source Format Enforcement (#532)
[thirdparty/squid.git] / lib / rfcnb / rfcnb-util.c
index f1e7ef251fc152242e9f174d92366a85eaa5c834..363d4533b3acd1f234fc94f090e8db7c74edcedc 100644 (file)
@@ -1,4 +1,10 @@
-#include "config.h"
+/*
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
 
 /* UNIX RFCNB (RFC1001/RFC1002) NetBIOS implementation
  *
@@ -6,7 +12,6 @@
  * RFCNB Utility Routines ...
  *
  * Copyright (C) Richard Sharpe 1996
- *
  */
 
 /*
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include "rfcnb/rfcnb.h"
-#include "rfcnb/std-includes.h"
+#include "squid.h"
+#include "rfcnb/rfcnb-io.h"
 #include "rfcnb/rfcnb-priv.h"
 #include "rfcnb/rfcnb-util.h"
-#include "rfcnb/rfcnb-io.h"
+#include "rfcnb/rfcnb.h"
+#include "rfcnb/std-includes.h"
 
 #if HAVE_ARPA_INET_H
 #include <arpa/inet.h>
@@ -38,8 +44,6 @@
 #include <string.h>
 #endif
 
-extern void (*Prot_Print_Routine) (FILE * fd, int dir, struct RFCNB_Pkt * pkt, int header, int payload);   /* Pointer to protocol print routine */
-
 const char *RFCNB_Error_Strings[] = {
     "RFCNBE_OK: Routine completed successfully.",
     "RFCNBE_NoSpace: No space available for a malloc call.",
@@ -364,10 +368,10 @@ RFCNB_Name_To_IP(char *host, struct in_addr *Dest_IP)
 
 /* Disconnect the TCP connection to the server */
 int
-RFCNB_Close(int socket)
+RFCNB_Close(int fd)
 {
 
-    close(socket);
+    close(fd);
 
     /* If we want to do error recovery, here is where we put it */
 
@@ -427,6 +431,7 @@ RFCNB_Session_Req(struct RFCNB_Con *con,
     char resp[16];
     int len;
     struct RFCNB_Pkt *pkt, res_pkt;
+    int result = 0;
 
     /* We build and send the session request, then read the response */
 
@@ -452,7 +457,7 @@ RFCNB_Session_Req(struct RFCNB_Con *con,
 #endif
 
     if ((len = RFCNB_Put_Pkt(con, pkt, RFCNB_Pkt_Sess_Len)) < 0) {
-
+        RFCNB_Free_Pkt(pkt);
         return (RFCNBE_Bad);    /* Should be able to write that lot ... */
 
     }
@@ -465,7 +470,7 @@ RFCNB_Session_Req(struct RFCNB_Con *con,
     res_pkt.next = NULL;
 
     if ((len = RFCNB_Get_Pkt(con, &res_pkt, sizeof(resp))) < 0) {
-
+        RFCNB_Free_Pkt(pkt);
         return (RFCNBE_Bad);
 
     }
@@ -499,12 +504,12 @@ RFCNB_Session_Req(struct RFCNB_Con *con,
             break;
         }
 
-        return (RFCNBE_Bad);
+        result = (RFCNBE_Bad);
         break;
 
     case RFCNB_SESSION_ACK:     /* Got what we wanted ...      */
 
-        return (0);
+        result = (0);
         break;
 
     case RFCNB_SESSION_RETARGET:        /* Go elsewhere                */
@@ -514,13 +519,17 @@ RFCNB_Session_Req(struct RFCNB_Con *con,
         memcpy(Dest_IP, (resp + RFCNB_Pkt_IP_Offset), sizeof(struct in_addr));
         *port = SVAL(resp, RFCNB_Pkt_Port_Offset);
 
-        return (0);
+        result = (0);
         break;
 
     default:                    /* A protocol error */
 
         RFCNB_errno = RFCNBE_ProtErr;
-        return (RFCNBE_Bad);
+        result = (RFCNBE_Bad);
         break;
     }
+
+    RFCNB_Free_Pkt(pkt);
+    return result;
 }
+