OSSP CVS Repository

ossp - Check-in [883]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 883
Date: 2001-Sep-07 12:23:31 (local)
2001-Sep-07 10:23:31 (UTC)
User:ms
Branch:
Comment: Cleaned up and KR styled.
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2_ch_socket.c      1.18 -> 1.19     17 inserted, 42 deleted

ossp-pkg/l2/l2_ch_socket.c 1.18 -> 1.19

--- l2_ch_socket.c       2001/09/06 19:28:24     1.18
+++ l2_ch_socket.c       2001/09/07 10:23:31     1.19
@@ -46,27 +46,22 @@
  ******************************************************************/
 static int inet_pton(int iFamily, const char *pszAddress, void *pvMemref)
 {
-    int             i    = 0;
+    int             i             = 0;
     struct in_addr  IP4Addr;
     struct in6_addr IP6Addr;
     char            *pszIndex     = NULL;    /* To index IPv6 validity */
     char            *pszNextfield = -1;      /* For IPv6 address trans */
 
-    if (iFamily == AF_INET)
-    {
-        if (inet_aton(pszAddress, &IP4Addr))
-        {
+    if (iFamily == AF_INET) {
+        if (inet_aton(pszAddress, &IP4Addr)) {
             memcpy(pvMemref, &IP4Addr, sizeof(struct in_addr));
             return 1; /* Success */
         }
         return 0;
     }
-
-    else if (iFamily == AF_INET6) /* If we are translating IPv6 addresses     */
-    {                             /* the user needs to use precise notation   */
-        pszIndex = pszAddress;    /* Initialize, verify in loop               */
-        for (i = 0; (i < 8) && pszNextfield; i++) /* Iterate through fields   */
-        {
+    else if (iFamily == AF_INET6) { /* Translate IPv6 addresses               */
+        pszIndex = pszAddress;      /* Initialize, verify in loop             */
+        for (i = 0; (i < 8) && pszNextfield; i++) { /* Iterate through fields */
             IP6Addr.__u6_addr.__u6_addr16[i] =\
                 ntohs((u_int16_t)strtol(pszIndex, &pszNextfield, 16));
             pszIndex = pszNextfield + 1;
@@ -74,17 +69,12 @@
 
         if ((i != 8) || (*pszNextfield))
             return 0;
-
-        else /* Success */
-        {
+        else { /* Success */
             memcpy(pvMemref, &IP6Addr, sizeof(struct in6_addr));
             return 1;
         }
-
     }
-
-    else      /* User converting from an address family that we don't support */
-    {
+    else {    /* User converting from an address family that we don't support */
         errno = EAFNOSUPPORT;
         return -1;
     }
@@ -164,7 +154,6 @@
             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) {
@@ -176,17 +165,15 @@
             else
                 return L2_ERR_USE; /* what?? we specify IPv4 when it is not? */
         }
-
         else /* host string was not parsable for some reason */
             return L2_ERR_SYS;
 
-        if (cfg->iProto == IPPROTO_TCP) /* With TCP we must connect */
-        {
+        if (cfg->iProto == IPPROTO_TCP) {        /* With TCP we must connect */
             if ((cfg->iSocket = socket(PF_INET, SOCK_STREAM, cfg->iProto)) == -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;
             }
@@ -197,14 +184,12 @@
 
         return L2_OK;
     }
-
     else if (cfg->iFamily == AF_INET6) { /* IPv6 */
         /* resolve host numerically */
         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) {
@@ -216,7 +201,6 @@
             else
                 return L2_ERR_USE; /* what?? we specify IPv6 when it is not? */
         }
-
         else /* host string was not parsable for some reason */
             return L2_ERR_SYS;
 
@@ -253,14 +237,12 @@
     if (cfg->iSocket == -1)
         return L2_ERR_ARG;
 
-    if (cfg->iProto == IPPROTO_TCP)
-    {
+    if (cfg->iProto == IPPROTO_TCP) {
         /* 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? */
 
@@ -268,17 +250,13 @@
                 return L2_ERR_SYS;
         }
     }
-
-    else if (cfg->iProto == IPPROTO_UDP)
-    {
+    else if (cfg->iProto == IPPROTO_UDP) {
         /* write message to the host target, but check to make  */
         /* sure that the whole message was successfully written */
         sizeWrite  = 0;
         sizeRemain = buf_size;
-        while(sizeRemain)
-        {
-            if (cfg->iFamily == AF_INET) /* IPv4 */
-            {
+        while(sizeRemain) {
+            if (cfg->iFamily == AF_INET) { /* IPv4 */
 /* TODO !!! */  sizeWrite  = sendto(cfg->iSocket, buf + sizeWrite, sizeRemain, 0,\
 /* Fill in  */      (struct sockaddr *)&IP4Sockaddr, sizeof(IP4Sockaddr));
 /* the host */
@@ -287,9 +265,7 @@
                 if (sizeWrite == -1)
                     return L2_ERR_SYS;
             }
-
-            else if (cfg->iFamily == AF_INET6) /* IPv6 */
-            {
+            else if (cfg->iFamily == AF_INET6) { /* IPv6 */
  /* TODO !!! */     sizeWrite  = sendto(cfg->iSocket, buf + sizeWrite, sizeRemain, 0,\
  /* Fill in  */         (struct sockaddr *)&IP6Sockaddr, sizeof(IP6Sockaddr));
  /* the host */
@@ -298,7 +274,6 @@
                 if (sizeWrite == -1)
                     return L2_ERR_USE;
             }
-
             else /* Neither IPv4 nor IPv6 */
                 return L2_ERR_USE;
         }

CVSTrac 2.0.1