--------------------- PatchSet 5924 Date: 2007/10/07 01:11:03 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Half-blind coversion of windows IPC to protocol-neutral code. Members: src/ipc_win32.cc:1.3.6.5->1.3.6.6 Index: squid3/src/ipc_win32.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ipc_win32.cc,v retrieving revision 1.3.6.5 retrieving revision 1.3.6.6 diff -u -r1.3.6.5 -r1.3.6.6 --- squid3/src/ipc_win32.cc 23 Aug 2007 04:27:07 -0000 1.3.6.5 +++ squid3/src/ipc_win32.cc 7 Oct 2007 01:11:03 -0000 1.3.6.6 @@ -1,6 +1,5 @@ - /* - * $Id: ipc_win32.cc,v 1.3.6.5 2007/08/23 04:27:07 amosjeffries Exp $ + * $Id: ipc_win32.cc,v 1.3.6.6 2007/10/07 01:11:03 amosjeffries Exp $ * * DEBUG: section 54 Windows Interprocess Communication * AUTHOR: Andrey Shorin @@ -118,15 +117,14 @@ DWORD ecode = 0; pid_t pid; -// INET6 TODO: IPv6-enable this function. - struct sockaddr_in CS; - struct sockaddr_in PS; + IPAddress tmp_addr; + struct addrinfo *aiCS = NULL; + struct addrinfo *aiPS = NULL; int crfd = -1; int prfd = -1; int cwfd = -1; int pwfd = -1; - socklen_t len; int x; requirePathnameExists(name, prog); @@ -200,25 +198,30 @@ return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } +// AYJ: these flags should be neutral, but if not IPv6 version needs adding if (type == IPC_TCP_SOCKET || type == IPC_UDP_SOCKET) { - len = sizeof(PS); - memset(&PS, '\0', len); - if (getsockname(pwfd, (struct sockaddr *) &PS, &len) < 0) { + tmp_addr.InitAddrInfo(aiPS); + + if (getsockname(pwfd, aiPS.ai_addr, &aiPS.ai_addrlen) < 0) { debugs(54, 0, "ipcCreate: getsockname: " << xstrerror()); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } - debugs(54, 3, "ipcCreate: FD " << pwfd << " sockaddr " << inet_ntoa(PS.sin_addr) << ":" << ntohs(PS.sin_port)); - len = sizeof(CS); - memset(&CS, '\0', len); + tmp_addr = *aiPS; + + debugs(54, 3, "ipcCreate: FD " << pwfd << " sockaddr " << tmp_addr ); + + tmp_addr.InitAddrInfo(aiCS); - if (getsockname(crfd, (struct sockaddr *) &CS, &len) < 0) { + if (getsockname(crfd, aiCS.ai_addr, &aiCS.ai_addrlen) < 0) { debugs(54, 0, "ipcCreate: getsockname: " << xstrerror()); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } - debugs(54, 3, "ipcCreate: FD " << crfd << " sockaddr " << inet_ntoa(CS.sin_addr) << ":" << ntohs(CS.sin_port)); + tmp_addr = *aiCS; + + debugs(54, 3, "ipcCreate: FD " << crfd << " sockaddr " << tmp_addr ); } if (type == IPC_TCP_SOCKET) { @@ -239,7 +242,7 @@ params.cwfd = cwfd; - params.PS = PS; + params.PS = *aiPS; params.prog = prog; @@ -378,7 +381,10 @@ int prfd_ipc = -1, pwfd_ipc = -1, crfd_ipc = -1, cwfd_ipc = -1; char *prog = NULL, *buf1 = NULL; - struct sockaddr_in CS_ipc, PS_ipc; + IPAddress PS_ipc; + IPAddress CS_ipc; + struct addrinfo *aiPS_ipc = NULL; + struct addrinfo *aiCS_ipc = NULL; struct ipc_params *params = (struct ipc_params *) in_params; int type = params->type; @@ -386,8 +392,7 @@ int cwfd = params->cwfd; char **args = params->args; - struct sockaddr_in PS = params->PS; - + IPAddress PS = params->PS; buf1 = (char *)xcalloc(1, 8192); strcpy(buf1, params->prog); @@ -416,7 +421,7 @@ fd_table[fd].flags.ipc = 1; cwfd = crfd = fd; } else if (type == IPC_UDP_SOCKET) { - if (comm_connect_addr(crfd, &PS) == COMM_ERROR) + if (comm_connect_addr(crfd, params->PS) == COMM_ERROR) goto cleanup; } @@ -475,36 +480,38 @@ goto cleanup; } - tmp_s = sizeof(PS_ipc); - memset(&PS_ipc, '\0', tmp_s); + PS_ipc.InitAddrInfo(aiPS_ipc); - if (getsockname(pwfd_ipc, (struct sockaddr *) &PS_ipc, &tmp_s) < 0) { + if (getsockname(pwfd_ipc, aiPS_ipc->ai_addr, &(aiPS_ipc->ai_addrlen)) < 0) { debugs(54, 0, "ipcCreate: getsockname: " << xstrerror()); ipcSend(cwfd, err_string, strlen(err_string)); goto cleanup; } - debugs(54, 3, "ipcCreate: FD " << pwfd_ipc << " sockaddr " << inet_ntoa(PS_ipc.sin_addr) << ":" << ntohs(PS_ipc.sin_port)); + PS_ipc = *aiPS_ipc; - tmp_s = sizeof(CS_ipc); - memset(&CS_ipc, '\0', tmp_s); + debugs(54, 3, "ipcCreate: FD " << pwfd_ipc << " sockaddr " << PS_ipc); - if (getsockname(crfd_ipc, (struct sockaddr *) &CS_ipc, &tmp_s) < 0) { + PS_ipc.InitAddrInfo(aiCS_ipc); + + if (getsockname(crfd_ipc, aiCS_ipc->ai_addr, &(aiCS_ipc->ai_addrlen)) < 0) { debugs(54, 0, "ipcCreate: getsockname: " << xstrerror()); ipcSend(cwfd, err_string, strlen(err_string)); goto cleanup; } - debugs(54, 3, "ipcCreate: FD " << crfd_ipc << " sockaddr " << inet_ntoa(CS_ipc.sin_addr) << ":" << ntohs(CS_ipc.sin_port)); + CS_ipc = *aiCS_ipc; + + debugs(54, 3, "ipcCreate: FD " << crfd_ipc << " sockaddr " << CS_ipc); - if (comm_connect_addr(pwfd_ipc, &CS_ipc) == COMM_ERROR) { + if (comm_connect_addr(pwfd_ipc, CS_ipc) == COMM_ERROR) { ipcSend(cwfd, err_string, strlen(err_string)); goto cleanup; } fd = crfd; - if (comm_connect_addr(crfd_ipc, &PS_ipc) == COMM_ERROR) { + if (comm_connect_addr(crfd_ipc, PS_ipc) == COMM_ERROR) { ipcSend(cwfd, err_string, strlen(err_string)); goto cleanup; }