]> Pileus Git - ~andy/fetchmail/blobdiff - socket.c
Remove port/service dualism and make everything a service.
[~andy/fetchmail] / socket.c
index 80caa30332a64fd3f8391f03c2b85ec070714f97..dc1d960dd78f796efba2748af25305ad9c76d262 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -319,7 +319,7 @@ int SockOpen(const char *host, const char *service,
 #endif
 #endif /* HAVE_INET_ATON */
 
-int SockOpen(const char *host, int clientPort,
+int SockOpen(const char *host, const char *service,
             const char *plugin)
 {
     int sock = -1;     /* pacify -Wall */
@@ -328,6 +328,7 @@ int SockOpen(const char *host, int clientPort,
 #endif /* HAVE_INET_ATON */
     struct sockaddr_in ad, **pptr;
     struct hostent *hp;
+    int clientPort = servport(service);
 
 #ifdef HAVE_SOCKETPAIR
     if (plugin) {
@@ -337,6 +338,9 @@ int SockOpen(const char *host, int clientPort,
     }
 #endif /* HAVE_SOCKETPAIR */
 
+    if (clientPort < 0)
+       return sock;
+
     memset(&ad, 0, sizeof(ad));
     ad.sin_family = AF_INET;
 
@@ -359,11 +363,11 @@ int SockOpen(const char *host, int clientPort,
             return -1;
         }
 
-               /* Socket opened saved. Usefull if connect timeout because
-                * it can be closed
-                */
-               mailserver_socket_temp = sock;
-               
+       /* Socket opened saved. Usefull if connect timeout because
+        * it can be closed
+        */
+       mailserver_socket_temp = sock;
+
         if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0)
         {
             int olderr = errno;
@@ -1072,7 +1076,7 @@ static ssize_t cygwin_read(int sock, void *buf, size_t count)
  * inetd.conf (and then SIGHUP inetd) for this to work.  */
 main()
 {
-    int                sock = SockOpen("localhost", 19, NULL);
+    int                sock = SockOpen("localhost", "chargen", NULL);
     char       buf[80];
 
     while (SockRead(sock, buf, sizeof(buf)-1))