]> git.sur5r.net Git - ngadmin/blobdiff - lib/src/protocol.c
Added the possibility to use global broadcast.
[ngadmin] / lib / src / protocol.c
index d1be292b8d8d7f460171001b812522d50235e523..5f99da233e1130829cfce63216d6c4bb75ee8aa9 100644 (file)
@@ -4,8 +4,24 @@
 
 
 
-
-const struct ether_addr nullMac={.ether_addr_octet={0, 0, 0, 0, 0, 0}};
+// ----------------------------
+int trim (char *txt, int start) {
+ char *p, c;
+ if ( txt==NULL ) {
+  return 0;
+ }
+ //for (p=txt; *p!=0; p++);
+ p=txt+start;
+ for (p--; p>=txt && ( (c=*p)==' ' || c=='\n' ); *p--=0);
+ return p-txt+1;
+}
 
 
 
@@ -21,7 +37,7 @@ void initNgHeader (struct ng_header *nh, char code, const struct ether_addr *cli
  
  
  memset(nh, 0, sizeof(struct ng_header));
- nh->unk1=1;
+ nh->version=1;
  nh->code=code;
  
  memcpy(nh->client_mac, client_mac, ETH_ALEN);
@@ -42,7 +58,7 @@ void initNgHeader (struct ng_header *nh, char code, const struct ether_addr *cli
 bool validateNgHeader (const struct ng_header *nh, char code, const struct ether_addr *client_mac, const struct ether_addr *switch_mac, unsigned int seqnum) {
  
  
- if ( nh->unk1!=1 ) {
+ if ( nh->version!=1 ) {
   return false;
  }
  
@@ -50,6 +66,10 @@ bool validateNgHeader (const struct ng_header *nh, char code, const struct ether
   return false;
  }
  
+ if ( nh->unk1!=0 ) {
+  return false;
+ }
  if ( *(unsigned short*)nh->unk2!=0 ) {
   return false;
  }
@@ -235,13 +255,13 @@ void freeAttr (struct attr *at) {
 
 
 
-// ---------------------------------------------------------------------------------------------------------------
-void extractPacketAttributes (struct ng_packet *np, unsigned short *error, unsigned short *attr_error, List *attr) {
+// --------------------------------------------------------------------------------------------------------------
+void extractPacketAttributes (struct ng_packet *np, unsigned char *error, unsigned short *attr_error, List *attr) {
  
  struct attr *at;
  
  
- if ( error!=NULL ) *error=ntohs(np->nh->error);
+ if ( error!=NULL ) *error=np->nh->error;
  if ( attr_error!=NULL ) *attr_error=ntohs(np->nh->attr);
  
  while ( getPacketTotalSize(np)<np->maxlen ) {
@@ -287,8 +307,6 @@ void extractSwitchAttributes (struct swi_attr *sa, const List *l) {
  
  memset(sa, 0, sizeof(struct swi_attr));
  
- // FIXME: mutex lock ?
  for (ln=l->first; ln!=NULL; ln=ln->next) {
   at=ln->data;
   
@@ -297,13 +315,13 @@ void extractSwitchAttributes (struct swi_attr *sa, const List *l) {
    case ATTR_PRODUCT:
     len=min(at->size, PRODUCT_SIZE);
     memcpy(sa->product, at->data, len);
-    //trim(sa->product, len); // FIXME
+    trim(sa->product, len);
    break;
    
    case ATTR_NAME:
     len=min(at->size, NAME_SIZE);
     memcpy(sa->name, at->data, len);
-    //trim(sa->name, len); // FIXME
+    trim(sa->name, len);
    break;
    
    case ATTR_MAC: