int smb_read_error = 0;
+static char *get_socket_addr(int fd)
+{
+ struct sockaddr sa;
+ struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
+ int length = sizeof(sa);
+ static fstring addr_buf;
+
+ fstrcpy(addr_buf,"0.0.0.0");
+
+ if (fd == -1) {
+ return addr_buf;
+ }
+
+ if (getsockname(fd, &sa, &length) < 0) {
+ DEBUG(0,("getpeername failed. Error was %s\n", strerror(errno) ));
+ return addr_buf;
+ }
+
+ fstrcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr));
+
+ return addr_buf;
+}
+
/****************************************************************************
Determine if a file descriptor is in fact a socket.
****************************************************************************/
smb_read_error = READ_ERROR;
return False;
}
+
+ /* not all of samba3 properly checks for packet-termination of strings. This
+ ensures that we don't run off into empty space. */
+ SSVAL(buffer+4,len, 0);
}
return True;
/* create a socket to write to */
res = socket(PF_INET, type, 0);
if (res == -1) {
- DEBUG(0,("socket error\n"));
+ DEBUG(0,("socket error (%s)\n", strerror(errno)));
return -1;
}
/* Some systems return EAGAIN when they mean EINPROGRESS */
if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
errno == EAGAIN) && (connect_loop < timeout) ) {
- msleep(connect_loop);
+ smb_msleep(connect_loop);
connect_loop += increment;
if (increment < 250) {
/* After 8 rounds we end up at a max of 255 msec */
char *client_name(void)
{
- return get_socket_name(client_fd,False);
+ return get_peer_name(client_fd,False);
}
char *client_addr(void)
+{
+ return get_peer_addr(client_fd);
+}
+
+char *client_socket_addr(void)
{
return get_socket_addr(client_fd);
}
Return the DNS name of the remote end of a socket.
******************************************************************/
-char *get_socket_name(int fd, BOOL force_lookup)
+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;
with dns. To avoid the delay we avoid the lookup if
possible */
if (!lp_hostname_lookups() && (force_lookup == False)) {
- return get_socket_addr(fd);
+ return get_peer_addr(fd);
}
- p = get_socket_addr(fd);
+ p = get_peer_addr(fd);
/* it might be the same as the last one - save some DNS work */
- if (strcmp(p, addr_buf) == 0) return name_buf;
+ if (strcmp(p, addr_buf) == 0)
+ return name_buf;
pstrcpy(name_buf,"UNKNOWN");
- if (fd == -1) return name_buf;
+ if (fd == -1)
+ return name_buf;
fstrcpy(addr_buf, p);
}
}
- alpha_strcpy(name_buf, name_buf, "_-.", sizeof(name_buf));
+ /* can't pass the same source and dest strings in when you
+ use --enable-developer or the clobber_region() call will
+ get you */
+
+ pstrcpy( tmp_name, name_buf );
+ alpha_strcpy(name_buf, tmp_name, "_-.", sizeof(name_buf));
if (strstr(name_buf,"..")) {
pstrcpy(name_buf, "UNKNOWN");
}
Return the IP addr of the remote end of a socket as a string.
******************************************************************/
-char *get_socket_addr(int fd)
+char *get_peer_addr(int fd)
{
struct sockaddr sa;
struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);