]> git.sur5r.net Git - ngadmin/commitdiff
Add error codes to handle bad replies and unknown errors
authordarkcoven <admin@darkcoven.tk>
Fri, 18 Oct 2013 20:59:08 +0000 (22:59 +0200)
committerdarkcoven <admin@darkcoven.tk>
Fri, 18 Oct 2013 20:59:08 +0000 (22:59 +0200)
cli/src/common.c
lib/include/ngadmin.h
lib/src/mirror.c
lib/src/network.c
lib/src/vlan.c

index 80f3f522fc048981c595f2ad1d126c251cfb9c58..7d35301eff059d4445435e0b540643126d877ac5 100644 (file)
@@ -40,6 +40,14 @@ void printErrCode (int err)
                printf("not implemented\n");
                break;
        
+       case ERR_BADREPLY:
+               printf("bad reply from switch\n");
+               break;
+       
+       case ERR_UNKNOWN:
+               printf("unknown error\n");
+               break;
+       
        default:
                printf("unknown status code (%i)\n", err);
        }
index a14917c0ef08169776d1b4a0ef9072168e0ce177..a98f42959eebd9363e6cd15ab7785339ae9effed 100644 (file)
@@ -48,7 +48,9 @@ enum {
        ERR_INVARG = -6,                /**< invalid argument */
        ERR_TIMEOUT = -7,               /**< timeout */
        ERR_MEM = -8,                   /**< out of memory */
-       ERR_NOTIMPL = -9                /**< not implemented */
+       ERR_NOTIMPL = -9,               /**< not implemented */
+       ERR_BADREPLY = -10,             /**< bad reply */
+       ERR_UNKNOWN = -11               /**< unknown error */
 };
 
 
index be4073847a7cc435e802cf080dc4b83bbd11d116..8b76c1ce08285ed935c8549e8dc8d7a46db6d742 100644 (file)
@@ -43,7 +43,7 @@ int ngadmin_getMirror (struct ngadmin *nga, char *ports)
                        memset(ports, 0, 1 + sa->ports);
                } else if (am->outport > 0 && at->size >= 1 + sa->ports) {
                        if (at->size < sizeof(struct attr_mirror) + sa->ports) {
-                               ret = ERR_INVARG;
+                               ret = ERR_BADREPLY;
                                goto end;
                        }
                        ports[0] = am->outport;
index e10659620a2b765639c00aa3947b43af2cc7d0e1..b48461c1fdb903165f318a98f96478676a390900 100644 (file)
@@ -146,6 +146,9 @@ static int checkErrorCode (const struct nsdp_cmd *nc)
 {
        switch (nc->error) {
        
+       case 0:
+               return ERR_OK;
+       
        case ERROR_DENIED:
                return (nc->attr_error == ATTR_PASSWORD) ? ERR_BADPASS : ERR_DENIED;
        
@@ -153,7 +156,7 @@ static int checkErrorCode (const struct nsdp_cmd *nc)
                return ERR_INVARG;
        
        default:
-               return ERR_OK;
+               return ERR_UNKNOWN;
        }
 }
 
index 441e142a1e4a4bd2fad71ce948bf7d1097198d25..962f2f2e0c5dbc280aa8396ca708c1f398447443 100644 (file)
@@ -32,7 +32,7 @@ int ngadmin_getVLANType (struct ngadmin *nga, int *t)
        *t = VLAN_DISABLED;
        
        if (attr->first == NULL) {
-               ret = ERR_INVARG;
+               ret = ERR_BADREPLY;
                goto end;
        }
        at = attr->first->data;
@@ -93,7 +93,7 @@ int ngadmin_getVLANPortConf (struct ngadmin *nga, unsigned char *ports)
        filterAttributes(attr, ATTR_VLAN_PORT_CONF, ATTR_END);
        
        if (attr->first == NULL) {
-               ret = ERR_INVARG;
+               ret = ERR_BADREPLY;
                goto end;
        }
        
@@ -104,7 +104,7 @@ int ngadmin_getVLANPortConf (struct ngadmin *nga, unsigned char *ports)
                avc = at->data;
 
                if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
-                       ret = ERR_INVARG;
+                       ret = ERR_BADREPLY;
                        goto end;
                }
                
@@ -155,7 +155,7 @@ int ngadmin_setVLANPortConf (struct ngadmin *nga, const unsigned char *ports)
        filterAttributes(conf_old, ATTR_VLAN_PORT_CONF, ATTR_END);
        
        if (conf_old->first == NULL) {
-               ret = ERR_INVARG;
+               ret = ERR_BADREPLY;
                goto end;
        }
        
@@ -168,7 +168,7 @@ int ngadmin_setVLANPortConf (struct ngadmin *nga, const unsigned char *ports)
                avc_old = at->data;
                
                if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
-                       ret = ERR_INVARG;
+                       ret = ERR_BADREPLY;
                        free(avc_new);
                        goto end;
                }
@@ -241,7 +241,7 @@ int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsig
        filterAttributes(attr, ATTR_VLAN_DOT_CONF, ATTR_END);
        
        if (attr->first == NULL) {
-               ret = ERR_INVARG;
+               ret = ERR_BADREPLY;
                goto end;
        }
        
@@ -253,7 +253,7 @@ int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsig
                avc = at->data;
                
                if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
-                       ret = ERR_INVARG;
+                       ret = ERR_BADREPLY;
                        goto end;
                }
                
@@ -303,7 +303,7 @@ int ngadmin_getVLANDotConf (struct ngadmin *nga, unsigned short vlan, unsigned c
        filterAttributes(attr, ATTR_VLAN_DOT_CONF, ATTR_END);
        
        if (attr->first == NULL) {
-               ret = ERR_INVARG;
+               ret = ERR_BADREPLY;
                goto end;
        }
        
@@ -314,7 +314,7 @@ int ngadmin_getVLANDotConf (struct ngadmin *nga, unsigned short vlan, unsigned c
                avc = at->data;
                
                if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
-                       ret = ERR_INVARG;
+                       ret = ERR_BADREPLY;
                        goto end;
                }
                
@@ -375,12 +375,12 @@ int ngadmin_setVLANDotConf (struct ngadmin *nga, unsigned short vlan, const unsi
                
                /* check if the switch is in 802.1Q mode */
                if (attr->first == NULL) {
-                       ret = ERR_INVARG;
+                       ret = ERR_BADREPLY;
                        goto end;
                } else {
                        at = attr->first->data;
                        if (at->size < sizeof(struct attr_vlan_conf) + sa->ports) {
-                               ret = ERR_INVARG;
+                               ret = ERR_BADREPLY;
                                goto end;
                        }
                }