Add const to the get_peer_addr() and get_socket_addr()
authorJeremy Allison <jra@samba.org>
Thu, 11 Oct 2007 22:36:13 +0000 (15:36 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 11 Oct 2007 22:36:13 +0000 (15:36 -0700)
calls. Use the IPv6 varient for get_peer_addr().
Jeremy.
(This used to be commit baf1f52e34ae2465a7a34be1065da29ed97e7bea)

source3/lib/util_sock.c
source3/printing/print_cups.c
source3/printing/print_iprint.c
source3/smbd/session.c
source3/smbd/sesssetup.c
source3/web/cgi.c

index 7a1a05ec294c64f0d9e223196d82af6836093955..5a96bb79d6e56a79224836903d9fde1a087fb273 100644 (file)
@@ -388,7 +388,7 @@ void client_setfd(int fd)
  Return a static string of an IP address (IPv4 or IPv6).
 ****************************************************************************/
 
-static char *get_socket_addr(int fd)
+static const char *get_socket_addr(int fd)
 {
        struct sockaddr_storage sa;
        socklen_t length = sizeof(sa);
@@ -444,17 +444,17 @@ static int get_socket_port(int fd)
        return -1;
 }
 
-char *client_name(void)
+const char *client_name(void)
 {
        return get_peer_name(client_fd,false);
 }
 
-char *client_addr(void)
+const char *client_addr(void)
 {
        return get_peer_addr(client_fd);
 }
 
-char *client_socket_addr(void)
+const char *client_socket_addr(void)
 {
        return get_socket_addr(client_fd);
 }
@@ -1598,14 +1598,14 @@ static bool matchname(char *remotehost,struct in_addr  addr)
  Return the DNS name of the remote end of a socket.
 ******************************************************************/
 
-char *get_peer_name(int fd, bool force_lookup)
+const char *get_peer_name(int fd, bool force_lookup)
 {
        static pstring name_buf;
        pstring tmp_name;
        static fstring addr_buf;
        struct hostent *hp;
        struct in_addr addr;
-       char *p;
+       const char *p;
 
        /* reverse lookups can be *very* expensive, and in many
           situations won't work because many networks don't link dhcp
@@ -1659,27 +1659,28 @@ char *get_peer_name(int fd, bool force_lookup)
  Return the IP addr of the remote end of a socket as a string.
  ******************************************************************/
 
-char *get_peer_addr(int fd)
+const char *get_peer_addr(int fd)
 {
-       struct sockaddr sa;
-       struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
-       socklen_t length = sizeof(sa);
-       static fstring addr_buf;
+       struct sockaddr_storage ss;
+       socklen_t length = sizeof(ss);
+       static char addr_buf[INET6_ADDRSTRLEN];
 
-       fstrcpy(addr_buf,"0.0.0.0");
+       safe_strcpy(addr_buf,"0.0.0.0",sizeof(addr_buf)-1);
 
        if (fd == -1) {
                return addr_buf;
        }
 
-       if (getpeername(fd, &sa, &length) < 0) {
+       if (getpeername(fd, (struct sockaddr *)&ss, &length) < 0) {
                DEBUG(0,("getpeername failed. Error was %s\n",
                                        strerror(errno) ));
                return addr_buf;
        }
 
-       fstrcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr));
-
+       print_sockaddr(addr_buf,
+                       sizeof(addr_buf),
+                       &ss,
+                       length);
        return addr_buf;
 }
 
index 8f1f06e7efe5906ce61529c7147509cb4228a597..d95b08c3c69488ed32d4f2f2da224f1ce69388d6 100644 (file)
@@ -563,7 +563,7 @@ static int cups_job_submit(int snum, struct printjob *pjob)
                        *response = NULL;       /* IPP Response */
        cups_lang_t     *language = NULL;       /* Default language */
        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
-       char            *clientname = NULL;     /* hostname of client for job-originating-host attribute */
+       const char      *clientname = NULL;     /* hostname of client for job-originating-host attribute */
        pstring         new_jobname;
        int             num_options = 0; 
        cups_option_t   *options = NULL;
index f2b27460bea74b650b68e92741720e4f81c83fc2..82095925b8bf1a42fac49231546419a30e680046 100644 (file)
@@ -726,7 +726,7 @@ static int iprint_job_submit(int snum, struct printjob *pjob)
        ipp_attribute_t *attr;          /* Current attribute */
        cups_lang_t     *language = NULL;       /* Default language */
        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
-       char            *clientname = NULL;     /* hostname of client for job-originating-host attribute */
+       const char      *clientname = NULL;     /* hostname of client for job-originating-host attribute */
 
        DEBUG(5,("iprint_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
 
@@ -782,7 +782,7 @@ static int iprint_job_submit(int snum, struct printjob *pjob)
        if (strcmp(clientname, "UNKNOWN") == 0) {
                clientname = client_addr();
        }
-
+       
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
                     "job-originating-host-name", NULL,
                     clientname);
index 8dd321fad7c4d8f84e5f91669e92ccb02271ae73..54d2ddf721cb238d374422e47dcdfcfbd4fb41ad 100644 (file)
@@ -65,7 +65,7 @@ BOOL session_claim(user_struct *vuser)
        struct sessionid sessionid;
        struct server_id pid = procid_self();
        fstring keystr;
-       char * hostname;
+       const char * hostname;
        struct db_context *ctx;
        struct db_record *rec;
        NTSTATUS status;
index 20021ec7f78c302c3004429181d53cfcba6f1fa0..a2f24c66d2760cc34a3ba682a1c49cbf0a378dd2 100644 (file)
@@ -1314,7 +1314,8 @@ static void setup_new_vc_session(void)
        invalidate_all_vuids();
 #endif
        if (lp_reset_on_zero_vc()) {
-               connections_forall(shutdown_other_smbds, client_addr());
+               connections_forall(shutdown_other_smbds,
+                               CONST_DISCARD(void *,client_addr()));
        }
 }
 
index 9af4337a21eae13cf8001c7944becbe0bb20b6a4..0e362ea2454d40db6d06728a1c18c2f656c2e4aa 100644 (file)
@@ -633,7 +633,7 @@ const char *cgi_pathinfo(void)
 /***************************************************************************
 return the hostname of the client
   ***************************************************************************/
-char *cgi_remote_host(void)
+const char *cgi_remote_host(void)
 {
        if (inetd_server) {
                return get_peer_name(1,False);
@@ -644,7 +644,7 @@ char *cgi_remote_host(void)
 /***************************************************************************
 return the hostname of the client
   ***************************************************************************/
-char *cgi_remote_addr(void)
+const char *cgi_remote_addr(void)
 {
        if (inetd_server) {
                return get_peer_addr(1);