OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_ch_socket.c versions 1.16 and 1.17
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/l2/l2_ch_socket.c 1.16 -> 1.17

--- l2_ch_socket.c       2001/09/06 16:10:05     1.16
+++ l2_ch_socket.c       2001/09/06 16:14:54     1.17
@@ -95,8 +95,7 @@
 #endif
 
 /* declare private channel configuration */
-typedef struct
-{
+typedef struct {
     int iFamily;             /* IP version to use, AF_INET4 or AF_INET6  */
     char *pszHost;           /* IP Address or name of host to connect to */
     int iPort;               /* TCP Port to connect to                   */
@@ -144,36 +143,31 @@
 static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch)
 {
     l2_ch_socket_t *cfg = (l2_ch_socket_t *)ctx->vp;
-    struct hostent      *pHostentry;
-    struct sockaddr_in  IP4Sockaddr;
+    struct hostent *pHostentry;
+    struct sockaddr_in IP4Sockaddr;
     struct sockaddr_in6 IP6Sockaddr;
-    struct in6_addr     *IP6Addr;
+    struct in6_addr *IP6Addr;
 
     /* make sure a target is configured */
     if (cfg->pszHost == NULL)
         return L2_ERR_USE;
 
-    /* open channel socket      */
-    if (cfg->iFamily == AF_INET) /* IPv4 */
-    {
+    /* open channel socket */
+    if (cfg->iFamily == AF_INET) { /* IPv4 */
         /* resolve host numerically */
-        if (inet_pton(AF_INET, cfg->pszHost, &IP4Sockaddr.sin_addr.s_addr) == 1)
-        {
+        if (inet_pton(AF_INET, cfg->pszHost, &IP4Sockaddr.sin_addr.s_addr) == 1) {
             IP4Sockaddr.sin_family = AF_INET;
             IP4Sockaddr.sin_port   = htons(cfg->iPort);
         }
 
         /* resolve host nominally */
-        else if ((pHostentry = gethostbyname(cfg->pszHost)) != NULL)
-        {
-            if (pHostentry->h_addrtype == AF_INET)
-            {
+        else if ((pHostentry = gethostbyname(cfg->pszHost)) != NULL) {
+            if (pHostentry->h_addrtype == AF_INET) {
                 IP4Sockaddr.sin_family = AF_INET;
                 IP4Sockaddr.sin_port   = htons(cfg->iPort);
-                memcpy(&IP4Sockaddr.sin_addr.s_addr, pHostentry->h_addr_list[0],\
-                    sizeof(IP4Sockaddr.sin_addr.s_addr));
+                memcpy(&IP4Sockaddr.sin_addr.s_addr, pHostentry->h_addr_list[0],
+                       sizeof(IP4Sockaddr.sin_addr.s_addr));
             }
-
             else
                 return L2_ERR_USE; /* what?? we specify IPv4 when it is not? */
         }
@@ -184,8 +178,7 @@
         if ((cfg->iSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
             return L2_ERR_SYS;
 
-        if (connect(cfg->iSocket, (struct sockaddr *)&IP4Sockaddr, sizeof(IP4Sockaddr)))
-        {
+        if (connect(cfg->iSocket, (struct sockaddr *)&IP4Sockaddr, sizeof(IP4Sockaddr))) {
             close(cfg->iSocket);
             return L2_ERR_SYS;
         }
@@ -193,26 +186,21 @@
         return L2_OK; /* we are connected */
     }
 
-    else if (cfg->iFamily == AF_INET6) /* IPv6 */
-    {
+    else if (cfg->iFamily == AF_INET6) { /* IPv6 */
         /* resolve host numerically */
-        if (inet_pton(AF_INET6, cfg->pszHost, &IP6Sockaddr.sin6_addr.s6_addr) == 1)
-        {
+        if (inet_pton(AF_INET6, cfg->pszHost, &IP6Sockaddr.sin6_addr.s6_addr) == 1) {
             IP6Sockaddr.sin6_family = AF_INET6;
             IP6Sockaddr.sin6_port   = htons(cfg->iPort);
         }
 
         /* resolve host nominally */
-        else if (pHostentry = gethostbyname(cfg->pszHost) != NULL)
-        {
-            if (pHostentry->h_addrtype == AF_INET6)
-            {
+        else if (pHostentry = gethostbyname(cfg->pszHost) != NULL) {
+            if (pHostentry->h_addrtype == AF_INET6) {
                 IP6Sockaddr.sin6_family = AF_INET6;
                 IP6Sockaddr.sin6_port   = htons(cfg->iPort);
                 memcpy(&IP6Sockaddr.sin6_addr.__u6_addr, pHostentry->h_addr_list[0],\
                     sizeof(IP6Sockaddr.sin6_addr.__u6_addr));
             }
-
             else
                 return L2_ERR_USE; /* what?? we specify IPv6 when it is not? */
         }
@@ -223,8 +211,7 @@
         if ((cfg->iSocket = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP)) == -1)
             return L2_ERR_SYS;
 
-        if (connect(cfg->iSocket, (struct sockaddr *)&IP6Sockaddr, sizeof(IP6Sockaddr)))
-        {
+        if (connect(cfg->iSocket, (struct sockaddr *)&IP6Sockaddr, sizeof(IP6Sockaddr))) {
             close(cfg->iSocket);
             return L2_ERR_SYS;
         }
@@ -240,22 +227,20 @@
                       const char *buf, size_t buf_size)
 {
     l2_ch_socket_t *cfg = (l2_ch_socket_t *)ctx->vp;
-    size_t          sizeWrite;
-    size_t          sizeRemain;
+    size_t sizeWrite;
+    size_t sizeRemain;
 
     /* parameter checks */
     if (cfg->iSocket == -1)
         return L2_ERR_USE;
 
-    /* write message to channel socket, but check to make   */
-    /* sure that the whole message was successfully written */
+    /* write message to channel socket, but check to make 
+       sure that the whole message was successfully written */
     sizeWrite  = 0;
     sizeRemain = buf_size;
-    while(sizeRemain)
-    {
+    while (sizeRemain) {
         sizeWrite  = send(cfg->iSocket, buf + sizeWrite, sizeRemain, 0);
-        sizeRemain = sizeRemain - sizeWrite; /* how much is left? */
-
+        sizeRemain = sizeRemain - sizeWrite;
         if (sizeWrite == -1)
             return L2_ERR_SYS;
     }

CVSTrac 2.0.1