+// --------------------------------------------------------------------
+int ngadmin_setNetConf (struct ngadmin *nga, const struct net_conf *nc) {
+
+ List *attr;
+ struct swi_attr *sa;
+ int ret=ERR_OK;
+
+
+ if ( nga==NULL || nc==NULL ) {
+ return ERR_INVARG;
+ } else if ( (sa=nga->current)==NULL ) {
+ return ERR_NOTLOG;
+ }
+
+
+ attr=createEmptyList();
+
+ if ( nc->dhcp ) {
+ pushBackList(attr, newByteAttr(ATTR_DHCP, 1));
+ } else {
+ pushBackList(attr, newByteAttr(ATTR_DHCP, 0));
+ if ( nc->ip.s_addr!=0 ) pushBackList(attr, newAddrAttr(ATTR_IP, nc->ip));
+ if ( nc->netmask.s_addr!=0 ) pushBackList(attr, newAddrAttr(ATTR_NETMASK, nc->netmask));
+ if ( nc->gw.s_addr!=0 ) pushBackList(attr, newAddrAttr(ATTR_GATEWAY, nc->gw));
+ }
+
+ if ( (ret=writeRequest(nga, attr))!=ERR_OK ) {
+ goto end;
+ }
+
+
+ if ( nc->dhcp ) {
+ sa->nc.dhcp=true;
+ } else {
+ memcpy(&sa->nc, nc, sizeof(struct net_conf));
+ }
+
+
+ end:
+
+ return ret;
+
+}
+
+
+
+// --------------------------------------------------
+int ngadmin_getVLANType (struct ngadmin *nga, int *t) {
+
+ List *attr;
+ ListNode *ln;
+ struct attr *at;
+ int ret=ERR_OK;
+
+
+ if ( nga==NULL || t==NULL ) {
+ return ERR_INVARG;
+ } else if ( nga->current==NULL ) {
+ return ERR_NOTLOG;
+ }
+
+
+ attr=createEmptyList();
+ pushBackList(attr, newEmptyAttr(ATTR_VLAN_TYPE));
+ if ( (ret=readRequest(nga, attr))!=ERR_OK ) {
+ goto end;
+ }
+
+
+ for (ln=attr->first; ln!=NULL; ln=ln->next) {
+ at=ln->data;
+ if ( at->attr==ATTR_VLAN_TYPE && at->size>=1 ) {
+ *t= (int)*(char*)at->data ;
+ break;
+ }
+ }
+
+
+ end:
+ destroyList(attr, (void(*)(void*))freeAttr);
+
+ return ret;
+
+}
+
+
+
+// ------------------------------------------------------------------
+int ngadmin_getVLANDotConf (struct ngadmin *nga, char *buf, int *len) {
+
+ List *attr;
+ ListNode *ln;
+ struct attr *at;
+ struct swi_attr *sa;
+ int ret=ERR_OK, i;
+ char *b=buf, *p=NULL;
+
+
+ if ( nga==NULL || buf==NULL || len==NULL || *len<=0 ) {
+ return ERR_INVARG;
+ } else if ( (sa=nga->current)==NULL ) {
+ return ERR_NOTLOG;
+ }
+
+
+ attr=createEmptyList();
+ pushBackList(attr, newEmptyAttr(ATTR_VLAN_DOT_CONF));
+ if ( (ret=readRequest(nga, attr))!=ERR_OK ) {
+ goto end;
+ }
+
+
+ for (ln=attr->first; ln!=NULL; ln=ln->next) {
+ at=ln->data;
+ p=at->data;
+ if ( (b-buf)+2+sa->ports>*len ) break; // no more room
+ if ( at->attr==ATTR_VLAN_DOT_CONF && at->size>=4 ) {
+ *(unsigned short*)b=ntohs(*(unsigned short*)p);b+=2;
+ for (i=1; i<=sa->ports; ++i) {
+ if ( (p[3]>>(sa->ports-i))&1 ) *b++=VLAN_TAGGED; // tagged
+ else if ( (p[2]>>(sa->ports-i))&1 ) *b++=VLAN_UNTAGGED; // untagged
+ else *b++=VLAN_NO;
+ }
+ }
+ }
+
+ *len=b-buf;
+
+
+ end:
+ destroyList(attr, (void(*)(void*))freeAttr);
+
+ return ret;
+
+}
+
+
+
+
+